Hopefully I can explain my question well enough; So, I have a data frame like this:
sample = data.frame("Room" = c("A1", "B2","A1","A3","A2"), "Name"=c("Peter","Tom","Peter","Anna","Peter"), "Class"=c("E","E","F","D","E"), "FY"=c(1,2,3,4,6))
Now I would like to create a new data frame, which has only the unique values of column "Class" as column names and the columns "Room" and "Name" as columns. The values should then be sums of "FY".
If there wasn´t the column "Room", I would do this:
test=as.data.frame(unclass(with(sample, tapply(FY, list(Name, Class), FUN=sum))))
But how can I do this with two columns?
This is my desired output:
output = data.frame(c("A1", "B2","A3", "A2"), c("Peter","Tom","Anna","Peter"), c(1,2,NA,6),c(3,NA,NA,NA),c(NA,NA,4,NA))
colnames(output) = c("Room", "Name","E","F","D")