Hi all,
Might be silly but I'm a newbie with R…
My df looks like this:
Id type count
3 A 5
3 B 0
3 c 1
4 A 5
4 A 4
4 A 3
I want to reshape it to this:
Id A B C
3 5 0 1
4 5 4 3
I tried:
df_wide <- spread(df, Type, count)
but nothing happened, the df stayed the same! What am I doing wrong?
Simon
From package reshape2 use the dcast function
W = dcast(id ~ type)
--
You received this message because you are subscribed to the Google Groups "Israel R User Group" group.
To unsubscribe from this group and stop receiving emails from it, send an email to israel-r-user-g...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Thanks, almost there.
My data has an additional column containing found/not found (I thought it wasn't important so didn't mention it earlier).
When applying your solution, I get:
Id A B C
3 found not-found found
4 found found found
With this message:
" Using Found as value column: use value.var to override."
I tried:
W <- dcast(df, Id ~ type, value.var = count)
But got this message:
Error: value.var (21567345
In addition: Warning message:
In if (!(value.var %in% names(data))) { :
the condition has length > 1 and only the first element will be used
To unsubscribe from this group and stop receiving emails from it, send an email to israel-r-user-group+unsub...@googlegroups.com.
Found my mistake!
Should have wrote:
W <- dcast(df, Id ~ type, value.var="count")
Thanks! R rocks!
Simon