regex - Replacing values in a data frame that don't begin with specfic character -


a<-c(1,2,3,4,5,6) b<-c("l124","l234","not","r23","nimt","lreg") df<-data.frame(a,b) 

i create third column of values column b begin l. other values not begin l listed "not l"

the final result like:

     b   c 1 1 l124   l124 2 2 l234   l234 3 3  not   not l 4 4  r23   not l 5 5 nimt   not l 6 6 lreg   lreg 

using ifelse , grepl example:

ifelse(grepl('^l',b),b,"not l") [1] "l124"  "l234"  "not l" "not l" "not l" "lreg"  

Comments

Popular posts from this blog

basic authentication with http post params android -

vb.net - Virtual Keyboard commands -

How to get multiresult with multicondition in Sql Server -