这可以通过使用重塑功能来完成。
> data <- data.frame( name = rep(c("firstName", "LastName"), each=5), salarygroup = rep(1:5, 2), Errors = sample(21:60,10,replace=TRUE) ) > data
名称薪水组错误
1 firstName 1 58 2 firstName 2 50 3 firstName 3 47 4 firstName 4 29 5 firstName 5 36 6 LastName 1 34 7 LastName 2 40 8 LastName 3 54 9 LastName 4 38 10 LastName 5 41 > reshape(data, idvar = "name", timevar = "salarygroup", direction = "wide")
名称错误1错误2错误3错误4错误5
1 firstName 58 50 47 29 36 6 LastName 34 40 54 38 41