[R-sig-eco] subsetting data in R

Chris Howden chris at trickysolutions.com.au
Fri Apr 29 08:57:19 CEST 2011


Try

pa2$influencia<-factor(pa2$influencia)




Chris Howden
Founding Partner
Tricky Solutions
Tricky Solutions 4 Tricky Problems
Evidence Based Strategic Development, IP Commercialisation and Innovation,
Data Analysis, Modelling and Training
(mobile) 0410 689 945
(fax / office) (+618) 8952 7878
chris at trickysolutions.com.au


-----Original Message-----
From: r-sig-ecology-bounces at r-project.org
[mailto:r-sig-ecology-bounces at r-project.org] On Behalf Of Manuel Spínola
Sent: Monday, 25 April 2011 12:37 AM
To: Christian Parker
Cc: r-sig-ecology at r-project.org
Subject: Re: [R-sig-eco] subsetting data in R

Thank you Christian.

Following your suggestion I got the following result,

 > pa2 = subset(pa, influencia=="AP")
 > pa2$influencia<-as.factor(pa2$influencia)
 > levels(pa$influencia)
[1] "AID" "AII" "AP"


On 24/04/2011 07:42 a.m., Christian Parker wrote:
> You are creating a new object, but the columns that are stored as
> factors are not being 'refactored' so you are retaining the original
> list of levels. To fix this you can use the factor function after you
> subset
>
> pa2 = subset(pa, influencia=="AID")
> pa2$influencia<-as.factor(pa2$influencia)
>
>
>
> On Apr 24, 2011, at 6:04 AM, Manuel SpC-nola<mspinola10 at gmail.com>
wrote:
>
>> Dear list members,
>>
>> I have a question regarding too subsetting a data set in R.
>>
>> I created an object for my data:
>>
>>> pa = read.csv("espec_indic.csv", header = T, sep=",", check.names =
>>> F)
>>> levels(pa$influencia)
>> [1] "AID" "AII" "AP"
>>
>> The object has 3 levels for influencia (AP, AID, AII)
>>
>> Now I subset only observations with influencia = "AID"
>>
>>> pa2 = subset(pa, influencia=="AID")
>> but if I ask for the levels of influencia still show me the 3 levels,
>> AP, AID, AII.
>>
>>> levels(pa2$influencia)
>> [1] "AID" "AII" "AP"
>>
>> Why is that?
>>
>> I was thinking that I was creating a new data frame with only AID as
>> a level for influencia.
>>
>> How can I make a complete new object with only the observations for
>> "AID" and that the only level for influencia is indeed "AID"?
>>
>> Best,
>>
>> Manuel
>>
>>
>>
>>
>> --
>> *Manuel SpC-nola, Ph.D.*
>> Instituto Internacional en ConservaciC3n y Manejo de Vida Silvestre
>> Universidad Nacional Apartado 1350-3000 Heredia COSTA RICA
>> mspinola at una.ac.cr mspinola10 at gmail.com
>> TelC)fono: (506) 2277-3598
>> Fax: (506) 2237-7036
>> Personal website: Lobito de rC-o
>> <https://sites.google.com/site/lobitoderio/>
>> Institutional website: ICOMVIS<http://www.icomvis.una.ac.cr/>
>>
>>     [[alternative HTML version deleted]]
>>
>> _______________________________________________
>> R-sig-ecology mailing list
>> R-sig-ecology at r-project.org
>> https://stat.ethz.ch/mailman/listinfo/r-sig-ecology


--
*Manuel SpC-nola, Ph.D.*
Instituto Internacional en ConservaciC3n y Manejo de Vida Silvestre
Universidad Nacional Apartado 1350-3000 Heredia COSTA RICA
mspinola at una.ac.cr mspinola10 at gmail.com
TelC)fono: (506) 2277-3598
Fax: (506) 2237-7036
Personal website: Lobito de rC-o
<https://sites.google.com/site/lobitoderio/>
Institutional website: ICOMVIS <http://www.icomvis.una.ac.cr/>

	[[alternative HTML version deleted]]



More information about the R-sig-ecology mailing list