<div dir="ltr">Hello, <div><br></div><div>Thanks a lot for your replies!</div><div><br></div><div>For this command, the trick with the "which" worked well. </div><div>I wanted to keep my @pop as the another variable with the Populations for each sample. But the strata approach is very interesting if I do analyses with multiple population groupings!</div><div><br></div><div>Thank you for the help, adegenet forum is great!</div><div><br></div><div>Amaranta.</div><br><div class="gmail_quote"><div dir="ltr">Missatge de Zhian Kamvar <<a href="mailto:kamvarz@science.oregonstate.edu">kamvarz@science.oregonstate.edu</a>> del dia dj., 25 d’oct. 2018 a les 3:11:<br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
<div>
<div dir="ltr">Just to pop in here: This looks like a situation that is best solved by using the strata slot.<br>
<br>
> I want to subset part of the individuals of my genlight object according<br>
> to a variable stored in the @other slot. I get an error I don't understand.<br>
> I stored 3 categorical variables in the @other slot. It looks like that:<br>
> *> str(other(<a href="http://asocial.gl" rel="noreferrer" target="_blank">asocial.gl</a> <<a href="http://asocial.gl" rel="noreferrer" target="_blank">http://asocial.gl</a>>))*<br>
> List of 3<br>
> $ basin : Factor w/ 3 levels "Rhine","Rhone_Valais",..: NA 2 NA 2 2 2 2 2<br>
> 2 2 ...<br>
> $ Sgeno : Factor w/ 3 levels "mm","mp","pp": 1 2 3 1 1 1 1 1 1 1 ...<br>
<div>> $ Spheno: Factor w/ 2 levels "M","P": 1 2 2 1 1 1 1 1 1 1 ...</div>
<div><br>
</div>
<div>Since each element in the list is the same length, you can convert it to a data frame and use it as the population strata like so:<br>
</div>
<div><br>
</div>
<div><span style="font-family:monospace,monospace">strata(<a href="http://asocial.gl" target="_blank">asocial.gl</a>) <- data.frame(other(<a href="http://asocial.gl" target="_blank">asocial.gl</a>))</span></div>
<div><br>
</div>
<div>When you do this, you can first set the population factor to be "basin" and then use adegenet's built-in population-subsetting to extract the Rhone_Valias population:<br>
<br>
</div>
<div><span style="font-family:monospace,monospace">setPop(<a href="http://ascocial.gl" target="_blank">ascocial.gl</a>) <- ~basin # assigns the "basin" column from the strata to be the population factor (make sure you have the strata assigned first)<br>
</span></div>
<div><span style="font-family:monospace,monospace"><br>
</span></div>
<div><span style="font-family:monospace,monospace"><a href="http://asocial.gl" target="_blank">asocial.gl</a>[pop = "Rhone_Valias"] # includes only the individuals in Rhone_Valias
</span><br>
</div>
<div>
<div><br>
</div>
<div>Hope that helps!</div>
<div>Zhian<br>
</div>
<div>
<div class="gmail_quote"><br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
Date: Thu, 25 Oct 2018 12:33:45 +0100<br>
From: Thibaut Jombart <<a href="mailto:thibautjombart@gmail.com" target="_blank">thibautjombart@gmail.com</a>><br>
To: <a href="mailto:amaranta.fontcuberta@unil.ch" target="_blank">amaranta.fontcuberta@unil.ch</a><br>
Cc: "<a href="mailto:adegenet-forum@lists.r-forge.r-project.org" target="_blank">adegenet-forum@lists.r-forge.r-project.org</a>"<br>
<<a href="mailto:adegenet-forum@lists.r-forge.r-project.org" target="_blank">adegenet-forum@lists.r-forge.r-project.org</a>><br>
Subject: Re: [adegenet-forum] trouble accessing @other<br>
Message-ID:<br>
<CANPRA+oJ_0Qa7zt2r=<a href="mailto:hEw5M3U9%2BEOr6_Z94faryW0q%2BvHZntzw@mail.gmail.com" target="_blank">hEw5M3U9+EOr6_Z94faryW0q+vHZntzw@mail.gmail.com</a>><br>
Content-Type: text/plain; charset="utf-8"<br>
<br>
Hi there,<br>
<br>
I think the NA in your logical vector may be the problem; can you try<br>
wrapping a 'which' around it?<br>
<br>
to_keep <- which(asocial.gl@other$basin=="Rhone_Valais")<br>
<a href="http://asocial.gl" rel="noreferrer" target="_blank">asocial.gl</a>[to_keep,]<br>
<br>
Let us know if it works.<br>
Best<br>
Thibaut<br>
<br>
--<br>
Dr Thibaut Jombart<br>
Associate Professor in Outbreak Analytics, London School of Hygiene and<br>
Tropical Medicine<br>
Senior Lecturer in Genetic Analysis, Imperial College London<br>
President of RECON: <a href="http://repidemicsconsortium.org" rel="noreferrer" target="_blank">
repidemicsconsortium.org</a><br>
<a href="https://thibautjombart.netlify.com" rel="noreferrer" target="_blank">https://thibautjombart.netlify.com</a><br>
Twitter: @TeebzR<br>
<br>
<br>
On Thu, 25 Oct 2018 at 00:43, Amaranta Fontcuberta <<br>
<a href="mailto:amaranta.fontcuberta@unil.ch" target="_blank">amaranta.fontcuberta@unil.ch</a>> wrote:<br>
<br>
> Hello,<br>
><br>
> I want to subset part of the individuals of my genlight object according<br>
> to a variable stored in the @other slot. I get an error I don't understand.<br>
> I stored 3 categorical variables in the @other slot. It looks like that:<br>
> *> str(other(<a href="http://asocial.gl" rel="noreferrer" target="_blank">asocial.gl</a> <<a href="http://asocial.gl" rel="noreferrer" target="_blank">http://asocial.gl</a>>))*<br>
> List of 3<br>
> $ basin : Factor w/ 3 levels "Rhine","Rhone_Valais",..: NA 2 NA 2 2 2 2 2<br>
> 2 2 ...<br>
> $ Sgeno : Factor w/ 3 levels "mm","mp","pp": 1 2 3 1 1 1 1 1 1 1 ...<br>
> $ Spheno: Factor w/ 2 levels "M","P": 1 2 2 1 1 1 1 1 1 1 ...<br>
><br>
> When I try to subset my dataset, I get this error:<br>
> *> <a href="http://asocial.gl" rel="noreferrer" target="_blank">asocial.gl</a> <<a href="http://asocial.gl" rel="noreferrer" target="_blank">http://asocial.gl</a>>[asocial.gl@other$basin=="Rhone_Valais",]*<br>
> Error in .local(x, i, j, ..., drop = drop) :<br>
> trying to get slot "n.loc" from an object of a basic class ("NULL") with<br>
> no slots<br>
><br>
> The condition seems to work well, since when I call it alone, it outputs a<br>
> list of TRUE, FALSE that corresponds well to the individuals I want to<br>
> keep.<br>
> *> asocial.gl@other$basin=="Rhone_Valais"*<br>
> [1] NA FALSE NA FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE<br>
> TRUE TRUE TRUE<br>
> [15] TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE<br>
> TRUE TRUE TRUE<br>
> ...<br>
><br>
> I use the same subseting command to select according to the @pop slot and<br>
> it works well.<br>
><br>
><br>
> Any help will be appreciated,<br>
><br>
> Thanks a lot in advance,<br>
><br>
> Amaranta.<br>
> ----------------------------------------------------------<br>
> Amaranta Fontcuberta, assistante dipl?m?e<br>
> Dept. ?cologie et ?volution<br>
> Universit? de Lausanne<br>
><br>
> _______________________________________________<br>
> adegenet-forum mailing list<br>
> <a href="mailto:adegenet-forum@lists.r-forge.r-project.org" target="_blank">adegenet-forum@lists.r-forge.r-project.org</a><br>
> <a href="https://lists.r-forge.r-project.org/cgi-bin/mailman/listinfo/adegenet-forum" rel="noreferrer" target="_blank">
https://lists.r-forge.r-project.org/cgi-bin/mailman/listinfo/adegenet-forum</a><br>
-------------- next part --------------<br>
An HTML attachment was scrubbed...<br>
URL: <<a href="http://lists.r-forge.r-project.org/pipermail/adegenet-forum/attachments/20181025/e9b2eb30/attachment-0001.html" rel="noreferrer" target="_blank">http://lists.r-forge.r-project.org/pipermail/adegenet-forum/attachments/20181025/e9b2eb30/attachment-0001.html</a>><br>
<br>
------------------------------<br>
<br>
Subject: Digest Footer<br>
<br>
_______________________________________________<br>
adegenet-forum mailing list<br>
<a href="mailto:adegenet-forum@lists.r-forge.r-project.org" target="_blank">adegenet-forum@lists.r-forge.r-project.org</a><br>
<a href="https://lists.r-forge.r-project.org/cgi-bin/mailman/listinfo/adegenet-forum" rel="noreferrer" target="_blank">https://lists.r-forge.r-project.org/cgi-bin/mailman/listinfo/adegenet-forum</a><br>
<br>
------------------------------<br>
<br>
End of adegenet-forum Digest, Vol 122, Issue 5<br>
**********************************************<br>
</blockquote>
</div>
</div>
</div>
</div>
</div>
</blockquote></div></div>