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&
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,
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
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
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.
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:
>
?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,
> 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
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
9 matches
Mail list logo