I have a data frame with species, like this:
df <- data.frame("especie" = c("abies", "abies", "acacia", "acacia", "acacia"), "use"=c("ornamental", "wood", "wood", "medicine", "firewood"))
df
especie use
1 abies ornamental
2 abies wood
3 acacia wood
4 acacia medicine
5 acacia firewood
I want to "spread" it so it goes like:
df2 <- data.frame("species"=c("abies", "acacia"), "use1"=c("ornamental", "wood"), "use2"=c("wood", "medicine"),
"use3"=c("", "firewood"), "use4"=c("", ""))
df2
species use1 use2 use3 use4
1 abies ornamental wood
2 acacia wood medicine firewood
I don't want a column with the name of each level, so tidyr::spread does not do what i want; if the sepecies has only one "use", it should be in "use1", I've got no clue how can this be done