I have a data.frame like attachment1, how can I transform it into the data.frame in attachment2?attachment1. attachment2
Asked
Active
Viewed 22 times
I have a data.frame like attachment1, how can I transform it into the data.frame in attachment2?attachment1. attachment2
letting your data name as df
,
df %>%
reshape2::melt(value.name = "fruit", measure.var = c("a", "b", "c", "d")) %>%
na.omit %>% rename( basket = variable)
basket fruit
1 a apple
2 a orange
5 a peach
10 b peach
15 c peach
19 d banana