[BioC] the function subset inside a function
Mark Robinson
mrobinson at wehi.EDU.AU
Fri Jul 4 01:32:51 CEST 2008
Lana.
Couple things.
1. Perhaps you want to be using the 'subset' argument, not the
'select' argument in the subset command, according to the help on the
subset command:
---------
Arguments:
x: object to be subsetted.
subset: logical expression indicating elements or rows to keep:
missing values are taken as false.
select: expression, indicating columns to select from a data frame.
drop: passed on to '[' indexing operator.
---------
Replace:
lapply(LI, subset, select=cov[[i]])
with:
lapply(LI, FUN=subset, subset=cov[[i]])
but ....
2. The object LI, which you are calling lapply on, is never defined in
your example below, so I could be misleading you. Perhaps you could
give more details.
Mark
On 04/07/2008, at 9:02 AM, Lana Schaffer wrote:
> 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 (which is
> always 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]])
>
>
> -----Original Message-----
> From: Lana Schaffer
> Sent: Thursday, July 03, 2008 3:44 PM
> To: 'bioconductor at stat.math.ethz.ch'
> Subject: the function subset inside a function
>
> Hi,
> I have successfully applied the subset function on a list. However,
> inside a function the subset did not work. Has anyone else run into
> this problem?
>
> 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
>
> _______________________________________________
> Bioconductor mailing list
> Bioconductor at stat.math.ethz.ch
> https://stat.ethz.ch/mailman/listinfo/bioconductor
> Search the archives: http://news.gmane.org/gmane.science.biology.informatics.conductor
------------------------------
Mark Robinson
Epigenetics Laboratory, Garvan
Bioinformatics Division, WEHI
e: m.robinson at garvan.org.au
e: mrobinson at wehi.edu.au
p: 03 9345 2628
f: 03 9347 0852
More information about the Bioconductor
mailing list