Hi, I have the following dataframe:> temp<-data.frame(a=c(1,1,2), b=2:4, c=1:3) > row.names(temp)<-c("D", "E", "F") > tempa b c D 1 2 1 E 1 3 2 F 2 4 3 I would like R to tell me which rows has value "a" equal to 1. The answer is the first row and the second row, or row D and row E. Which function should i use? function subset? function which? Thanks! [[alternative HTML version deleted]]
What do you think? This is covered in the Introduction to R document that comes with R. -- Sent from my phone. Please excuse my brevity. On September 19, 2016 8:37:30 PM PDT, John <miaojpm at gmail.com> wrote:>Hi, > > I have the following dataframe: > >> temp<-data.frame(a=c(1,1,2), b=2:4, c=1:3) >> row.names(temp)<-c("D", "E", "F") >> temp > a b c >D 1 2 1 >E 1 3 2 >F 2 4 3 > > I would like R to tell me which rows has value "a" equal to 1. The >answer is the first row and the second row, or row D and row E. Which >function should i use? function subset? function which? > > Thanks! > > [[alternative HTML version deleted]] > >______________________________________________ >R-help at r-project.org mailing list -- To UNSUBSCRIBE and more, see >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.
On 9/19/2016 10:37 PM, John wrote:> Hi, > > I have the following dataframe: > >> temp<-data.frame(a=c(1,1,2), b=2:4, c=1:3) >> row.names(temp)<-c("D", "E", "F") >> temp > a b c > D 1 2 1 > E 1 3 2 > F 2 4 3 > > I would like R to tell me which rows has value "a" equal to 1. The > answer is the first row and the second row, or row D and row E. Which > function should i use? function subset? function which?row.names(temp[temp$a==1,]) -- -- Robert W. Baer, Ph.D. Professor of Physiology Kirksville College of Osteopathic Medicine A T Still University of Health Sciences 800 W. Jefferson St Kirksville, MO 63501 660-626-2321 Department 660-626-2965 FAX
There are many good R tutorials on the web. Some recommendations can be found here: https://www.rstudio.com/online-learning/#R Please spend some time learning fundamental R constructs and functionality before posting what appear to be very basic questions here. Cheers, Bert Bert Gunter "The trouble with having an open mind is that people keep coming along and sticking things into it." -- Opus (aka Berkeley Breathed in his "Bloom County" comic strip ) On Mon, Sep 19, 2016 at 8:37 PM, John <miaojpm at gmail.com> wrote:> Hi, > > I have the following dataframe: > >> temp<-data.frame(a=c(1,1,2), b=2:4, c=1:3) >> row.names(temp)<-c("D", "E", "F") >> temp > a b c > D 1 2 1 > E 1 3 2 > F 2 4 3 > > I would like R to tell me which rows has value "a" equal to 1. The > answer is the first row and the second row, or row D and row E. Which > function should i use? function subset? function which? > > Thanks! > > [[alternative HTML version deleted]] > > ______________________________________________ > R-help at r-project.org mailing list -- To UNSUBSCRIBE and more, see > 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.