我希望得到每个Dish'组的平均得分。但是,当我尝试使用以下代码时,它无法找到Objects Dish / Score。
dishes <- read.table(file=theFile, header=TRUE, sep=",")
aggdata <- aggregate(formula= Score ~ Dish,
data = dishes,
FUN = mean)
来自一些重建数据的输出:
structure(list(UserName.Dish.Score = structure(c(26L, 25L, 23L,
24L, 13L, 14L, 15L, 17L, 28L, 22L, 12L, 30L, 29L, 20L, 18L, 19L,
16L, 27L, 21L, 10L, 9L, 7L, 8L, 2L, 3L, 4L, 5L, 11L, 6L, 1L), .Label = c("kjetsand;Bacalao;3",
"kjetsand;Chicken Curry;5", "kjetsand;Chicken Tikka Masala;5",
"kjetsand;Chili Con Carne;3", "kjetsand;Kebab;3", "kjetsand;Paella;3",
"kjetsand;Pasta Bolognese;3", "kjetsand;Pasta Carbonara;3", "kjetsand;Pizza Margherita;3",
"kjetsand;Pizza Napolitana;4", "kjetsand;Sushi;5", "nilstesd;Bacalao;6",
"nilstesd;Chicken Curry;4", "nilstesd;Chicken Tikka Masala;5",
"nilstesd;Chili Con Carne;4", "nilstesd;Coq au vin;5", "nilstesd;Kebab;3",
"nilstesd;Kentucky Fried Chicken;2", "nilstesd;Lutefisk;5", "nilstesd;MacDonalds Cheeseburger;1",
"nilstesd;Moules frites;5", "nilstesd;Paella;6", "nilstesd;Pasta Bolognese;5",
"nilstesd;Pasta Carbonara;5", "nilstesd;Pizza Margherita;4",
"nilstesd;Pizza Napolitana;6", "nilstesd;Ratatouille;4", "nilstesd;Sushi;6",
"nilstesd;Sweet And Sour Pork;3", "nilstesd;Taco;2"), class = "factor")), .Names = "UserName.Dish.Score", row.names = c(NA,
30L), class = "data.frame")
答案 0 :(得分:0)
将Score
的班级更改为numeric
dishes$Score <- as.numeric(dishes$Score)
然后您可以汇总数据
aggregate(formula= Score ~ Dish,
data = dishes,
FUN = mean)