【发布时间】:2021-03-08 19:15:13
【问题描述】:
我的数据目前是df1的格式:
outcome <- c("success", "failure", "success", "failure", "success", "failure")
basketball <- c(10, 7, 7, 8, 9, 10)
soccer <- c(8, 21, 30, 21, 6, 10)
football <- c(9, 2, 1, 3, 1, 5)
df1 <- data.frame(outcome, basketball, soccer, football)
我希望它采用 df2 格式,这样我可以更轻松地使用 ggplot2 创建条形图。
symptom <- c("basketball", "basketball", "soccer", "soccer", "football", "football")
mean <- c(10, 6, 9, 7, 3, 1)
sd <- c(1, 2, 1, 3, 0.5, 0.2)
df2 <- data.frame(outcome, symptom, mean, sd)
目前我有很多代码可以让我以一种迂回的方式到达那里,但我觉得必须有一种简化的方式来用几行代码来做到这一点。有没有办法使用 dplyr 或 tidyr 动词来使用它?
谢谢!
【问题讨论】:
-
是 'mean', 'sd' 中的值基于输入数据