[R] help required to melt a data frame
Wu Gong
ghowoo at gmail.com
Tue May 25 23:13:54 CEST 2010
Hope it helps this time:)
### Package reshape, function melt and cast
### Read table
dummy <- read.table(textConnection("State Months Bedroom
1 xxx Jan 1
2 xxx Jan 2
3 xxx Jan 1
4 yyy Jan 1
5 yyy Jan 2
6 yyy Jan 1
7 zzz Jan 3
8 zzz Jan 1
9 zzz Jan 2
10 xxx Feb 3
11 xxx Feb 4
12 xxx Feb 2
13 yyy Feb 1
14 yyy Feb 2
15 yyy Feb 1
16 zzz Feb 2
17 zzz Feb 3
18 zzz Feb 3 "))
## Melt
melt.dummy <- melt.data.frame(dummy,id.vars=c("State","Bedroom"),
measure.vars="Months")
## Cast
cast(melt.dummy, State + Bedroom ~ value,length)
-----
A R learner.
--
View this message in context: http://r.789695.n4.nabble.com/help-required-to-melt-a-data-frame-tp2229633p2230729.html
Sent from the R help mailing list archive at Nabble.com.
More information about the R-help
mailing list