I have a data.frame datas which have two columns A and B. I want to filter column A by some values and to get a value list which contain the value in B. Best wishes! [[alternative HTML version deleted]]
> -----Original Message----- > From: r-help-bounces at r-project.org [mailto:r-help-bounces at r-project.org] On Behalf > Of caocheng?? > Sent: Sunday, September 28, 2008 7:26 PM > To: R-help at r-project.org > Subject: [R] does there any function like sumif in excel? > > I have a data.frame datas which have two columns A and B. > I want to filter column A by some values and to get a value list which > contain the value in B. > Best wishes! >Not sure if I am interpreting you question correctly, but you could do something like datas <-data.frame(1:10,rnorm(10)) names(datas) <- c("A","B") rslt <- datas[ datas[, 'A'] %in%(1:5) , ] where datas[,'a'] %in%(1:5) is the example filter criteria that I used for the example. What is the nature of your data, and what are your filter criteria? Dan Daniel Nordlund Bothell, WA USA
yourData$B[yourData$A == someValue] On Sun, Sep 28, 2008 at 10:25 PM, caocheng?? <caocheng8230 at gmail.com> wrote:> I have a data.frame datas which have two columns A and B. > I want to filter column A by some values and to get a value list which > contain the value in B. > Best wishes! > > [[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. >-- Jim Holtman Cincinnati, OH +1 513 646 9390 What is the problem that you are trying to solve?
There are several ways to subset the dataframe ?select will give you one. or mydata[mydata$A=value]<- mydata then apply sum() I do not think there is one single command equivalent to sumif() --- On Sun, 9/28/08, caocheng?? <caocheng8230 at gmail.com> wrote:> From: caocheng?? <caocheng8230 at gmail.com> > Subject: [R] does there any function like sumif in excel? > To: R-help at r-project.org > Received: Sunday, September 28, 2008, 10:25 PM > I have a data.frame datas which have two columns A and B. > I want to filter column A by some values and to get a value > list which > contain the value in B. > Best wishes! > > [[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.__________________________________________________________________ Yahoo! Canada Toolbar: Search from anywhere on the web, and bookmark your favourite sites. Download it now at http://ca.toolbar.yahoo.com.