Re: [R] subsetting a dataframe

2015-06-09 Thread Ryan Derickson
Lots of ways to do this, I use %in% with bracket notation [row, column]. The empty column argument below returns all columns but you could have conditional logic there as well. dd[dd$rows %in% test_rows, ] On Mon, Jun 8, 2015 at 6:44 PM, Bogdan Tanasa wrote: > Dear all, > > would appreciate y

Re: [R] subsetting a dataframe

2015-06-08 Thread William Dunlap
Use is.element(elements,set), or its equivalent, elements %in% set: df <- data.frame(dd = c(1, 2, 3), rows = c("A1", "A2", "A3"), columns = c("B1", "B2", "B3"), numbers = c(400, 500, 600)) test_rows <-c("A1","A3") df[ is.element(df$rows, test_rows

[R] subsetting a dataframe

2015-06-08 Thread Bogdan Tanasa
Dear all, would appreciate your suggestions on subsetting a dataframe : please let's consider an example dataframe df: dd<-c(1,2,3) rows<-c("A1","A2","A3") columns<-c("B1","B2","B3") numbers <- c(400, 500, 600) df <- dataframe(dd,rows,columns, numbers) and a vector : test_rows <-c("A1","A3") ;

Re: [R] Subsetting a dataframe by dynamic column name

2014-03-27 Thread Sneha Bishnoi
t; -Original Message- > From: r-help-boun...@r-project.org > [mailto:r-help-boun...@r-project.org] On Behalf Of Sneha Bishnoi > Sent: Thursday, March 27, 2014 11:06 AM > To: Sarah Goslee > Cc: r-help > Subject: Re: [R] Subsetting a dataframe by dynamic column name > > Hi Sara

Re: [R] Subsetting a dataframe by dynamic column name

2014-03-27 Thread David Carlson
e Cc: r-help Subject: Re: [R] Subsetting a dataframe by dynamic column name Hi Sarah, Thanks! Do agree its over complicated. However looking at the solutions I think I did not state my problem completely. V provides choices for only certain set of columns in Finaldata. So v2 may not represent al

Re: [R] Subsetting a dataframe by dynamic column name

2014-03-27 Thread Sneha Bishnoi
Hi Sarah, Thanks! Do agree its over complicated. However looking at the solutions I think I did not state my problem completely. V provides choices for only certain set of columns in Finaldata. So v2 may not represent all columns of Finaldata. I want to retain columns not provided as a choice for

Re: [R] Subsetting a dataframe by dynamic column name

2014-03-27 Thread Sarah Goslee
There are many ways. You're making it overly complicated Here, in an actual reproducible example (as you were requested to submit): V <- data.frame(v1=c(1,0,0), v2=c("Shape", "Length", "Rate"), stringsAsFactors=FALSE) Finaldata <- data.frame(Shape = runif(5), Length = runif(5), Rate = runif(5))

[R] Subsetting a dataframe by dynamic column name

2014-03-27 Thread Sneha Bishnoi
Hi all! I am trying to drop columns from a data frame dynamically depending on user input. The dataframe whose columns need to be dropped is called "Finaldata" So here is what I do: V is a dataframe with columns v1 and v2 as follows v1 v2 1 1 Shape 2 0 Length 3 0

Re: [R] Subsetting a dataframe

2010-10-24 Thread ANJAN PURKAYASTHA
Thanks all for your help. Anjan On Sun, Oct 24, 2010 at 1:38 PM, Jorge Ivan Velez wrote: > Hi Anjan, > > Please consider the following example: > > > x <- c(2, rep(1, 10)) > > all(x == 1) > [1] FALSE > > d <- replicate(10, sample(x, replace = TRUE)) > > d > [,1] [,2] [,3] [,4] [,5] [,6] [,

Re: [R] Subsetting a dataframe

2010-10-24 Thread Jorge Ivan Velez
Hi Anjan, Please consider the following example: > x <- c(2, rep(1, 10)) > all(x == 1) [1] FALSE > d <- replicate(10, sample(x, replace = TRUE)) > d [,1] [,2] [,3] [,4] [,5] [,6] [,7] [,8] [,9] [,10] [1,]111111211 1 [2,]11121

[R] Subsetting a dataframe

2010-10-24 Thread ANJAN PURKAYASTHA
Hi, I have a dataframe with 43 columns and a 1000 rows. Each entry in the dataframe can be either P or A. here is a small chunk: c1c2 ...c43 r100 P A ... P r101 A A ... A r102 P P ... P How does one subset this data frame to select those rows t

Re: [R] subsetting a dataframe

2010-06-04 Thread William Dunlap
> -Original Message- > From: r-help-boun...@r-project.org > [mailto:r-help-boun...@r-project.org] On Behalf Of yjmha69 > Sent: Friday, June 04, 2010 12:28 PM > To: R-help@r-project.org > Subject: [R] subsetting a dataframe > > Hi there, > > a<-data.fram

[R] subsetting a dataframe

2010-06-04 Thread yjmha69
Hi there, > a<-data.frame(c(1,2,2,5,9,9),c("A","B","C","D","E","F")) > names(a)<-c("x1","x2") > max(table(a$x1)) [1] 2 > The above shows the max count for x1 is 2, which is correct. But we can't tell there are 2 groups that meet this criteria: 2,2 and 9,9. I then want to extract the records

Re: [R] subsetting a dataframe with a string logical expression

2009-07-08 Thread Henrique Dallazuanna
Try this: subset(x, eval(parse(text=filter))) On Wed, Jul 8, 2009 at 4:46 PM, Tracey Frescino wrote: > Hi, > > I am trying to subset a dataset based on a filter defined by a user... > I prompt the user for input.. resulting in a string logical expression > ("X1 < 3"). > > I have tried using su

[R] subsetting a dataframe with a string logical expression

2009-07-08 Thread Tracey Frescino
Hi, I am trying to subset a dataset based on a filter defined by a user... I prompt the user for input.. resulting in a string logical expression ("X1 < 3"). I have tried using subset, but it is looking for a logical expression, not a character string. I keep getting the error: 'subset' must

Re: [R] subsetting a dataframe

2008-03-04 Thread Chuck Cleland
On 3/4/2008 8:41 AM, John Sorkin wrote: > windows XP > R 2.6.0 > > I am having problems deleting a row from a data frame. I create my dataframe > by subsetting a larger dataframe: > > ShortLavin<-Lavin[Lavin[,"Site"]=="PP" | Lavin[,"Site"]=="CC" | > Lavin[,"Site"]=="FH",] I would do that in

Re: [R] subsetting a dataframe

2008-03-04 Thread Dimitris Rizopoulos
/(0)16/337015 Web: http://med.kuleuven.be/biostat/ http://www.student.kuleuven.be/~m0390867/dimitris.htm - Original Message - From: "John Sorkin" <[EMAIL PROTECTED]> To: Sent: Tuesday, March 04, 2008 2:41 PM Subject: [R] subsetting a dataframe > windows XP &g

Re: [R] subsetting a dataframe

2008-03-04 Thread Prof Brian Ripley
On Tue, 4 Mar 2008, John Sorkin wrote: > windows XP > R 2.6.0 > > I am having problems deleting a row from a data frame. I create my dataframe > by subsetting a larger dataframe: > > ShortLavin<-Lavin[Lavin[,"Site"]=="PP" | Lavin[,"Site"]=="CC" | > Lavin[,"Site"]=="FH",] > > I then perform a glm

[R] subsetting a dataframe

2008-03-04 Thread John Sorkin
windows XP R 2.6.0 I am having problems deleting a row from a data frame. I create my dataframe by subsetting a larger dataframe: ShortLavin<-Lavin[Lavin[,"Site"]=="PP" | Lavin[,"Site"]=="CC" | Lavin[,"Site"]=="FH",] I then perform a glm using the data frame and plot the results. fit1poisson