查找摘要统计信息。在将数据从 Excel 导入 R 后遇到任何问题

Finding summary statistics. Struggling with having anything work after importing data into R from Excel

在这里对 R 很陌生,对编码和计算机的概念也很陌生。

class 的第二周,我需要从教授提供的一组数据中找到一些汇总统计数据。我下载了数据图表并尝试在 class 期间按照他的口头指示进行操作,但我是我学位课程中仅有的非计算机科学背景之一(我是一名正在攻读健康信息学学位的注册护士) , 所以他对我来说太快了。

我希望就从哪里开始他的任务列表让我完成一些意见。我将他的数据下载到一个 excel 文件中,然后将其上传到 R 中,现在它是一个矩阵。但是,我尝试获取他想要的列的均值和标准差的所有尝试都出现了错误。我知道我需要将这些列名转换成某种向量,但在线每个网站都告诉我以不同的方式完成这些任务。我什至不知道从哪里开始做这个作业。

任何关于如何让我自己入门的帮助都将不胜感激。我附上了他的说明和我的矩阵的屏幕截图。请原谅我 ignorance/lack 与在座的大多数人相比,我的熟悉程度...这是我进入硕士课程的第二周,我希望我能尽快开始学习它,我只是还没到那一步。

说明包括:

# * Import the dataset
# * summarize the dataset,Compute the mean and standard deviation for the three variables (columns): age, height, weight
# * Tabulate smokers and age.level data with the variable and its frequency. How many smokers in each age category ?
# * Subset dataset by the mothers that smoke and weigh less than 100kg,how many mothers meet this requirements?
# * Compute the mean and standard deviation for the three variables (columns): age, height, weight
# * Plot a histogram

Stack Overflow 不是做作业的地方,但我能感受到你的痛苦。一点一点来吧。

首先让我们使用一个包来帮助我们完成这些任务:

library(data.table) # if not installed, install it with install.packages("data.table")

然后,让我们加载数据:

library(readxl) #again, install it if not installed

dt = setDT(read_excel("path/to/your/file/here.xlsx"))

现在开始计算:

1 总结数据集。在这里,您会看到 table.

的范围、均值、中位数和其他有趣的数据
summary(dt)

1年龄、身高和体重的平均值和标准差(将年龄替换为身高和体重的列名即可)

dt[, .(meanValue = mean(age, na.rm = TRUE), stdDev = sd(age, na.rm = TRUE))]

2 制表吸烟者和 age.level。获取每个组合的计数:

dt[, .N, by = .(smoke, age.level)]

3 个 wt < 100 的吸烟母亲子集(我假设未怀孕的母亲在妊娠场有 NA。根据需要调整):

dt[smoke == 1 & weight < 100 & !is.na(gestation), .N]

4与1A相同

5 绘制直方图(但你没有指定什么变量,所以假设它是年龄):

hist(dt$age)

继续学习R,没那么难。评论里推荐的书是一个很好的开始