I have some data of foods eaten on different days.
day <- c(1,1,1,1,2,2,2,3,3,3,3,3)
food <- c('pizza','pizza','taco','snake','snake','taco','taco','pizza','taco','pizza','taco','snake')
all <- data.frame(day, food)
I'd like to create a table with food on the x axis, day on the y axis, and the number of foods per day in the matrices such that
food.list <- unique(all$food)
day.list <- unique(all$day )
output <- data.frame(c(2,1,1),c(0,2,1),c(2,2,1))
output
1 2 3
pizza 2 0 2
taco 1 2 2
snake 1 1 1
What is a straightforward way to solve this problem?