Dear all, This is the sample of the source data (tab delimited)
http://dpaste.com/82660/plain/ - Gundala Viswanath Jakarta - Indonesia On Mon, Oct 6, 2008 at 9:05 PM, Gustaf Rydevik <[EMAIL PROTECTED]> wrote: > On Mon, Oct 6, 2008 at 1:37 PM, Gundala Viswanath <[EMAIL PROTECTED]> wrote: >> Dear all, >> >> I have no problem with this individual grep command: >> >>> datk <- grep("XM_528056", source$V1) >>> dat2 <- source[datk,] >>> print(dat2) >> V1 V2 V3 V4 V5 V6 V7 >> 35995 XM_528056 panTro2 chr8 + 1775569 1896107 Chimpanzee >> >> >> BUT, when I run them under the loop it gives this error: >> >> >>> hm_acc <- c("XM_528056","AB002296") >>> for (i in 1:length(hm_acc)){ >> + >> + hm_acc_id <- as.character(hm_acc[i]) >> + print(hm_acc_id) >> + >> + hm_allk <- grep(hm_acc_id,source$V1) >> + hm_all <- source[hm_allk,] >> + >> + print(hm_all) >> + } >> >> [1] "XM_528056" >> [1] V1 V2 V3 V4 V5 V6 V7 >> <0 rows> (or 0-length row.names) >> [1] "AB002296" >> [1] V1 V2 V3 V4 V5 V6 V7 >> <0 rows> (or 0-length row.names) >> ..... >> >> What's wrong with my way of using grep? >> Please advice. >> >> >> - Gundala Viswanath >> Jakarta - Indonesia >> > > > Hi, > > Could you give us a small sample of the "source" data, so that your > example is reproducible? > From looking at your code, it seems as if you copied something wrong. > First you write: > grep("XM_528056", source$V1) > > ,but when you print dat2 it seems as if your ID-code ("XM_528056") is > in V2, not V1. > > > regards, > > Gustaf > > > -- > Gustaf Rydevik, M.Sci. > tel: +46(0)703 051 451 > address:Essingetorget 40,112 66 Stockholm, SE > skype:gustaf_rydevik > ______________________________________________ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.