[R] R: subset dataframe/list

David Winsemius dwinsemius at comcast.net
Tue Jun 2 16:52:16 CEST 2009


Also look at the documentation for read.csv2().

--  
David.

On Jun 2, 2009, at 5:43 AM, Cecilia Carmo wrote:

> Thank you all!!!
>
> The problem was the decimal symbol! My data was saved in a txt file,  
> so I’ve introduced the dec="," in «read.table» and it worked.  
> What I’ve done was
> coeficientes<-read.table("coeficientes.txt",sep="\t",header=T,dec=",")
>
> Then, subset worked fine
> coeficientesWanted<-subset(coeficientes,b1>0)
>
> Thanks again,
> Cecília Carmo (Universidade de Aveiro – Portugal)
>
> Doesn´t work neither!
>
>> 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 done
> coeficientes$b1<-as.numeric(as.character(coeficientes$b1))
> And b1 was substituted by NA’s
>
> Then I’ve done
> coeficientes$b1<-as.numeric(coeficientes$b1)
> And b1 was transformed in other numbers
>     caedois   b1           b2           b3
> 1        1    38    -20,29478338 -0,274638864
> 2        2     7     74,54239889 -0,069958424
> 3        5     2     35,2398622  0,214327185
> 4       10    48
> 5       14    15  40,06560548 -0,081828338
> 6       15    31  0,969969409  0,102775555
>
> Thanks anyway,
> Cecília
>
>
> Em Mon, 01 Jun 2009 13:11:48 -0500 (CDT)
> markleeds at verizon.net escreveu:
>> hi: when I sent you my solution,  I didn't realize that you had  
>> factors. if you change the
>> factors  to characters as described in that email, and then use my  
>> approach , i think it should still work.
>> On Jun 1, 2009, markleeds at verizon.net wrote: Hi: coeficientes[, 
>> (coeficientes[,"b1"] > 0)]
>> will i think give you all the rows of the object where b1 is  
>> greater than zero.
>> I can't tell if coeficients is a data frame or a matrix but the  
>> above should work in either case.
>> On Jun 1, 2009, Cecilia Carmo <cecilia.carmo at ua.pt> 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 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"
>> But I don´t know how to handle it!
>> Coul anyone help me?
>> Thanks,
>> Cecília Carmo (Universidade de Aveiro – Portugal

David Winsemius, MD
Heritage Laboratories
West Hartford, CT




More information about the R-help mailing list