[R] subsetting

2008-01-04 Thread Matthias Wendel
I'm using R Version 2.6.1 under Windows XP. > search() [1] ".GlobalEnv""s" "s" "package:cairoDevice" [5] "package:datasets" "package:foreign" "package:graphics" "package:grDevices" [9] "package:gWidgetsrJava" "package:

[R] subsetting

2007-10-25 Thread henrik . parn
Dear all, I have received some data on birds that looks sth like this: # a unique id for each individual id <- c(1,1,1,2,2,2,3,3,3,4,4,5,6) # the year the bird was measured year <- c(1995, 1996, 1997, 1995, 1996, 1997, 1996, 1997, 1998, 1996, 1997, 1997, 1998) # the year the bird was hatched y

Re: [R] subsetting

2008-01-04 Thread Bert Gunter
PROTECTED] [mailto:[EMAIL PROTECTED] On Behalf Of Matthias Wendel Sent: Friday, January 04, 2008 10:37 AM To: r-help@r-project.org Subject: [R] subsetting I'm using R Version 2.6.1 under Windows XP. > search() [1] ".GlobalEnv""s" &qu

Re: [R] subsetting

2008-01-04 Thread Gabor Grothendieck
Here are three ways: 1. Define inner inside outer: outer <- function() { s <- 1; inner <- function() s; inner() } outer() # 1 2. Use parent.frame: inner <- function() parent.frame()$s outer <- function() { s <- 1; inner() } outer() # 1 3. Pass s explicitly: inner <- function(s) s outer <- fu

Re: [R] subsetting

2007-10-25 Thread John Kane
I don't understand the criteria that gives you just the three ids. As I read the criteria if we put the data into a data.frame you have subset(mydata ,year==year.hatch & year.1st.reprod == year.hatch+1) but this gives more than the three ids. What am I missing? --- [EMAIL PROTECTED] wrote:

[R] subsetting of factor

2008-09-11 Thread Hui-Yi Chu
Dear R list, I think my question maybe easy for you but I really spent entire day to resolve it. Say I have a matrix, rows are 6000 genes, columns(1-6) are 3 genotypes (a,b,c) with 2 repeat. I have to use two groups each time for t-test, a vs. c or b vs. c, but I dont know how to write correct cod

[R] Subsetting Method [ Revisited

2008-01-09 Thread Gregory Wall
Hello Everyone: As usual, thanks in advance for any help. I was hoping to get some more advice on this question: I'm trying to write a subsetting routine for an S3 object I've created -- lets call it myObject. myObject has a few attributes basically of type string and numerics. Its atomic va

[R] Subsetting array (NA:s)

2008-01-10 Thread Lauri Nikkinen
Hi R-users, I have an array similar to this: tmp <- array(1:6, c(2,3,3)) n1 <- c("one", "two") n2 <- c("three", "four", "five") n3 <- c("six", "seven", "eight") dimnames(tmp) <- list(n1, n2, n3) tmp[1,,1] <- NA tmp[1,3,2] <- NA tmp[2,,3] <- NA tmp How to subset !is.na(x) rows resulting , , six

[R] Subsetting within xyplot()

2008-02-26 Thread David Afshartous
All, I'm having problems w/ a simple attempt to subset an xyplot. The first plot below is a plot of y versus x for certain values of a third categorical variable z. Now I'd like to further restrict this to certain values of variable y. Neither of the two attempts below work. Any suggestions m

[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

[R] subsetting a data.frame

2007-10-10 Thread João Fadista
Dear all, I would like to be able to subset a data.frame in a special way. I will put here an example: Score Name 88 19_0070 88 19_0070 87 19_0070 79 002127_0658 79 002127_0658 77 002127_0658 So, for the abo

[R] Subsetting expand.grid() result

2009-08-20 Thread jack.kel...@bigpond.com
Hi, I have only 2 months' experience with R. Here is one sort of problem that arose: * Site 1 has transects A,B,C,D. * Site 2 has transects A,B,C,D,E,F. * Site 3 has transect A. * ... and Site 1000 has transects A,B,C. At each transect, measure ALL of the various categories belonging to propertie

[R] Subsetting data by date

2008-07-21 Thread Williams, Robin
Hi all, Firstly I appologise if this question has been answered previously, however searching of the archives and the internet generally has not yielded any results. I am looking in to the effects of summer weather conditions (temperature, humidity etc), on the incidences of a breathing dis

[R] subsetting the gene list

2008-09-02 Thread Abhilash Venu
Hi all, I am working on a single color expression data using limma. I would like to perform a cluster analysis after selecting the differentially genes based on the P value (say 0.001). As far as my knowledge is concerned I have to do the sub setting of these selected genes on the normalized data

[R] subsetting a data frame

2008-09-03 Thread joseph
I have a data frame that looks like this: V1 V2 V3 ab0:1:12 df1:2:1 cd1:0:9 where V3 is in the form x:y:z Can someone show me how to subset the rows where the values of x, y and z <= 10: V1 V2 V3 df1:2:1 cd1:0:9 Thanks Joseph [[alternative

Re: [R] subsetting of factor

2008-09-12 Thread Adaikalavan Ramasamy
help(rowttests) says that fac needs to be a factor. So how about ? m <- matrix( rnorm(30), nc=6 ) genotype <- c("a", "a", "b", "b", "c", "c") w1 <- which( genotype %in% c("a", "b") ) w2 <- which( genotype %in% c("a", "c") ) w3 <- which( genotype %in% c("b", "c") ) list( ab = rowttes

Re: [R] subsetting of factor

2008-09-12 Thread Hui-Yi Chu
Hi Adai, It works!! Thanks a lot!! Hui-Yi On Fri, Sep 12, 2008 at 11:26 AM, Adaikalavan Ramasamy < [EMAIL PROTECTED]> wrote: > help(rowttests) says that fac needs to be a factor. So how about ? > > m <- matrix( rnorm(30), nc=6 ) > genotype <- c("a", "a", "b", "b", "c", "c") > > w1 <- which(

[R] Subsetting data frame problem....

2008-01-01 Thread Marko Milicic
Dear R users, I'm new but already fascinated R user so please forgive for my ignorance. I have the problem, I read most of help pages but couldn't find the solution. The problem follows I have large data set 10,000 rows and more than 100 columns... Say something like var1,var2,var2,var4.

Re: [R] Subsetting Method [ Revisited

2008-01-09 Thread Steven McKinney
Message- From: [EMAIL PROTECTED] on behalf of Gregory Wall Sent: Wed 1/9/2008 3:59 PM To: r-help@r-project.org Subject: [R] Subsetting Method [ Revisited Hello Everyone: As usual, thanks in advance for any help. I was hoping to get some more advice on this question: I'm trying to w

Re: [R] Subsetting array (NA:s)

2008-01-10 Thread Marc Schwartz
Lauri Nikkinen wrote: > Hi R-users, > > I have an array similar to this: > > tmp <- array(1:6, c(2,3,3)) > n1 <- c("one", "two") > n2 <- c("three", "four", "five") > n3 <- c("six", "seven", "eight") > dimnames(tmp) <- list(n1, n2, n3) > tmp[1,,1] <- NA > tmp[1,3,2] <- NA > tmp[2,,3] <- NA > tmp >

[R] Subsetting without partial matches

2009-01-30 Thread Jonathan Dushoff
I have a list of observations of individuals. I would like to make a list of individuals, with a data frame of observations for each individual. The following code usually works, but not always -- # Make a list of empty data

[R] Subsetting without partial matches

2009-01-31 Thread Jonathan Dushoff
David: Thank you for your very valuable response. In fact, I was trying to _avoid_ partial matching, not accomplish it. Subset is a _much_ better way of doing what I was trying to do. Humorously, however, your code also reproduces the mistake that brought me here, AFAICT. I think my code

[R] Subsetting to unique values

2008-06-06 Thread Emslie, Paul [Ctr]
I want to take the first row of each unique ID value from a data frame. For instance > ddTable <- data.frame(Id=c(1,1,2,2),name=c("Paul","Joe","Bob","Larry")) I want a dataset that is Id Name 1 Paul 2 Bob > unique(ddTable) Will give me all 4 rows, and > unique(ddTable$Id) Will

Re: [R] Subsetting within xyplot()

2008-02-26 Thread Henrique Dallazuanna
Try this: xyplot(y ~ x , data = junk.frm, type = c("g", "p","smooth"), pch=20, subset=z=="D" & y < 2) On 26/02/2008, David Afshartous <[EMAIL PROTECTED]> wrote: > > All, > > I'm having problems w/ a simple attempt to subset an xyplot. > > The first plot below is a plot of y versus x for certa

Re: [R] Subsetting within xyplot()

2008-02-26 Thread Erik Iverson
See the description of the subset argument in ?xyplot subset: logical or integer indexing vector (can be specified in terms of variables in 'data'). Only these rows of 'data' will be used for the plot. If 'subscripts' is 'TRUE', the subscripts will provide ind

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

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

[R] subsetting large data frames.

2008-12-07 Thread hesicaia
Hi all, I have a question regarding subsetting of large data frames. I have two data frames “catches” and “tows” and they both have the same 30 variables (columns). I would like to select rows in the data frame “tows” where all 5 specific variables are NOT matched in “catches. That is to say, th

Re: [R] subsetting a data.frame

2007-10-10 Thread jim holtman
Is this what you want? > x <- read.table(textConnection("Score Name + 88 19_0070 + 88 19_0070 + 87 19_0070 + 79 002127_0658 + 79 002127_0658 + 77 002127_0658"), header=TRUE) > # return best scores > best <- by(x, x$Name, f

Re: [R] subsetting a data.frame

2007-10-10 Thread Peter Dalgaard
jim holtman wrote: > Is this what you want? > > >> x <- read.table(textConnection("Score Name >> > + 88 19_0070 > + 88 19_0070 > + 87 19_0070 > + 79 002127_0658 > + 79 002127_0658 > + 77 002127_0658"), header=TRUE)

[R] subsetting of a data.frame

2009-05-21 Thread culpritNr1
Hello everybody How do you subset a data.frame when your boundaries are a combination of explicit and implicit limits? For example, I need to subset from the fourth (explicit) to the last (implicit) column a data.frame named A. In other languages you would do A[ , 4:]. Would anybody show me the

Re: [R] Subsetting data by date

2008-07-21 Thread Gabor Grothendieck
Try this: Lines <- "Date,Temp 1-Apr-1997,50 3-Sept-2001,60" library(zoo) # function to reduce 4 char mos to 3 char convert.date <- function(x, format) as.Date(sub("(-...).-", "\\1-", x), format) # z <- read.zoo("myfile.csv", header = TRUE, sep = ",", FUN = convert.date, format = "%d-%b-%Y") z <

Re: [R] Subsetting data by date

2008-07-21 Thread Gabor Grothendieck
Continuing on, to just get points from May to Sep mo <- as.numeric(format(time(z), "%m")) z.summer <- z[mo >= 5 & mo <= 9] If in your case z is multivariate rather than univariate (as it is in our example) then it would be: z.summer <- z[mo >= 5 & mo <= 9, ] On Mon, Jul 21, 2008 at 9:55 AM, Gabo

Re: [R] Subsetting data by date

2008-07-21 Thread Williams, Robin
Forecasting [EMAIL PROTECTED] -Original Message- From: Gabor Grothendieck [mailto:[EMAIL PROTECTED] Sent: Monday, July 21, 2008 3:26 PM To: Williams, Robin Cc: R-help@r-project.org Subject: Re: [R] Subsetting data by date Continuing on, to just get points from May to Sep mo <- as.nume

Re: [R] Subsetting data by date

2008-07-21 Thread Williams, Robin
] -Original Message- From: Gabor Grothendieck [mailto:[EMAIL PROTECTED] Sent: Monday, July 21, 2008 3:26 PM To: Williams, Robin Cc: R-help@r-project.org Subject: Re: [R] Subsetting data by date Continuing on, to just get points from May to Sep mo <- as.numeric(format(time(z),

Re: [R] Subsetting data by date

2008-07-21 Thread John Kane
PM > To: Williams, Robin > Cc: R-help@r-project.org > Subject: Re: [R] Subsetting data by date > > Continuing on, to just get points from May to Sep > > mo <- as.numeric(format(time(z), "%m")) > z.summer <- z[mo >= 5 & mo <= 9] > > If in your case

Re: [R] Subsetting data by date

2008-07-21 Thread John Kane
?subset is one of several ways. You don't need a loop. Loops are BAD in R :) --- On Mon, 7/21/08, Williams, Robin <[EMAIL PROTECTED]> wrote: > From: Williams, Robin <[EMAIL PROTECTED]> > Subject: Re: [R] Subsetting data by date > To: "Gabor Grothendieck"

Re: [R] Subsetting data by date

2008-07-21 Thread Gabor Grothendieck
26 PM > To: Williams, Robin > Cc: R-help@r-project.org > Subject: Re: [R] Subsetting data by date > > Continuing on, to just get points from May to Sep > > mo <- as.numeric(format(time(z), "%m")) > z.summer <- z[mo >= 5 & mo <= 9] > > If in your case

Re: [R] subsetting the gene list

2008-09-02 Thread Adaikalavan Ramasamy
Have you tried reading some of the material from the BioConductor workshop http://bioconductor.org/workshops/ ? Here is a simplistic way of proceeding: ## Calculate pvalues from t-test p <- apply( mat, function(x) t.test( x ~ cl )$p.value ) ## Subset mat.sub <- mat[ p, ] ## Cluster heat

Re: [R] subsetting a data frame

2008-09-03 Thread Marc Schwartz
on 09/03/2008 05:06 PM joseph wrote: > I have a data frame that looks like this: > V1 V2 V3 > ab0:1:12 > df1:2:1 > cd1:0:9 > where V3 is in the form x:y:z > Can someone show me how to subset the rows where the values of x, y and z <= > 10: > V1 V2 V3 > df1:2:1 > c

Re: [R] subsetting a data frame

2008-09-06 Thread joseph
Hello How can I change the function to get the rows with the sum (x+y+z) = 10? Thank you very much Joseph - Original Message From: Marc Schwartz <[EMAIL PROTECTED]> To: joseph <[EMAIL PROTECTED]> Cc: r-help@r-project.org Sent: Wednesday, September 3, 2008 3:24:58 PM Sub

Re: [R] subsetting a data frame

2008-09-06 Thread joseph
nt: Saturday, September 6, 2008 10:43:09 AM Subject: Re: [R] subsetting a data frame Dear Joseph, Try DF[sapply(strsplit(as.character(DF$V3), ":"), function(i) all(as.numeric(i) == 10)), ] HTH, Jorge On Sat, Sep 6, 2008 at 1:24 PM, joseph <[EMAIL PROTECTED]> wrote:

Re: [R] subsetting a data frame

2008-09-06 Thread stephen sefick
h <[EMAIL PROTECTED]> > Sent: Saturday, September 6, 2008 10:43:09 AM > Subject: Re: [R] subsetting a data frame > > > > Dear Joseph, > > Try > > > DF[sapply(strsplit(as.character(DF$V3), ":"), > function(i) all(as.numeric(i) == 10))

Re: [R] subsetting a data frame

2008-09-06 Thread stephen sefick
ssage >> From: Jorge Ivan Velez <[EMAIL PROTECTED]> >> To: joseph <[EMAIL PROTECTED]> >> Sent: Saturday, September 6, 2008 10:43:09 AM >> Subject: Re: [R] subsetting a data frame >> >> >> Dear Joseph, >> Try >> >> DF

Re: [R] subsetting a data frame

2008-09-06 Thread Jorge Ivan Velez
oseph > > - Original Message > From: Jorge Ivan Velez <[EMAIL PROTECTED]> > To: joseph <[EMAIL PROTECTED]> > Sent: Saturday, September 6, 2008 10:43:09 AM > Subject: Re: [R] subsetting a data frame > > > Dear Joseph, > Try > > > DF[sapply(st

Re: [R] Subsetting data frame problem....

2008-01-01 Thread jim holtman
?complete.cases On Jan 1, 2008 8:50 PM, Marko Milicic <[EMAIL PROTECTED]> wrote: > Dear R users, > > I'm new but already fascinated R user so please forgive for my > ignorance. I have the problem, I read most of help pages but couldn't > find the solution. The problem follows > > I have large

Re: [R] Subsetting data frame problem....

2008-01-01 Thread Ross Darnell
You could try > complete.case.df <- na.omit(df) Ross Darnell -Original Message- From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] On Behalf Of Marko Milicic Sent: Wednesday, 2 January 2008 11:50 AM To: r-help@r-project.org Subject: [R] Subsetting data frame problem Dear R

Re: [R] Subsetting data frame problem....

2008-01-01 Thread Simon Blomberg
PROTECTED] [mailto:[EMAIL PROTECTED] > On Behalf Of Marko Milicic > Sent: Wednesday, 2 January 2008 11:50 AM > To: r-help@r-project.org > Subject: [R] Subsetting data frame problem > > Dear R users, > > I'm new but already fascinated R user so please forgiv

Re: [R] Subsetting without partial matches

2009-01-30 Thread David Winsemius
I have not seen you describe the value of doing partial matching in this application, so pardon this perhaps non-responsive reply: Wouldn't it have been much, much simpler to have used the subset function (which returns a dataframe object) at the first assignment to donotprint? Something

Re: [R] Subsetting to unique values

2008-06-06 Thread Chuck Cleland
On 6/6/2008 9:35 AM, Emslie, Paul [Ctr] wrote: I want to take the first row of each unique ID value from a data frame. For instance ddTable <- data.frame(Id=c(1,1,2,2),name=c("Paul","Joe","Bob","Larry")) I want a dataset that is Id Name 1 Paul 2 Bob unique(ddTable) Will give m

Re: [R] Subsetting to unique values

2008-06-06 Thread John Kane
I don't have R on this machine but will this work. myrows <- unique(ddTable[,1]) unis <- ddTable(myrows, ] --- On Fri, 6/6/08, Emslie, Paul [Ctr] <[EMAIL PROTECTED]> wrote: > From: Emslie, Paul [Ctr] <[EMAIL PROTECTED]> > Subject: [R] Subsetting to unique valu

Re: [R] Subsetting to unique values

2008-06-06 Thread Adrian Dusa
Emslie, Paul [Ctr] atac.mil> writes: > > I want to take the first row of each unique ID value from a data frame. > For instance > > ddTable <- > data.frame(Id=c(1,1,2,2),name=c("Paul","Joe","Bob","Larry")) > > I want a dataset that is > IdName > 1 Paul > 2 Bob > > > unique(ddTable

Re: [R] Subsetting to unique values

2008-06-06 Thread jim holtman
The interesting thing about R is that there are several ways to "skin the cat"; here is yet another solution: > do.call(rbind, by(ddTable, ddTable$Id, function(z) z[1,,drop=FALSE])) Id name 1 1 Paul 2 2 Bob > On Fri, Jun 6, 2008 at 9:35 AM, Emslie, Paul [Ctr] <[EMAIL PROTECTED]> wrote: > I

Re: [R] Subsetting to unique values

2008-06-06 Thread Jorge Ivan Velez
Dear Paul, Try also: ddTable <- data.frame(Id=c(1,1,2,2),name=c("Paul","Joe","Bob","Larry")) ddTable[unique(ddTable$Id),] HTH, Jorge On Fri, Jun 6, 2008 at 9:35 AM, Emslie, Paul [Ctr] <[EMAIL PROTECTED]> wrote: > I want to take the first row of each unique ID value from a data frame. > For

[R] Subsetting data in a loop

2008-10-29 Thread t c
I need some help with sub-setting my data.  I am trying to divide a data frame into multiple data frames based on the year collected, and stored in a list with each new data frame labeled with "year X" where X is the year the data was collected.  When I run my current code I get nine error messa

Re: [R] subsetting large data frames.

2008-12-07 Thread Marc Schwartz
on 12/07/2008 11:16 AM hesicaia wrote: > Hi all, > I have a question regarding subsetting of large data frames. I have two > data frames “catches” and “tows” and they both have the same 30 variables > (columns). I would like to select rows in the data frame “tows” where all 5 > specific variables

Re: [R] subsetting large data frames.

2008-12-07 Thread hesicaia
It worked wonderfully - Thanks very much! hesicaia wrote: > > Hi all, > I have a question regarding subsetting of large data frames. I have two > data frames “catches” and “tows” and they both have the same 30 variables > (columns). I would like to select rows in the data frame “tows” where

Re: [R] subsetting of a data.frame

2009-05-21 Thread Sarah Goslee
You can for example use ncol(A) to get the number of columns. Sarah On Thu, May 21, 2009 at 12:06 PM, culpritNr1 wrote: > > Hello everybody > > How do you subset a data.frame when your boundaries are a combination of > explicit and implicit limits? > > For example, I need to subset from the four

Re: [R] subsetting of a data.frame

2009-05-21 Thread Jorge Ivan Velez
Dear culprit Try this: A[ , 4:ncol(A) ] HTH, Jorge On Thu, May 21, 2009 at 12:06 PM, culpritNr1 wrote: > > Hello everybody > > How do you subset a data.frame when your boundaries are a combination of > explicit and implicit limits? > > For example, I need to subset from the fourth (explicit

Re: [R] subsetting of a data.frame

2009-05-21 Thread culpritNr1
Hi Sarah and Jorge, ncol(). How elegant! Thank you. Jorge Ivan Velez wrote: > > Dear culprit > Try this: > A[ , 4:ncol(A) ] > > HTH, > > Jorge > > > > On Thu, May 21, 2009 at 12:06 PM, culpritNr1 > wrote: > >> >> Hello everybody >> >> How do you subset a data.frame when your bounda

[R] subsetting with column name as string

2008-08-06 Thread Faheem Mitha
Hi, Consider the following x = c(1,2) y = c(3,4) d = data.frame(cbind(x,y)) d$x [1] 1 2 d$"x" [1] 1 2 foo = function(val) + { + return(d$val) + } bar = function() + { + return(d$"x") + } foo("x") NULL bar() [1] 1 2 I'm a little surprised that R accepts both the form d$x and

Re: [R] Subsetting data in a loop

2008-10-29 Thread hadley wickham
?split. Hadley On Wed, Oct 29, 2008 at 3:22 PM, t c <[EMAIL PROTECTED]> wrote: > I need some help with sub-setting my data. I am trying to divide a data > frame into multiple data frames based on the year collected, and stored in a > list with each new data frame labeled with "year X" where X

[R] subsetting a matrix based on condition

2009-02-24 Thread A Ezhil
Dear All, I have matrix of size 2500 x 12. I would like to select all the rows if 6 out 12 values are > 0. How can I do that in R? Thanks in advance. Kind regards, Ezhil __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-he

[R] Subsetting matrix with values from vector

2009-09-15 Thread jorgusch
Hello, I have a large matrix (data), in which there is a column offerid. The values are numbers (lets say 1:5) There is another vector (idnew), which contains some of the offerids and many more (3:10). I want a subset of the matrix wiith only those rows, which match the criteria of the vector.

[R] Subsetting dataframes based on column names

2009-09-22 Thread Corey Sparks
Dear R users, I am interested in taking the columns from multiple dataframes, the problem is that the different dataframes have different combinations of the same variable names, here's a simple example: a<-rep(1:10) b<-rep(1:10) c<-rep(21:30) d<-rep(31:40) dat.a<-data.frame(a,b,c,d) names(d

[R] subsetting from a vector or matrix

2009-09-24 Thread Jim Bouldin
I realize this should be simple but I'm having trouble subsetting vectors and matrices, for example extracting all values meeting a certain criterion, from a vector. Cannot seem to figure out the correct syntax and help page not very helpful. Or should I be using some other function than subset.

Re: [R] subsetting with column name as string

2008-08-06 Thread milton ruser
Try this foo1 = function(val) { return(d[val]) } foo1("x") Good luck miltinho astronauta brazil On 8/6/08, Faheem Mitha <[EMAIL PROTECTED]> wrote: > > > Hi, > > Consider the following > > x = c(1,2) >> y = c(3,4) >> d = data.frame(cbind(x,y)) >> d$x >> > [1] 1 2 > >> d$"x" >> > [1] 1

Re: [R] subsetting with column name as string

2008-08-06 Thread Faheem Mitha
On Wed, 6 Aug 2008, milton ruser wrote: Try this foo1 = function(val) { return(d[val]) } foo1("x") Thanks for the suggestion. I appreciate it. My original question wasn't just a pragmatic "how do I do this" type question. I was also wondering about the language issues involved.

Re: [R] subsetting with column name as string

2008-08-06 Thread Prof Brian Ripley
On Wed, 6 Aug 2008, Faheem Mitha wrote: Hi, Consider the following x = c(1,2) y = c(3,4) d = data.frame(cbind(x,y)) d$x [1] 1 2 d$"x" [1] 1 2 foo = function(val) + { + return(d$val) + } bar = function() + { + return(d$"x") + } foo("x") NULL bar() [1] 1 2 I'm a little surpr

Re: [R] subsetting with column name as string

2008-08-06 Thread Dan Davison
On Wed, Aug 06, 2008 at 11:53:25AM -0400, Faheem Mitha wrote: > > Hi, > > Consider the following > >> x = c(1,2) >> y = c(3,4) >> d = data.frame(cbind(x,y)) >> d$x > [1] 1 2 >> d$"x" > [1] 1 2 >> >> foo = function(val) > + { > + return(d$val) > + } >> >> bar = function() > + { > + return(d$"x")

[R] subsetting dataframe by rownames to be excluded

2008-10-11 Thread Alexy Khrabrov
Is there a way to select a subset of a dataframe consisting of all those rows with rownames *except* from a subset of rownames to be excluded? Example: > a <- data.frame(x=1:10,y=10:1) > a <- a[order(a$y),] # to make rownames differ visually > a[8,] x y 3 3 8 > a["8",] x y 8 8 3 > a[-

[R] subsetting a data frame using string matching

2008-01-21 Thread Karin Lagesen
Example data frame: a = c("Alpha", "Beta", "Gamma", "Beeta", "Alpha", "beta") b = c(1:6) example = data.frame("Title" = a, "Vals" = b) > example Title Vals 1 Alpha1 2 Beta2 3 Gamma3 4 Beeta4 5 Alpha5 6 beta6 > I would like to be able to get a new data frame from

[R] subsetting data-frame by vector of characters

2008-06-13 Thread james perkins
Hi, I have a very simple problem but I can't think how to solve it without using a for loop and creating a large logical vector. However given the nature of the problem I am sure there is a "1-liner" that could do the same thing much more efficiently. bascially I have a dataframe with charac

[R] Subsetting a data.frame degenerates at one column?

2008-02-08 Thread Allen S. Rout
Greetings. At the moment, I'm applying R to some AIX 'nmon' output, trying to get a handle on some disk performance metrics. In case anyone's interested: http://docs.osg.ufl.edu/tsm/pdf/ some of them are more edifying than others. (ahem) I'm trying to develop a somewhat general framework for

Re: [R] subsetting a matrix based on condition

2009-02-24 Thread Dimitris Rizopoulos
one way is: mat <- matrix(rnorm(2500*12), 2500, 12) ind <- rowSums(mat > 0) > 6 mat[ind, ] I hope it helps. Best, Dimitris A Ezhil wrote: Dear All, I have matrix of size 2500 x 12. I would like to select all the rows if 6 out 12 values are > 0. How can I do that in R? Thanks in advance

Re: [R] Subsetting matrix with values from vector

2009-09-15 Thread Dimitris Rizopoulos
have a look at ?"%in%" Best, Dimitris jorgusch wrote: Hello, I have a large matrix (data), in which there is a column offerid. The values are numbers (lets say 1:5) There is another vector (idnew), which contains some of the offerids and many more (3:10). I want a subset of the matrix wiith

Re: [R] Subsetting matrix with values from vector

2009-09-15 Thread Jorge Ivan Velez
Hi jorgusch, First, do not call your data, "data" :-) require(fortunes) fortune('dog') Here are two suggestions to do what you asked for: # your data id <- 1:5 idnew <- 3:10 # to get the indexes id %in% idnew # to get the id's matching the new vector id[ id %in% idnew ] # another way inters

Re: [R] Subsetting dataframes based on column names

2009-09-22 Thread David Winsemius
On Sep 22, 2009, at 5:58 PM, Corey Sparks wrote: Dear R users, I am interested in taking the columns from multiple dataframes, the problem is that the different dataframes have different combinations of the same variable names, here's a simple example: a<-rep(1:10) b<-rep(1:10) c<-rep(21:3

Re: [R] Subsetting dataframes based on column names

2009-09-22 Thread Henrique Dallazuanna
You can use intersect also: dat.a[intersect(names(dat.a), names(dat.b))] On Tue, Sep 22, 2009 at 6:58 PM, Corey Sparks wrote: > Dear R users, > I am interested in taking the columns from multiple dataframes, the problem > is that the different dataframes have different combinations of the same

Re: [R] subsetting from a vector or matrix

2009-09-25 Thread andrew
both the following will probably do the trick. ?subset ?"[" Basically on the second one, you want to come down to something that looks like x[L] where x is a matrix/vector, and L is a logical vector that has the same dimension as x, but is TRUE on the values of x that you want to select. for i

[R] Subsetting an array by a vector of dimensions

2008-07-11 Thread Richard Pearson
Hi Is it possible to subset an n-dimensional array by a vector of n dimensions? E.g. assume I have x <- array(1:24, dim=2:4) x[1,1,2] [1] 7 dims <- c(1,1,2) I would like a function that I can supply x and dims as parameters to, and have it return 7. Also, I would like to do something like

[R] subsetting matrix according to columns with character index

2008-08-13 Thread Ralph S.
Hi, I have a long matrix of the following form which I would like to subset according to the third column: [x y z]: a1 c1 1 a1 c1 2 a2 c1 1 a1 c2 1 a1 c2 2 . . . The first two columns a characters ai and cj. I would like to keep all the rows where there are two entries for z, 1 and 2. Tha

Re: [R] subsetting dataframe by rownames to be excluded

2008-10-11 Thread Prof Brian Ripley
On Sat, 11 Oct 2008, Alexy Khrabrov wrote: Is there a way to select a subset of a dataframe consisting of all those rows with rownames *except* from a subset of rownames to be excluded? Example: Yes: DF[is.na(match(row.names(DF), exclude_me)), ] a <- data.frame(x=1:10,y=10:1) a <- a[order

Re: [R] subsetting a data frame using string matching

2008-01-21 Thread Chuck Cleland
On 1/21/2008 5:18 AM, Karin Lagesen wrote: > Example data frame: > > > a = c("Alpha", "Beta", "Gamma", "Beeta", "Alpha", "beta") > b = c(1:6) > example = data.frame("Title" = a, "Vals" = b) > > >> example > Title Vals > 1 Alpha1 > 2 Beta2 > 3 Gamma3 > 4 Beeta4 > 5 Alpha5

Re: [R] subsetting a data frame using string matching

2008-01-21 Thread Richard . Cotton
> a = c("Alpha", "Beta", "Gamma", "Beeta", "Alpha", "beta") > b = c(1:6) > example = data.frame("Title" = a, "Vals" = b) > > > > example > Title Vals > 1 Alpha1 > 2 Beta2 > 3 Gamma3 > 4 Beeta4 > 5 Alpha5 > 6 beta6 > > > > I would like to be able to get a new data fra

Re: [R] subsetting data-frame by vector of characters

2008-06-13 Thread Chuck Cleland
On 6/13/2008 10:07 AM, james perkins wrote: Hi, I have a very simple problem but I can't think how to solve it without using a for loop and creating a large logical vector. However given the nature of the problem I am sure there is a "1-liner" that could do the same thing much more efficientl

Re: [R] subsetting data-frame by vector of characters

2008-06-13 Thread Wacek Kusnierczyk
james perkins wrote: > Hi, > > I have a very simple problem but I can't think how to solve it without > using a for loop and creating a large logical vector. However given > the nature of the problem I am sure there is a "1-liner" that could do > the same thing much more efficiently. > > bascially

Re: [R] subsetting data-frame by vector of characters

2008-06-13 Thread james perkins
Thanks a lot for that. Its the %in% I needed to work out mainly large didn't mean anything in particular, just that it gets quite long with the real data. I did mean: names = c("John", "Phil", "Robert") The only problem is that using the method you suggest is that I lose the indexing, ie in t

Re: [R] subsetting data-frame by vector of characters

2008-06-13 Thread Peter Dalgaard
james perkins wrote: > Thanks a lot for that. Its the %in% I needed to work out mainly > > large didn't mean anything in particular, just that it gets quite long > with the real data. > I did mean: names = c("John", "Phil", "Robert") > > The only problem is that using the method you suggest is that

Re: [R] subsetting data-frame by vector of characters

2008-06-13 Thread Wacek Kusnierczyk
james perkins wrote: > Thanks a lot for that. Its the %in% I needed to work out mainly > > large didn't mean anything in particular, just that it gets quite long > with the real data. > I did mean: names = c("John", "Phil", "Robert") > > The only problem is that using the method you suggest is that

Re: [R] Subsetting a data.frame degenerates at one column?

2008-02-08 Thread jim holtman
try: input[,targets, drop=FALSE] see: ?"[" for an explanation. On 2/8/08, Allen S. Rout <[EMAIL PROTECTED]> wrote: > > Greetings. > > At the moment, I'm applying R to some AIX 'nmon' output, trying to get > a handle on some disk performance metrics. In case anyone's > interested: > > http://

Re: [R] Subsetting a data.frame degenerates at one column?

2008-02-09 Thread John Kane
I think I understand this. Try str(input) and you will see that input$disk2 in a vector. You can force a data.frame using data.frame(input(,targets)) --- "Allen S. Rout" <[EMAIL PROTECTED]> wrote: > > Greetings. > > At the moment, I'm applying R to some AIX 'nmon' > output, trying to get >

Re: [R] Subsetting a data.frame degenerates at one column?

2008-02-09 Thread Henrique Dallazuanna
Try this also: input[targets] On 08/02/2008, Allen S. Rout <[EMAIL PROTECTED]> wrote: > > Greetings. > > At the moment, I'm applying R to some AIX 'nmon' output, trying to get > a handle on some disk performance metrics. In case anyone's > interested: > > http://docs.osg.ufl.edu/tsm/pdf/ > > som

Re: [R] Subsetting a data.frame degenerates at one column?

2008-02-11 Thread Allen S. Rout
"jim holtman" <[EMAIL PROTECTED]> writes: > try: > input[,targets, drop=FALSE] > see: > ?"[" > for an explanation. Thanks, you who responded; this was exactly helpful, and a good reference to the part of the FM I was missing. To unpack (and demonstrate some comprehension gained.. ;) the sub

Re: [R] subsetting dataframe by rownames to be excluded

2008-10-13 Thread Dieter Menne
Prof Brian Ripley stats.ox.ac.uk> writes: > Yes: DF[is.na(match(row.names(DF), exclude_me)), ] Assuming everything is possible in R: would it be possible to make the below work without breaking existing code? a <- data.frame(x=1:10) rownames(a) = letters[1:10] exclude = c("a","c") a[is.na(matc

Re: [R] subsetting dataframe by rownames to be excluded

2008-10-13 Thread Prof Brian Ripley
On Mon, 13 Oct 2008, Dieter Menne wrote: Prof Brian Ripley stats.ox.ac.uk> writes: Yes: DF[is.na(match(row.names(DF), exclude_me)), ] Assuming everything is possible in R: would it be possible to make the below work without breaking existing code? It would be possible, but not I think des

Re: [R] subsetting dataframe by rownames to be excluded

2008-10-13 Thread David Winsemius
On Oct 13, 2008, at 5:36 AM, Dieter Menne wrote: Prof Brian Ripley stats.ox.ac.uk> writes: Yes: DF[is.na(match(row.names(DF), exclude_me)), ] Assuming everything is possible in R: would it be possible to make the below work without breaking existing code? a <- data.frame(x=1:10) rowna

[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

[R] Subsetting Data Frame based On Specified K Value

2009-09-02 Thread Gundala Viswanath
I have a data that looks like this: http://dpaste.com/88988/plain/ How can I extract/subset the data frame based on selected uniq ID. Let's say I want the first K uniq ID. I want to be able to specify the parameter "K" here, (i.e. given K=3, we hope to extract dat$V2 = 0,1,2). I'm stuck with thi

  1   2   >