[R] ave function
arun
smartpink111 at yahoo.com
Tue Aug 13 20:01:17 CEST 2013
Hi,
You could try:
lapply(split(Clean,list(Clean$TERM,Clean$INST_NUM)),function(x) shapiro.test(x$GRADE))
A.K.
----- Original Message -----
From: Robert Lynch <robert.b.lynch at gmail.com>
To: r-help at r-project.org
Cc:
Sent: Tuesday, August 13, 2013 1:46 PM
Subject: [R] ave function
I've written the following function
CoursePrep <- function (Source, SaveName) {
Clean$TERM <- as.factor(Clean$TERM)
Clean$INST_NUM <- as.factor(Clean$INST_NUM)
Clean$zGrade <- with(Clean, ave(GRADE., list(TERM, INST_NUM), FUN =
scale))
write.csv(Clean,paste(SaveName, "csv", sep ="."), row.names = FALSE)
return(Clean)
}
which is all well and good, but I wan't to throw a shapiro.test in before I
normalize. that is I don't really understand quite how I did ( I got help)
what I wanted to in the
Clean$zGrade <- with(Clean, ave(GRADE., list(TERM, INST_NUM), FUN = scale))
that code for the whole of Clean finds all sets of GRADE.'s that have the
same INST_NUM and TERM computes a mean, subtracts off the mean and divides
by the standard deviation. I would like to for each one of those sets of
grades to call shapiro.test() on the set, to see if it is normal *before* I
assume it is.
I know the naive
with(Clean, shapiro.test( list(TERM, INST_NUM)))
doesn't work.
with(Clean, ave(GRADE., list(TERM, INST_NUM), FUN =
function(x)shapiro.test(x)))
which returns
Error in shapiro.test(x) : sample size must be between 3 and 5000
and I have checked that the sets selected are all of length between 3 and
5000.
using the following on my full data
ClassSize <- with(Clean, ave(GRADE., list(TERM, INST_NUM), FUN =
function(x)length(x)))
> summary(ClassSize)
Min. 1st Qu. Median Mean 3rd Qu. Max.
22.0 198.0 241.0 244.4 279.0 466.0
here is some sample data
GRADE TERM INST_NUM
1, 9, 1
2, 9, 1
3, 9, 1
1.5, 8, 2
1.75, 8, 2
2, 8, 2
0.5, 9, 2
2, 9, 2
3.5, 9, 2
3.5, 8, 1
3.75, 8, 1
4, 8, 1
and hopefully the code would test the following set of grades
(1,2,3)(1.5,1.75,2)(0.5,2,3.5)(3.5,3.75,4)
Thanks Robert
[[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.
More information about the R-help
mailing list