我是一名医学生,对R的使用不是很丰富!感谢任何帮助!
答案 0 :(得分:0)
带有data.table:
# example data
N <- 25
df <- data.frame(
age = sample(18:65, N, TRUE),
sex = sample(1:2, N, TRUE),
employment = sample(1:10, N, TRUE),
wages = sample(1:50, N, TRUE)*10
)
# convert to data.table
library(data.table)
setDT(df)
# pivot
df[employment != "", .(avg_wages = mean(wages)), by=.(age, sex)]
要用英语解释“枢轴”部分: