[R] Help with cast/reshape

Daniel Malter daniel at umd.edu
Sat Oct 1 11:04:03 CEST 2011


df2<-melt(df1)
df3<-cast(df2,Index~Name)
df3

HTH,
Daniel


Dana Sevak wrote:
> 
> I realize that this is terribly basic, but I just don't seem to see it at
> this moment, so I would very much appreciate your help.
> 
> 
> How shall I transform this dataframe:
> 
>> df1
>   Name Index Value
> 1    a     1   0.1
> 2    a     2   0.2
> 3    a     3   0.3
> 4    a     4   0.4
> 5    b     1   2.1
> 6    b     2   2.2
> 7    b     3   2.3
> 8    b     4   2.4
> 
> 
> into this dataframe:
> 
>> df2
>     Index  a       b
> 1  1     0.1     2.1
> 2  2     0.2     2.2
> 3  3     0.3     2.3
> 4  4     0.4     2.4
> 
> 
> df1 = data.frame(c("a", "a", "a", "a", "b", "b", "b", "b"),
> c(1,2,3,4,1,2,3,4), c(0.1, 0.2, 0.3, 0.4, 2.1, 2.2, 2.3, 2.4))
> colnames(df1) = c("Name", "Index", "Value")
> 
> df2 = data.frame(c(1,2,3,4), c(0.1, 0.2, 0.3, 0.4), c(2.1, 2.2, 2.3, 2.4))
> colnames(df2) = c("Index", "a", "b")
> 
> 
> Thank you very much.
> 
> Dana
> 
> 
> ______________________________________________
> R-help@ mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide
> http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
> 

--
View this message in context: http://r.789695.n4.nabble.com/Help-with-cast-reshape-tp3862176p3862404.html
Sent from the R help mailing list archive at Nabble.com.



More information about the R-help mailing list