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

相关推荐
Byte Wizard几秒前
C语言数据在内存中的存储
c语言·开发语言
basketball6162 分钟前
C++面试考点 头文件与实现文件形式
开发语言·c++
SilentSamsara3 分钟前
类型注解进阶:Union、Optional、Any 与 Callable
开发语言·python·青少年编程
历程里程碑3 分钟前
56 . 高效ET非阻塞IO服务器设计指南
java·运维·服务器·开发语言·数据结构·c++·排序算法
恣艺8 分钟前
Python 游戏开发与文件处理:PyGame + Turtle + openpyxl + python-docx + PyPDF2
开发语言·python·pygame
高林雨露15 分钟前
kotlin 相关code
开发语言·kotlin
我还记得那天19 分钟前
函数的递归调用
c语言·开发语言·visualstudio
zhangfeng113319 分钟前
ThinkPHP5 事件系统的标准最佳实践 事件系统的完整设计逻辑tags.php tags.php(事件地图)
android·开发语言·php
xyq202422 分钟前
HTML 标签简写及全称
开发语言
tongluowan00723 分钟前
数据结构 Bitmap(位图)示例 - 用户签到系统
开发语言·数据结构·bitmap·用户签到系统