[R] grep
Steven T. Yen
@tyen @end|ng |rom ntu@edu@tw
Mon Jul 11 03:08:45 CEST 2022
Dear, Below, jj contains character strings starting with “z.” and “x.”.
I want to grep all that contain either “z.” or “x.”. I had to grep “z.”
and “x.” separately and then tack the result together. Is there a
convenient grep option that would grep strings with either “z.” or “x.”.
Thank you!
> jj<-names(v$est); jj
[1] "z.one" "z.liberal" "z.conserv" "z.dem" "z.rep" "z.realinc"
[7] "x.one" "x.liberal" "x.conserv" "x.dem" "x.rep" "x.realinc"
[13] "mu1_1" "mu2_1" "rho"
> j1<-grep("z.",jj,value=TRUE); j1
[1] "z.one" "z.liberal" "z.conserv" "z.dem" "z.rep" "z.realinc"
> j2<-grep("x.",jj,value=TRUE); j2
[1] "x.one" "x.liberal" "x.conserv" "x.dem" "x.rep" "x.realinc"
> j<-c(j1,j2); j
[1] "z.one" "z.liberal" "z.conserv" "z.dem" "z.rep" "z.realinc"
[7] "x.one" "x.liberal" "x.conserv" "x.dem" "x.rep" "x.realinc"
More information about the R-help
mailing list