Hi,
library(stringr)
b[str_detect(colnames(b),"^y")]
# y y.1 y.2
#1 0.0 0.00 0.00
#2 19.55811 17.023812 15.354880
#3 10.74991 9.024250 8.177128
#4 5.91924 4.789331 4.367188
#or
b[,!is.na(match(gsub("\\..*","",names(b)),"y"))]
# y y.1 y.2
that is exactly what I wanted! Thank you Sarah!
Andras
--- On Tue, 5/21/13, Sarah Goslee wrote:
> From: Sarah Goslee
> Subject: Re: [R] help with data.frame
> To: "Andras Farkas"
> Cc: r-help@r-project.org
> Date: Tuesday, May 21, 2013, 2:07 PM
> So if I understan
So if I understand you correctly, and I may not, you want to extract
the columns from a dataframe that start with y?
Using your reproducible example (thanks!):
> b[, grepl("^y", colnames(b))]
y y.1 y.2
1 0.0 0.00 0.00
2 19.55811 17.023812 15.354880
3 10.74991
Dear All
I have the following code for list "a":
a <-list(structure(c(0, 4, 8, 12, 0, 19.5581076131386, 10.7499105081144,
5.91923975728553, 0, 4.08916328337685, 2.26872955281708, 1.24929641535359
), .Dim = c(4L, 3L), .Dimnames = list(NULL, c("time", "y", "b"
)), istate = c(2L, 107L, 250L, NA, 5L
4 matches
Mail list logo