I am trying to spread a single column in an R dataframe. I have reviewed many posts on SO, but cant get my solution to work because most solutions seem to require a formula (count, mean, sum, etc). I am simply looking to spread a column of characters. For example:
library(tidyverse)
school<- c("univ1", "univ2","univ1", "univ2","univ1" )
student<-c('bob', 'sally','ben','trudy','evan')
df <- data.frame(school, student)
produces:
school student
univ1 bob
univ2 sally
univ1 ben
univ2 trudy
univ1 evan
but what I am trying to output is:
school student1 student2 student2
univ1 bob ben evan
univ2 sally trudy
How would I accomplish this? I tried spread() and pivot_wider() but neither work. Any thoughts? The actual dataset is quite large (over 300k rows of data) that will need transposed in this manner if that makes a difference.