[R] convert data from
jim holtman
jholtman at gmail.com
Thu Sep 20 22:07:03 CEST 2007
This should get you close to what you want:
> x <- read.table(textConnection(" X1 X2
+ A 1 2
+ B 3 4
+ C 5 6"), header=TRUE)
> # add rownames to the dataframe
> x$name <- row.names(x)
> require(reshape) # use reshape package
[1] TRUE
> melt(x, id='name')
name variable value
1 A X1 1
2 B X1 3
3 C X1 5
4 A X2 2
5 B X2 4
6 C X2 6
On 9/20/07, Pan Zheng <zhpan99 at yahoo.com> wrote:
> Hi,
>
> I am trying to convert a data frame from:
>
> X1 X2
> A 1 2
> B 3 4
> C 5 6
>
> to:
> A01 1
> A02 2
> B01 3
> B02 4
> C01 5
> C02 6.
>
> How can I do it in R?
>
> I appreciate your help.
>
> Zheng
>
>
> ---------------------------------
>
> [[alternative HTML version deleted]]
>
> ______________________________________________
> R-help at r-project.org 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.
>
--
Jim Holtman
Cincinnati, OH
+1 513 646 9390
What is the problem you are trying to solve?
More information about the R-help
mailing list