某些行的标准变量

发布于 2025-01-21 08:11:08 字数 347 浏览 0 评论 0原文

我有一个很长的数据集,其中包含不同类型的问题。

age <- ("18-30","31-45","60+","46-60", "31-45", "18-30", "60+", "46-60")
gender <- ("M","F","F","F","M","M","F","M")
case <- ("Q1","Q1","Q2","Q2","Q3","Q3","Q4","Q4")
height <- (0,200,310,0,0,175,270,150)

我想计算高度列的平均值,平均值和标准偏差。因此,Q1,Q2,Q3和Q4的4个不同表。我对R的了解真的有限,有人可以帮助我吗? 提前致谢

I have a long dataset with different type of questions referred to in the case row.

age <- ("18-30","31-45","60+","46-60", "31-45", "18-30", "60+", "46-60")
gender <- ("M","F","F","F","M","M","F","M")
case <- ("Q1","Q1","Q2","Q2","Q3","Q3","Q4","Q4")
height <- (0,200,310,0,0,175,270,150)

I would like to calculate, the mean, the median and standard deviation per question for the height column. So 4 different tables for Q1, Q2, Q3 and Q4. I my knowledge of r is really limited anyone can help me with it please?
thanks in advance

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

戏剧牡丹亭 2025-01-28 08:11:08
library(dplyr)
df <- tibble(
  age = c("18-30","31-45","60+","46-60", "31-45", "18-30", "60+", "46-60"),
gender = c("M","F","F","F","M","M","F","M"),
case = c("Q1","Q1","Q2","Q2","Q3","Q3","Q4","Q4"),
height = c(0,200,310,0,0,175,270,150)
)

df %>% 
  group_by(case) %>% 
  summarise(mean = mean(height), 
            median = median(height), 
            sd = sd(height))

如果您需要每种情况的单个数据框,则可以简单地过滤就所需的问题,即第一种情况“ Q1”

df  %>% 
      group_by(case) %>% 
      summarise(mean = mean(height), 
                median = median(height), 
                sd = sd(height)) %>%
      filter(case == "Q1")
library(dplyr)
df <- tibble(
  age = c("18-30","31-45","60+","46-60", "31-45", "18-30", "60+", "46-60"),
gender = c("M","F","F","F","M","M","F","M"),
case = c("Q1","Q1","Q2","Q2","Q3","Q3","Q4","Q4"),
height = c(0,200,310,0,0,175,270,150)
)

df %>% 
  group_by(case) %>% 
  summarise(mean = mean(height), 
            median = median(height), 
            sd = sd(height))

If you want individual dataframes for each case, you can simply filter for the questions you want, i.e. for the first case "Q1"

df  %>% 
      group_by(case) %>% 
      summarise(mean = mean(height), 
                median = median(height), 
                sd = sd(height)) %>%
      filter(case == "Q1")
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文