I have data in a file named hands.dat, which is given at the end of this question. (It's from a stats textbook example on anova). I'd like to do an aov on this, which I guess would be d <- read.table("~/hands.dat", header=TRUE) aov(Bacterial.Counts ~ Water + Soap + Antibacterial.Soap + Alcohol.Spray, data=d) but this fails. Do I need to break d$Method up into columns for each category, with boolean entries? Or is there a way to do this more cleanly? Data file (hands.dat) =========== Bacterial.Counts Method 74 Water 84 Soap 70 Antibacterial.Soap 51 Alcohol.Spray 135 Water 51 Soap 164 Antibacterial.Soap 5 Alcohol.Spray 102 Water 110 Soap 88 Antibacterial.Soap 19 Alcohol.Spray 124 Water 67 Soap 111 Antibacterial.Soap 18 Alcohol.Spray 105 Water 119 Soap 73 Antibacterial.Soap 58 Alcohol.Spray 139 Water 108 Soap 119 Antibacterial.Soap 50 Alcohol.Spray 170 Water 207 Soap 20 Antibacterial.Soap 82 Alcohol.Spray 87 Water 102 Soap 95 Antibacterial.Soap 17 Alcohol.Spray -- View this message in context: http://www.nabble.com/reform-data-for-aov%28%29--tp22769061p22769061.html Sent from the R help mailing list archive at Nabble.com.
I'm trying to follow along in a text by Velleman and others, with the 'handwashing' example of anova. I used read.table() to read the data, and now I have an object d (put below the dots here), with an entry Method that has possible values "Water", "Soap", etc. What I can't figure out is how to take this d$Method and use it in an aov call. I tried aov(Bacterial.Counts ~ Water + Soap + Antibacterial.Soap + Alcohol.Spray, data=d) but this fails. Do I need to break d$Method up into columns for each category, with boolean entries? Or is there a way to do this more cleanly? ... the data ... `d` <- structure(list(Bacterial.Counts = c(74L, 84L, 70L, 51L, 135L, 51L, 164L, 5L, 102L, 110L, 88L, 19L, 124L, 67L, 111L, 18L, 105L, 119L, 73L, 58L, 139L, 108L, 119L, 50L, 170L, 207L, 20L, 82L, 87L, 102L, 95L, 17L), Method = structure(c(4L, 3L, 2L, 1L, 4L, 3L, 2L, 1L, 4L, 3L, 2L, 1L, 4L, 3L, 2L, 1L, 4L, 3L, 2L, 1L, 4L, 3L, 2L, 1L, 4L, 3L, 2L, 1L, 4L, 3L, 2L, 1L), .Label = c("Alcohol.Spray", "Antibacterial.Soap", "Soap", "Water"), class = "factor")), .Names c("Bacterial.Counts", "Method"), class = "data.frame", row.names = c(NA, -32L)) -- View this message in context: http://www.nabble.com/reform-data-for-aov%28%29--tp22769850p22769850.html Sent from the R help mailing list archive at Nabble.com.
Dan Kelley <kelley.dan <at> gmail.com> writes:> > > I have data in a file named hands.dat, which is given at the end of this > question. (It's from a stats textbook example on anova). I'd like to do an > aov on this, which I guess would be > > d <- read.table("~/hands.dat", header=TRUE) > > aov(Bacterial.Counts ~ Water + Soap + Antibacterial.Soap + Alcohol.Spray, > data=d) > > Data file (hands.dat) > ===========> > Bacterial.Counts Method > 74 Water > 84 Soap > 70 Antibacterial.Soap > 51 Alcohol.SprayTo be sure that data are ok, first try str(d) Method should be factor. aov(BacterialCounts~Method,data=d) Dieter