[R] Dataframe with single level column
Blanchette, Marco
MAB at stowers-institute.org
Fri Nov 21 16:57:43 CET 2008
Dear all,
I have a dataframe with multiple observations and the levels as the last column, as in:
d <- data.frame(A=sample(1:100,12),B=sample(1:100,12),levels=c(rep('A',4),rep('B',4),rep('C',4)))
> d
A B levels
1 77 40 A
2 14 18 A
3 56 7 A
4 46 27 A
5 63 35 B
6 80 21 B
7 3 54 B
8 93 76 B
9 5 46 C
10 16 53 C
11 40 17 C
12 25 31 C
I need to run anova analyis on the group in levels against the merge data in the first two columns. I can manually split and join the different columns as in
> d.t <- rbind(data.frame(value=d[,1],ind=d[,3]),data.frame(value=d[,2],ind=d[,3]))
but I was wondering if there would be a more elegant and easy way than that that would prevent me from hard coding the different vectors making the data frame.
Thanks
--
Marco Blanchette, Ph.D.
Assistant Investigator
Stowers Institute for Medical Research
1000 East 50th St.
Kansas City, MO 64110
Tel: 816-926-4071
Cell: 816-726-8419
Fax: 816-926-2018
More information about the R-help
mailing list