[R] printing a single row, but dont know which row to print

David Winsemius dwinsemius at comcast.net
Mon Nov 16 19:48:00 CET 2009


On Nov 16, 2009, at 1:38 PM, baptiste auguie wrote:

> Hi,
>
> Try this,
>
> set.seed(2) # reproducible
> d = matrix(sample(1:20,20), 4, 5)
> d
>
> d[ d[ ,2] == 18 , ]
>
> You may need to test with all.equal if your values are subject to
> rounding errors.
>
> HTH,
>
> baptiste
>
> 2009/11/16 frenchcr <frenchcr at btinternet.com>:
>>
>>
>> I have 20 columns of data, and in column 5 I have a value of 17600  
>> but I
>> dont know which row this value is in (i have over 300,000 rows).
>>
>> I'm trying to do 2 things:
>>
>> 1) I want to find out which row in column 5 has this number in it.

Using baptiste's setup:

 > which(d[, 2]==18)
[1] 4

>>
>> 2) Then I want to print out that row with all the column headers so  
>> i can
>> look at the other parameters in the row that are associated with  
>> this value.
>>
>>
>> How do i do it?
>>
>>
>> --
>> View this message in context: http://old.nabble.com/printing-a-single-row%2C-but-dont-know-which-row-to-print-tp26376647p26376647.html
>> Sent from the R help mailing list archive at Nabble.com.
>>
>> ______________________________________________
>> 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.
>>
>
> ______________________________________________
> 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