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]]
with data named dat1 match(2, dat1$samp.depth) John Kane Kingston ON Canada> -----Original Message----- > From: catalinroibu at gmail.com > Sent: Tue, 27 Aug 2013 20:24:04 +0300 > To: r-help at r-project.org > 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.____________________________________________________________ GET FREE SMILEYS FOR YOUR IM & EMAIL - Learn more at http://www.inbox.com/smileys Works with AIM?, MSN? Messenger, Yahoo!? Messenger, ICQ?, Google Talk? and most webmails
Hello, Try the following. dat <- read.table(text = " 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 ", header = TRUE) idx <- which(dat$samp.depth == 2)[1] rownames(dat)[idx] Hope this helps, Rui Barradas Em 27-08-2013 18:24, catalin roibu escreveu:> 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. >
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.
Well I don't see anything that looks like a year but go from this dat1[match(2, dat1$samp.depth),] and pick off what you want I guess John Kane Kingston ON Canada -----Original Message----- From: catalinroibu at gmail.com Sent: Tue, 27 Aug 2013 20:46:27 +0300 To: jrkrideau at inbox.com Subject: Re: [R] find row name with specific value Thank you! But I want to view to year, not the row index. Is there a possibility? On 27 August 2013 20:41, John Kane <jrkrideau at inbox.com> wrote: with data named dat1 match(2, dat1$samp.depth) John Kane Kingston ON Canada > -----Original Message----- > From: catalinroibu at gmail.com > Sent: Tue, 27 Aug 2013 20:24:04 +0300 > To: r-help at r-project.org > 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 [http://silvic.usv.ro] >> ? ? ? [[alternative HTML version deleted]]> > ______________________________________________ > R-help at r-project.org mailing list > https://stat.ethz.ch/mailman/listinfo/r-help [https://stat.ethz.ch/mailman/listinfo/r-help] > PLEASE do read the posting guide > http://www.R-project.org/posting-guide.html [http://www.R-project.org/posting-guide.html] > and provide commented, minimal, self-contained, reproducible code. ____________________________________________________________ GET FREE SMILEYS FOR YOUR IM & EMAIL - Learn more at http://www.inbox.com/smileys [http://www.inbox.com/smileys] Works with AIM?, MSN? Messenger, Yahoo!? Messenger, ICQ?, Google Talk? and most webmails -- --- 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 [http://silvic.usv.ro] ____________________________________________________________ FREE 3D EARTH SCREENSAVER - Watch the Earth right on your desktop!
I would tend to go for very basic approach. Since there is no column of data named 'year' I will assume that the row names contain the year. min( row.names(mydata)[mydata$samp.depth==2] ) Although it's not pretty, I think it comes close to representing in R the language the request as presented in the English language. This does assume all of the row names convert correctly to a numeric year if one were to do as.numeric(row.names(mydata)) -- Don MacQueen Lawrence Livermore National Laboratory 7000 East Ave., L-627 Livermore, CA 94550 925-423-1062 On 8/27/13 10:24 AM, "catalin roibu" <catalinroibu at gmail.com> wrote:>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.