I'm trying to spread a two column dataset into multiple columns. Here is a similar dataframe.
dummydf<- data.frame(LnPD=rnorm(25,0.6,3),K=rep(x,5))
All I want to do is reshape the data so each column is an appropriate factors (i.e. there should be 5 columns each for A:E) with corresponding figures. I thought this would do it but it keeps asking for column names:
dummy %>%
group_by(K) %>%
mutate(group_now = 1:n())
spread(K,LnPD)
I'm sure it's a simple fix but I can't get my head around it. The other error it gave me was something related with duplicate identifiers, although that was with my own dataset not the above.
Thanks in advance.
x
in thedummydf
definition? – alistaire%>%
) after your mutate call and you calldummy
instead ofdummydf
. When I correct those issues and replaceK=rep(x, 5)
in yourdata.frame()
call withK=rep(c(1, 2, 3, 4, 5),5)
the code works for me – tbradleyx<-factor(LETTERS[1:5])
– Dasr