[R] subset dataframe/list
Cecilia Carmo
cecilia.carmo at ua.pt
Mon Jun 1 22:18:30 CEST 2009
It doesn't work. b1 was substituted by NA's with this
message:
Warning message:
NAs introduced by coercion
I will see in the webpage that you mentioned.
Thanks,
Cecília
Em Mon, 1 Jun 2009 13:23:12 -0400
David Winsemius <dwinsemius at comcast.net> escreveu:
>
> On Jun 1, 2009, at 1:01 PM, Cecilia Carmo wrote:
>
>> Hi R-helpers!
>>
>> I have the following object:
>>> head(coeficientes)
>> caedois b1 b2 b3
>> 1 1 0,033120395 -20,29478338 -0,274638864
>> 2 2 -0,040629634 74,54239889 -0,069958424
>> 3 5 -0,001116816 35,2398622 0,214327185
>> 4 10 0,171875
>> 5 14 0,007288399 40,06560548 -0,081828338
>> 6 15 0,027530346 0,969969409 0,102775555
>>
>> I´ve tried to subset it like this:
>>> coefSelected<-subset(coeficientes,"b1">0)
>> but it does nothing
>>
>> Then I’ve tried:
>>> coefSelected<-subset(coeficientes,b1>0)
>> But I´ve got the following
>> Warning message:
>> In Ops.factor(b1, 0) : > not meaningful for factors
>
> So the b1 variable is a factor. How it got that way is
>hard to determine.
>>
>>
>> So I’ve tried:
>>> coefSelected<-subset(coeficientes,coeficientes$b1>0)
>> Warning message:
>> In Ops.factor(coeficientes$b1, 0) : > not meaningful for
>>factors
>>
>> I´ve done
>>> mode(coeficientes)
>> [1] "list"
>
> So coeficientes could be just a list or more likely it
>is a data.frame.
>
> What happens if you convert b1 to numeric? Try this way:
>
> coeficientes$b1 <- as.numeric(
>as.character(coeficientes$b1) )
>
> Then try subsetting.
>
> See:
>http://cran.r-project.org/doc/FAQ/R-FAQ.html#How-do-I-convert-factors-to-numeric_003f
>
>>
>>
>> But I don´t know how to handle it!
>> Coul anyone help me?
>> Thanks,
>>
>> Cecília Carmo (Universidade de Aveiro – Portugal
>>
>> ______________________________________________
>> R-help at r-project.org mailing list
>> https://stat.ethz.ch/mailman/listinfo/r-help
>> PLEASE do read the posting guide
>>http://www.R-project.org/posting-guide.html
>> and provide commented, minimal, self-contained,
>>reproducible code.
>
> David Winsemius, MD
> Heritage Laboratories
> West Hartford, CT
>
More information about the R-help
mailing list