[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.

相关推荐
留不住丨晚霞10 分钟前
说说SpringBoot常用的注解?
java·开发语言
hardStudy_h20 分钟前
C++——内联函数与Lambda表达式
开发语言·jvm·c++
艾莉丝努力练剑1 小时前
【C语言】学习过程教训与经验杂谈:思想准备、知识回顾(三)
c语言·开发语言·数据结构·学习·算法
witton2 小时前
Go语言网络游戏服务器模块化编程
服务器·开发语言·游戏·golang·origin·模块化·耦合
枯萎穿心攻击3 小时前
ECS由浅入深第三节:进阶?System 的行为与复杂交互模式
开发语言·unity·c#·游戏引擎
Jerry Lau3 小时前
go go go 出发咯 - go web开发入门系列(一) helloworld
开发语言·前端·golang
nananaij3 小时前
【Python基础入门 re模块实现正则表达式操作】
开发语言·python·正则表达式
Micro麦可乐3 小时前
Java常用加密算法详解与实战代码 - 附可直接运行的测试示例
java·开发语言·加密算法·aes加解密·rsa加解密·hash算法
天下一般3 小时前
go入门 - day1 - 环境搭建
开发语言·后端·golang
雷羿 LexChien3 小时前
C++内存泄漏排查
开发语言·c++