[R] subset dataframe/list

David Winsemius dwinsemius at comcast.net
Mon Jun 1 23:17:03 CEST 2009


So now is the time to back up to the beginning and demonstrate how you  
created the coeficientes object. Ideally you would also provide the  
results of:

dput(coeficientes)

or

str(coeficientes)

Subset will only work with dataframes, so if coeficientes is not a  
dataframe, then you will need to come. It would also be a good idea to  
describe what you are trying to get out of this effort.

-- 
David.

On Jun 1, 2009, at 4:18 PM, Cecilia Carmo wrote:

> 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,
>>>

David Winsemius, MD
Heritage Laboratories
West Hartford, CT




More information about the R-help mailing list