Re: [R] selecting rows based on number that occurs after letter

2010-04-26 Thread Dennis Murphy
Hi: This seems to be easier to pull off if x is a data frame rather than a matrix. x <- data.frame(GCM = c("BA1y1","BA2y3","C3A1r1y1","C3A2r2y2t4","C3r2y1y1"), y = c(1:3, 11, 12), stringsAsFactors = FALSE) x$val <- as.numeric(substring(lapply(strsplit(x$GCM, 'y'), '[

Re: [R] selecting rows based on number that occurs after letter

2010-04-26 Thread Daisy Englert Duursma
Hello, Thanks for your help, I have played around with the suggestion a bit but I can still not sub-setting in the way I need If I have a matrix x as follows: > x <- matrix(c("BA1y1","BA2y3","C3A1r1y1","C3A2r2y2t4","C3r2y1y1",1,2,3, 11,12) , nrow=5, ncol=2, dimnames=list(c("a","b","c","d","e")

Re: [R] selecting rows based on number that occurs after letter

2010-04-18 Thread jim holtman
Use regular expressions: > x <- c( "BA1y1", "C3A2r3y1", "MA3r3y1r3", "MA23r34y123z99") > # extact the number after the 'y' > num <- sub(".*y(\\d +).*", "\\1 ", x) > > num [1] "1" "1" "1" "123" > On Sun, Apr 18, 2010 at 8:41 PM, Daisy Englert Duursma < daisy.duur...@gmail.com> wrote: > Hel