[adegenet-forum] extracting genefreq $tab from an indexed list
Jombart, Thibaut
t.jombart at imperial.ac.uk
Mon Mar 30 14:53:02 CEST 2015
Hi there,
the operator [[]] returns a slot of a list, not a list, which is an issue here. To subset a list you should use [].
Otherwise, to do what you want, you need something like:
lapply(mygenfreq, function(e) t(e$tab))
Note that as of adegnet_2.0-0, there will be a simpler interface to get frequencies (tab(x, freq=TRUE)).
Cheers
Thibaut
________________________________
From: adegenet-forum-bounces at lists.r-forge.r-project.org [adegenet-forum-bounces at lists.r-forge.r-project.org] on behalf of Vikram Chhatre [crypticlineage at gmail.com]
Sent: 30 March 2015 03:25
To: adegenet-forum at lists.r-forge.r-project.org
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
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.r-forge.r-project.org/pipermail/adegenet-forum/attachments/20150330/e723430f/attachment.html>
More information about the adegenet-forum
mailing list