[R] re form data for aov()?

Dan Kelley kelley.dan at gmail.com
Sun Mar 29 19:01:19 CEST 2009


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.




More information about the R-help mailing list