Re: [R] Choosing columns by number

2015-08-25 Thread David Winsemius
TX 77840-4352 > > -Original Message- > From: R-help [mailto:r-help-boun...@r-project.org] On Behalf Of Sam Albers > Sent: Tuesday, August 25, 2015 10:45 AM > To: stephen sefick > Cc: r-help@r-project.org > Subject: Re: [R] Choosing columns by number > > Thierry&

Re: [R] Choosing columns by number

2015-08-25 Thread David L Carlson
15 10:45 AM To: stephen sefick Cc: r-help@r-project.org Subject: Re: [R] Choosing columns by number Thierry's answer of: data.frame( seq_along(iris), colnames(iris) ) is exactly what I was looking for. Apologies for vagueness and HTML. It was unintended. Sam On Tue, Aug 25, 2015 at 8:32 AM,

Re: [R] Choosing columns by number

2015-08-25 Thread Sam Albers
Thierry's answer of: data.frame( seq_along(iris), colnames(iris) ) is exactly what I was looking for. Apologies for vagueness and HTML. It was unintended. Sam On Tue, Aug 25, 2015 at 8:32 AM, stephen sefick wrote: > ?grep > > I think this will do what you want. > > #something like > a <- d

Re: [R] Choosing columns by number

2015-08-25 Thread Thierry Onkelinx
Here are a few ideas. data.frame( seq_along(iris), colnames(iris) ) which(colnames(iris) %in% c("Sepal.Width", "Petal.Width")) grep("\\.Width$", colnames(iris)) ir. Thierry Onkelinx Instituut voor natuur- en bosonderzoek / Research Institute for Nature and Forest team Biometrie & Kwaliteitszo

Re: [R] Choosing columns by number

2015-08-25 Thread K. Elo
Hi! 25.08.2015, 18:17, Sam Albers wrote: Hi all, This is a process question. How do folks efficiently identify column numbers in a dataframe without manually counting them. For example, if I want to choose columns from the iris dataframe I know of two options. I can do this: str(iris)'data.

Re: [R] Choosing columns by number

2015-08-25 Thread David Winsemius
On Aug 25, 2015, at 8:17 AM, Sam Albers wrote: > Hi all, > > This is a process question. How do folks efficiently identify column > numbers in a dataframe without manually counting them. For example, if I > want to choose columns from the iris dataframe I know of two options. I can > do this: >

Re: [R] Choosing columns by number

2015-08-25 Thread stephen sefick
?grep I think this will do what you want. #something like a <- data.frame(a=rnorm(10), b=rnorm(10), c=rnorm(10), d=rnorm(10)) toMatch <- c("a", "d") grep(paste(toMatch,collapse="|"), colnames(a)) #to subset a[,grep(paste(toMatch,collapse="|"), colnames(a))] On Tue, Aug 25, 2015 at 10:17 AM,

Re: [R] Choosing columns by number

2015-08-25 Thread Marc Schwartz
> On Aug 25, 2015, at 10:17 AM, Sam Albers wrote: > > Hi all, > > This is a process question. How do folks efficiently identify column > numbers in a dataframe without manually counting them. For example, if I > want to choose columns from the iris dataframe I know of two options. I can > do th

[R] Choosing columns by number

2015-08-25 Thread Sam Albers
Hi all, This is a process question. How do folks efficiently identify column numbers in a dataframe without manually counting them. For example, if I want to choose columns from the iris dataframe I know of two options. I can do this: > str(iris)'data.frame':150 obs. of 5 variables: $ S