[R] subset function within a function

Lana Schaffer schaffer at scripps.edu
Thu Jul 3 23:25:21 CEST 2008


Hi,
I am using this subset statement and it works
outside a function.
LIS[[i]]<- lapply(LI, subset, select=cov[[i]]) 
However, wrapped inside a function this statement
produces the same values for every LIS[[1]] which
is only the first subset of LI.
Does anyone know why is not working correctly inside
a function?

ff = factor(covariate)
nLev <- nlevels(ff)
cov <- vector(mode="list",length=nLev)
for (gp in 1:nLev) {
cov[[gp]] <- covariate == levels(ff)[gp]  }

LIS <- vector(mode="list",length=nLev)
#if (SINGLE == T ) LIS[[1]] <- LI else {}
for (i in 1:nLev) 
LIS[[i]]<- lapply(LI, subset, select=cov[[i]]) 


Lana Schaffer
Biostatistics/Informatics
The Scripps Research Institute
DNA Array Core Facility
La Jolla, CA 92037
(858) 784-2263
(858) 784-2994
schaffer at scripps.edu 



More information about the R-help mailing list