[adegenet-forum] extracting genefreq $tab from an indexed list
Vikram Chhatre
crypticlineage at gmail.com
Mon Mar 30 14:11:24 CEST 2015
Hi Roman,
Thank you for the explanation. The following does not work.
>mygenfreqT <- lapply(mygenfreq, FUN=function(x) t(x at tab))
Error in t(x at tab) :
trying to get slot "tab" from an object of a basic class ("list") with no
slots
Someone else suggested another solution, which seems to have worked:
>mygenfreqT <- lapply(lapply(mygenfreq, "[[", "tab"), function(x) t(x))
> head(mygenfreqT[[1]])
1 2 3 4 5 6 7 8 9 10 11
12
L0001.1 0.60 0.500 0.325 0.675 0.600 0.500 0.500 0.375 0.550 0.475 0.350
0.275
L0001.2 0.40 0.500 0.675 0.325 0.400 0.500 0.500 0.625 0.450 0.525 0.650
0.725
L0002.1 0.30 0.150 0.175 0.250 0.275 0.400 0.325 0.325 0.475 0.275 0.175
0.150
Any other solutions are welcome.
Thanks
Vikram
On Mon, Mar 30, 2015 at 2:09 AM, Roman Lustrik <roman.lustrik at biolitika.si>
wrote:
> Oops, make that `lapply(x, FUN = function(x) x at tab)` <x at tab)>.
>
> Cheers,
> Roman
>
> ----
> In god we trust, all others bring data.
>
> ------------------------------
> *From: *"Roman Lustrik" <roman.lustrik at biolitika.si>
> *To: *"Vikram Chhatre" <crypticlineage at gmail.com>
> *Cc: *adegenet-forum at lists.r-forge.r-project.org
> *Sent: *Monday, March 30, 2015 8:08:22 AM
> *Subject: *Re: [adegenet-forum] extracting genefreq $tab from an indexed
> list
>
>
> S4 objects are different to the classical S3 object like data.frames,
> lists and other "basic" objects. One of their peculiarities is that they're
> accessed through "@" operator. In truth, user is not meant to access the
> slots directly - the developer should provide methods to access all the
> slots that she or he deems appropriate for user to access. No method could
> mean either it hasn't been implemented yet, or is not implemented by design
> (Thibaut will have more to say about this).
>
> And now crux of the matter. Your first two examples work because lists
> can be accessed through various operators. This is often done via `lapply(X
> = x, FUN = "[[", "element_name")`. In your case, you can try creating an
> anonymous function that accesses the slot.
>
> library(adegenet)
> data(nancycats)
> x <- list(nancycats)
> lapply(x, FUN = function(x) x$tab)
>
>
>
> Cheers,
>
> Roman
>
>
>
>
> ----
> In god we trust, all others bring data.
>
> ------------------------------
> *From: *"Vikram Chhatre" <crypticlineage at gmail.com>
> *To: *adegenet-forum at lists.r-forge.r-project.org
> *Sent: *Monday, March 30, 2015 4:25:16 AM
> *Subject: *[adegenet-forum] extracting genefreq $tab from an indexed list
>
> I am working with hundreds of genpop objects indexed in a list. Using
> lapply and makefreq functions, population gene frequencies were stored in
> individual objects (1 per data set).
>
> Here is an example with just three objects:
>
> >summary(mygenpop)
> Length Class Mode
> data1.str 1 genpop S4
> data2.str 1 genpop S4
> data3.str 1 genpop S4
>
> >mygenfreq <- lapply(mygenpop, function(x) makefreq(x, truenames=TRUE))
>
> >summary(mygenfreq)
> Length Class Mode
> data1.str 3 -none- list
> data2.str 3 -none- list
> data3.str 3 -none- list
>
> >summary(mygenfreq[[1]]$tab)
> > str(mygenfreq[[1]])
> $ tab : num [1:30, 1:1974] 0.6 0.5 0.325 0.675 0.6 0.5 0.5 0.375 0.55
> 0.475 ...
> $ nobs: num [1:30, 1:1000] 40 40 40 40 40 40 40 40 40 40 ...
>
> Next job is to work with the $tab matrix, but I am not sure how to access
> it from all objects in one command.
>
> >mygenfreqT <- lapply(mygenfreq[[1:3]]$tab, function(x) t(x))
>
> This throws an error. The syntax seems to be wrong, but I am not sure
> how to fix this. Thanks for any help.
>
> Vikram
>
>
>
> _______________________________________________
> adegenet-forum mailing list
> adegenet-forum at lists.r-forge.r-project.org
> https://lists.r-forge.r-project.org/cgi-bin/mailman/listinfo/adegenet-forum
>
>
> _______________________________________________
> adegenet-forum mailing list
> adegenet-forum at lists.r-forge.r-project.org
> https://lists.r-forge.r-project.org/cgi-bin/mailman/listinfo/adegenet-forum
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.r-forge.r-project.org/pipermail/adegenet-forum/attachments/20150330/ea9bfc7b/attachment.html>
More information about the adegenet-forum
mailing list