# R 2.3.1 I read the data set into R, but the data set have two rows per record. i.e. ......... 105 1 1 1103 1 5 4 8 5 22 105 2 2 2 2 1 2 17 16 26 106 1 2 606 1 5 12 11 9 37 106 2 2 2 2 2 2 16 14 29 107 1 3 611 1 7 9 10 7 33 107 2 2 2 2 2 2 10 13 29 ........... How do you extract the certain columns on the first row set of each? Tthe first row set are like: 105 1 1 1103 1 5 4 8 5 22 106 1 2 606 1 5 12 11 9 37 107 1 3 611 1 7 9 10 7 33 so, nothing gets imported from the second row set. 105 2 2 2 2 1 2 17 16 26 106 2 2 2 2 2 2 16 14 29 107 2 2 2 2 2 2 10 13 29 I tried:> a <- subset(lead.dat, rownumber==1)Error in eval(expr, envir, enclos) : object "rownumber" not found> b <- subset(lead.dat, rownumber==2)Error in eval(expr, envir, enclos) : object "rownumber" not found What is wrong with this? thx much [[alternative HTML version deleted]]
maybe the following is what you're looking for:
lead.dat[!duplicate(rownames(lead.dat)), ]
lead.dat[duplicate(rownames(lead.dat)), ]
I hope it helps.
Best,
Dimitris
----
Dimitris Rizopoulos
Ph.D. Student
Biostatistical Centre
School of Public Health
Catholic University of Leuven
Address: Kapucijnenvoer 35, Leuven, Belgium
Tel: +32/(0)16/336899
Fax: +32/(0)16/337015
Web: http://med.kuleuven.be/biostat/
http://www.student.kuleuven.be/~m0390867/dimitris.htm
Quoting Ethan Johnsons <ethan.johnsons at gmail.com>:
> # R 2.3.1
>
> I read the data set into R, but the data set have two rows per record.
>
> i.e.
>
> .........
> 105 1 1 1103 1 5 4 8 5 22
> 105 2 2 2 2 1 2 17 16 26
> 106 1 2 606 1 5 12 11 9 37
> 106 2 2 2 2 2 2 16 14 29
> 107 1 3 611 1 7 9 10 7 33
> 107 2 2 2 2 2 2 10 13 29
> ...........
>
> How do you extract the certain columns on the first row set of each?
>
> Tthe first row set are like:
> 105 1 1 1103 1 5 4 8 5 22
> 106 1 2 606 1 5 12 11 9 37
> 107 1 3 611 1 7 9 10 7 33
>
> so, nothing gets imported from the second row set.
>
> 105 2 2 2 2 1 2 17 16 26
> 106 2 2 2 2 2 2 16 14 29
> 107 2 2 2 2 2 2 10 13 29
> I tried:
>
>> a <- subset(lead.dat, rownumber==1)
> Error in eval(expr, envir, enclos) : object "rownumber" not found
>> b <- subset(lead.dat, rownumber==2)
> Error in eval(expr, envir, enclos) : object "rownumber" not found
>
> What is wrong with this?
> thx much
>
> [[alternative HTML version deleted]]
>
> ______________________________________________
> 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
> and provide commented, minimal, self-contained, reproducible code.
>
>
Disclaimer: http://www.kuleuven.be/cwis/email_disclaimer.htm
This will work too:> n <- dim(lead.dat)[1] > n[1] 6> ix <- seq(1,n,by=2) > ix[1] 1 3 5> lead.dat[ix,][,1] [,2] [,3] [,4] [,5] [,6] [,7] [,8] [,9] [,10] [1,] 105 1 1 1103 1 5 4 8 5 22 [2,] 106 1 2 606 1 5 12 11 9 37 [3,] 107 1 3 611 1 7 9 10 7 33 -- ================================David Barron Said Business School University of Oxford Park End Street Oxford OX1 1HP