stephen sefick
2008-Apr-04 15:44 UTC
[R] loop? apply? I want to repeat a task through 208 itterations.
structure(list(RM215alk = c(15, 13, 12, 14, NA, 13, 16, 13, 16, #subset of data 13, 17, 13, 19, 13, 14, 14, 15, 15, 14, 16, 14, 15, 13, 14), NSCl = c(NA, NA, 2.9, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA)), .Names = c("RM215alk", "NSCl"), class = "data.frame", row.names = c(NA, -24L)) apply(if n>=3(x.f, 2, shapiro.test)else(NULL)) #crappy code showing my lack of knowledge on the subject I would like to apply this to a 208 column data matrix, and this is the first time I have tried a repetitive task in R- so please bear with me. the shapiro.test requires 3 to 5000 observations and there are some columns that don't have three observation making it unnecessary to preform a test for normality. How do I do this? thanks stephen -- Let's not spend our time and resources thinking about things that are so little or so large that all they really do for us is puff us up and make us feel like gods. We are mammals, and have not exhausted the annoying little problems of being mammals. -K. Mullis
jim holtman
2008-Apr-04 21:24 UTC
[R] loop? apply? I want to repeat a task through 208 itterations.
I think this is what you want to do. I did not have 'shaprio.test' so I just returned a value:> x <- structure(list(RM215alk = c(15, 13, 12, 14, NA, 13, 16, 13, 16,+ #subset of data + 13, 17, 13, 19, 13, 14, 14, 15, 15, 14, 16, 14, 15, 13, 14), + NSCl = c(NA, NA, 2.9, NA, NA, NA, NA, NA, NA, NA, NA, NA, + NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA)), .Names = c("RM215alk", + "NSCl"), class = "data.frame", row.names = c(NA, -24L))> > apply(x, 2, function(.col){+ if (sum(!is.na(.col)) >= 3) 3 # I don't have this function: shaprio.test(.col) + else NULL + }) $RM215alk [1] 3 $NSCl NULL On Fri, Apr 4, 2008 at 10:44 AM, stephen sefick <ssefick at gmail.com> wrote:> structure(list(RM215alk = c(15, 13, 12, 14, NA, 13, 16, 13, 16, > #subset of data > 13, 17, 13, 19, 13, 14, 14, 15, 15, 14, 16, 14, 15, 13, 14), > NSCl = c(NA, NA, 2.9, NA, NA, NA, NA, NA, NA, NA, NA, NA, > NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA)), .Names = c("RM215alk", > "NSCl"), class = "data.frame", row.names = c(NA, -24L)) > > apply(if n>=3(x.f, 2, shapiro.test)else(NULL)) #crappy code showing my > lack of knowledge on the subject > > I would like to apply this to a 208 column data matrix, and this is > the first time I have tried a repetitive task in R- so please bear > with me. the shapiro.test requires 3 to 5000 observations and there > are some columns that don't have three observation making it > unnecessary to preform a test for normality. How do I do this? > thanks > > stephen > -- > Let's not spend our time and resources thinking about things that are > so little or so large that all they really do for us is puff us up and > make us feel like gods. We are mammals, and have not exhausted the > annoying little problems of being mammals. > > -K. Mullis > > ______________________________________________ > 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. >-- Jim Holtman Cincinnati, OH +1 513 646 9390 What is the problem you are trying to solve?
anna freni sterrantino
2008-Apr-04 21:31 UTC
[R] loop? apply? I want to repeat a task through 208 itterations.
hi Stephen, you may want to check ?apply What you want is : a<-matrix(1:120,10,20) a[1:8,1:2]=NA apply(a,2, function(x) if(sum(!is.na(x)) > (length(x)-3)) shapiro.test(x) else NA ) Cheers Anna ----- Messaggio originale ----- Da: stephen sefick <ssefick@gmail.com> A: r-help@r-project.org Inviato: Venerdì 4 aprile 2008, 8:44:45 Oggetto: [R] loop? apply? I want to repeat a task through 208 itterations. structure(list(RM215alk = c(15, 13, 12, 14, NA, 13, 16, 13, 16, #subset of data 13, 17, 13, 19, 13, 14, 14, 15, 15, 14, 16, 14, 15, 13, 14), NSCl = c(NA, NA, 2.9, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA)), .Names = c("RM215alk", "NSCl"), class = "data.frame", row.names = c(NA, -24L)) apply(if n>=3(x.f, 2, shapiro.test)else(NULL)) #crappy code showing my lack of knowledge on the subject I would like to apply this to a 208 column data matrix, and this is the first time I have tried a repetitive task in R- so please bear with me. the shapiro.test requires 3 to 5000 observations and there are some columns that don't have three observation making it unnecessary to preform a test for normality. How do I do this? thanks stephen -- Let's not spend our time and resources thinking about things that are so little or so large that all they really do for us is puff us up and make us feel like gods. We are mammals, and have not exhausted the annoying little problems of being mammals. -K. Mullis ______________________________________________ R-help@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. La casella di posta intelligente. [[alternative HTML version deleted]]