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 su
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
You can also use droplevels() on your new object (as of R 2.12).
Cheers,
Roman
On Sun, Apr 24, 2011 at 3:42 PM, 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.
>
By default, read.csv() turns character variables into factors, using all the
unique values as the levels.
subset() retains those levels by default, as they are a vital element of the
data. If you are studying some attribute of men and women, say height,
even if you are only looking at the heights
Thank you very much for your response, Christian, Roman, and Sarah.
Sarah,
I am trying your suggestion but I cannot see the levels:
> pa2 = factor(subset(pa, influencia=="AP")$influencia)
> levels(pa2$influencia)
Error in pa2$influencia : $ operator is invalid for atomic vectors
Best,
Manuel
pa2 <- subset(pa, influencia=="AP")
pa2$influencia <- factor(pa2$influencia)
levels(pa2$influencia)
On Sun, Apr 24, 2011 at 11:24 AM, Manuel Spínola wrote:
> Thank you very much for your response, Christian, Roman, and Sarah.
>
> Sarah,
>
> I am trying your suggestion but I cannot see the levels:
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
Thank you very much Gustavo.
That works.
Manuel
On 24/04/2011 08:30 a.m., Gustavo Carvalho wrote:
> pa2<- subset(pa, influencia=="AP")
> pa2$influencia<- factor(pa2$influencia)
> levels(pa2$influencia)
>
> On Sun, Apr 24, 2011 at 11:24 AM, Manuel SpÃnola
> wrote:
>> Thank you very much for yo
Thank you for all the responses.
Is there a way to do a complete data set from an object in R?
I have a data set with more than 3000 columns.
The subsetting is ok but it could be dangerous if you are using other
factors to do some analysis as you need to specify the levels for all
your factors
If this isn't already answered:
I don't quite understand the question: what do you mean by "do a
complete data set from an object in R"? What do you mean by "the
subsetting is dangerous ... as you need to specify the levels for all
your factors again"?
(What do your 3000 columns of data re
Thank you very much Ben.
I was doing an analysis of indicator species with the subset data and
the other levels were still in my subset data and the analysis was
considering them in the analysis.
My 3000 columns are plant species presence/absence type of data.
Best,
Manuel
On 26/04/2011 12:06
878
ch...@trickysolutions.com.au
-Original Message-
From: r-sig-ecology-boun...@r-project.org
[mailto:r-sig-ecology-boun...@r-project.org] On Behalf Of Manuel Spínola
Sent: Monday, 25 April 2011 12:37 AM
To: Christian Parker
Cc: r-sig-ecology@r-project.org
Subject: Re: [R-sig-eco] subsett
12 matches
Mail list logo