[R] dercribe: to get the mean and sd, and print with paste

Of course you can hard-coded the standard deviation and mean GPA values.

like:

R 复制代码
#Using the command describe, tell what is the standard deviation and the mean GPA of the students in Year 4 (GE_survey_Y4)
#the variable name is Q19_actual_GPA
#Please write your code below
library(psych)
describe(GE_survey_Y4$Q19_actual_GPA)

and:

R 复制代码
standard_deviation <-0.31
print(standard_deviation)
mean_GPA1 <- 3.33
print(mean_GPA1)

but you have an alternative way to dynamically do it:

Create a df to store the sedcribe result and use stats$ to get the stored answer:

R 复制代码
stats <- describe(GE_survey_Y4$Q19_actual_GPA)
standard_deviation <- stats$sd
mean_GPA1 <- stats$mean

The instruction "#Please write a sentence with your answer below" is asking you to provide a written interpretation or summary of the results obtained from your code. This is often done in academic or professional settings to ensure that the reader understands the significance of the results without having to interpret the code themselves.

R 复制代码
If you have a variable statsanswer1 containing the number 7 and you want to report it in a sentence, you can use the paste() function to concatenate the text with the value of the variable. Here's how you can do it:

statsanswer1 <- 7
report_sentence <- paste("The answer is", statsanswer1)
print(report_sentence)

In this code, paste() combines the string "The answer is" with the value of statsanswer1 to create the sentence "The answer is 7". The print() function is then used to display the sentence.

Don't use "+" or "," directly, may work in Java or Python but not here.

相关推荐
铭毅天下2 分钟前
EasySearch Rules 规则语法速查手册
开发语言·前端·javascript·ecmascript
YMWM_17 分钟前
print(f“{s!r}“)解释
开发语言·r语言
愤豆20 分钟前
05-Java语言核心-语法特性--模块化系统详解
java·开发语言·python
bksczm21 分钟前
文件流(fstream)
java·开发语言
NGC_661122 分钟前
Java 线程池阻塞队列与拒绝策略
java·开发语言
小碗羊肉34 分钟前
【从零开始学Java | 第二十二篇】List集合
java·开发语言
m0_7167652336 分钟前
C++提高编程--STL常用容器(set/multiset、map/multimap容器)详解
java·开发语言·c++·经验分享·学习·青少年编程·visual studio
froginwe111 小时前
Bootstrap4 折叠组件使用指南
开发语言
sunwenjian8861 小时前
SpringBean的生命周期
java·开发语言
毕设源码-赖学姐1 小时前
【开题答辩全过程】以 基于Java的游泳馆会员管理系统的设计与实现为例,包含答辩的问题和答案
java·开发语言