[R] using subset

Petr Pikal petr.pikal at precheza.cz
Mon Dec 6 14:20:48 CET 2004



On 6 Dec 2004 at 7:55, Doran, Harold wrote:

> Antonio:
> 
> If the variable you are subsetting is a factor with multiple levels
> (and it appears you have 15), then the levels of the factor remain and
> will show up in summary, but your data set will only include the rows
> of data that you want. I am pretty sure subset has worked properly in
> your case.
> 
> Try 
> 
> > data[1:20,]
> 
> And just look at your data to see.

Hi Antonio

If you want to get rid of factor levels in your subsetted data in 
species column,

data2$species <- factor(data2$species)

should do the trick

Cheers
Petr


> 
> -----Original Message-----
> From: r-help-bounces at stat.math.ethz.ch
> [mailto:r-help-bounces at stat.math.ethz.ch] On Behalf Of Antonio Olinto
> Sent: Monday, December 06, 2004 7:45 AM To: R-help Subject: [R] using
> subset
> 
> Hi,
> 
> I have doubts in using subset command. I have a list of, lets say, 15
> species and I want to make a subset with only 2 of them. I'm the
> command data2 <- subset(data1, species=="sp1"|species=="sp2")
> 
> Nevertheless, when I ask for the summary (summary(data2)) the others
> species names still apearing. Also I tried data2<-data1(data1$species
> %in% c("sp1","sp2")),]
> 
> But I got the same result. How can I get a "clean" subset?
> 
> Thanks for any help. Best regards.
> 
> Antonio Olinto
> 
> 
> 
> -------------------------------------------------
> WebMail Bignet - O seu provedor do litoral www.bignet.com.br
> 
> ______________________________________________
> R-help at stat.math.ethz.ch mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide!
> http://www.R-project.org/posting-guide.html
> 
> ______________________________________________
> R-help at stat.math.ethz.ch mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide!
> http://www.R-project.org/posting-guide.html

Petr Pikal
petr.pikal at precheza.cz




More information about the R-help mailing list