[R] find row name with specific value

arun smartpink111 at yahoo.com
Tue Aug 27 19:51:48 CEST 2013



Hi,

May be this helps:

#dat1 is dataset.
with(dat1,tapply(row.names(dat1),list(samp.depth),FUN=head,1))
#     1      2      3 
#"1592" "1596" "1600" 
row.names(dat1)[tapply(seq_len(nrow(dat1)),list(dat1$samp.depth),FUN=head,1)]
#[1] "1592" "1596" "1600"

#or
row.names(dat1)[!duplicated(dat1$samp.depth)]
#[1] "1592" "1596" "1600"
row.names(dat1)[head(which(dat1$samp.depth%in%2),1)]
#[1] "1596"



A.K.



----- Original Message -----
From: catalin roibu <catalinroibu at gmail.com>
To: r-help at r-project.org
Cc: 
Sent: Tuesday, August 27, 2013 1:24 PM
Subject: [R] find row name with specific value

Hello all!
I want to find the first year where is fixed value (eg 2).
My data is like this:
HUMstd    HUMres samp.depth
1592 0.5687519        NA          1
1593 1.5251896        NA          1
1594 1.8168727        NA          1
1595 1.1265923 0.8253599          1
1596 0.8725422 0.7423323          2
1597 0.6744835 0.5443933          2
1598 0.7605894 0.8698533          2
1599 0.6559708 0.8695049          2
1600 0.8606666 0.4699240          3
1601 1.0398217 1.0643867          3
1602 0.5707846 0.7079530          3
1603 0.5136122 0.8443149          3
1604 0.6700944 0.9767793          3
1605 0.7239053 0.9378163          3
1606 0.6772079 0.8428935          3
1607 0.9368149 1.0333812          3
1608 0.7091008 0.7860034          3
1609 1.1177742 1.2792296          3

Thank you!

-
---
Catalin-Constantin ROIBU
Lecturer PhD, Forestry engineer
Forestry Faculty of Suceava
Str. Universitatii no. 13, Suceava, 720229, Romania
office phone     +4 0230 52 29 78, ext. 531
mobile phone   +4 0745 53 18 01
                       +4 0766 71 76 58
FAX:                +4 0230 52 16 64
silvic.usv.ro

    [[alternative HTML version deleted]]

______________________________________________
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.




More information about the R-help mailing list