I have a dataframe df like this:
type V1 V2 1 A bla bla 2 A bla bla 3 B bloo bla 4 B bloo bla 5 C moo bloo 6 C moo bloo
I am currently melting / casting to get this:
type bla bloo moo A 4 0 0 B 2 2 0 C 0 2 2
using the following commands:
library(reshape) melted <- melt(df, id='type') count <- function(x) { length(na.omit(x)) } casted <- cast(melted, type~value, count)
However, instead of counting / summing, I want to get a list of the original names of the growths. Something like that:
type bla bloo moo A 1,2 0 0 B 3,4 3,4 0 C 0 5,6 5,6
where each value for bla, bloo and moo is a list of unique growth names from the original data frame.
Can anyone help?
r reshape
Harry palmer
source share