Reshape data problem

3 views
Skip to first unread message

Roy Francis Mathew

unread,
Jan 17, 2011, 8:33:00 AM1/17/11
to ggp...@googlegroups.com
Hi,

Here are two dataframes, which are identical in information but presented in different format.

t1<-data.frame(n=factor(1:5),x=32:36,y=22:26,z=42:46)
t2<-data.frame(n=factor(rep(1:5,1,each=3)),var=factor(rep(c("x","y","z"),5)),val=c(32,22,42,33,23,43,34,24,44,35,25,45,36,26,46))

I would like to convert t2 to t1. I cannot figure out how to do it with melt/cast/recast/reshape etc.


Regards
Roy Mathew Francis
royfranc...@agrsci.dk

Brandon Hurr

unread,
Jan 17, 2011, 9:31:26 AM1/17/11
to Roy Francis Mathew, ggp...@googlegroups.com
> ?cast
> cast(t2, n~var)
Using val as value column.  Use the value argument to cast to override this choice
  n  x  y  z
1 1 32 22 42
2 2 33 23 43
3 3 34 24 44
4 4 35 25 45
5 5 36 26 46

HTH, 

B

Santosh Srinivas

unread,
Jan 17, 2011, 9:30:03 AM1/17/11
to Roy Francis Mathew, ggp...@googlegroups.com
library(reshape)
t2.c <- cast(t2, n~var)

Better to get this question to r-help

> --
> You received this message because you are subscribed to the ggplot2 mailing list.
> Please provide a reproducible example: http://gist.github.com/270442
>
> To post: email ggp...@googlegroups.com
> To unsubscribe: email ggplot2+u...@googlegroups.com
> More options: http://groups.google.com/group/ggplot2
>

Reply all
Reply to author
Forward
0 new messages