[R] converting a summary table to survey database form
arun
smartpink111 at yahoo.com
Thu Aug 22 18:17:17 CEST 2013
Hi,
May be this helps:
dat1<- structure(...
dat1$ID<- row.names(dat1)
library(reshape2)
dat2<-melt(dat1,id.vars="ID")
dat2New<-dat2[order(as.numeric(dat2$ID)),]
head(dat2New)
# ID variable value
#1 1 Ramses 4
#11 1 Sheiks 5
#21 1 Trojans 7
#31 1 Unnamed 2
#2 2 Ramses 4
#12 2 Sheiks 5
A.K.
----- Original Message -----
From: Pancho Mulongeni <p.mulongeni at namibia.pharmaccess.org>
To: "r-help at r-project.org" <r-help at r-project.org>
Cc:
Sent: Thursday, August 22, 2013 12:08 PM
Subject: [R] converting a summary table to survey database form
Hi!
I am looking to choose a condom based on its pleasure score.
I received some summarised data from 10 individuals:
structure(list(Ramses = c(4, 4, 5, 5, 6, 3, 4, 4, 3, 4), Sheiks = c(5,
5, 6, 4, 7, 6, 4, 5, 6, 3), Trojans = c(7, 8, 7, 9, 6, 3, 2,
2, 2, 3), Unnamed = c(2, 1, 1, 3, 3, 4, 5, 4, 4, 3)), .Names = c("Ramses",
"Sheiks", "Trojans", "Unnamed"), row.names = c(NA, 10L), class = "data.frame")
However to do an annova to see if the mean score is not the same for all brands, I understand I need to have the data in survey database form i.e.
1 Ramses 4
1 Sheiks 4
1 Trojans 7
1 Unamed 2
2 Ramses 4
...
10 Unamed 3
I would have a dataframe with two factor 'brand' and 'score'. I would then do an aov(score~brand,data=condom.dataframe) for instance.
However to get my original condomData which has the tabulated scores per brand into the summarised form is a pain.
I tried to just get a vector that essentially has all the rows of condomData put into one long vector from i.e. c( a1_1,a1_2...a1_5,a2_1,2_..a2_5.......a10_5)
I would then bind this together with a names vector of rep(c('Ramses','Sheiks','Trojans','Unamed),10) and I would have my desired datafram for anova.
But alas my attempt below does not work:
r<-dim(condomData)[1]
scoreS<-c()
for (i in 1:r) {
score<-as.numeric(condomData[r,])
scoreS<-c(scoreS,s)
}
It just gives me the last row of condomData copied 10 times.
Any help?
Thank you, I really want to know if all condoms are equal.
Pancho Mulongeni
Research Assistant
PharmAccess Foundation
1 Fouché Street
Windhoek West
Windhoek
Namibia
Tel: +264 61 419 000
Fax: +264 61 419 001/2
Mob: +264 81 4456 286
______________________________________________
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.
More information about the R-help
mailing list