Dear R-user, May I seek your help over a issue, probably a simple one. I just one to scan the following numbers, avoiding [1]s, [2]. By the way, I know how to scan numbers in the absence of such [1] and [2]. ------------------------------------------------------ [1] 18 18 17 14 17 13 13 18 13 16 16 14 [1] 12 19 15 21 13 17 10 13 18 14 17 13 [2] 13 15 20 14 18 15 10 12 20 17 17 17 ------------------------------------------------------ Any suggestion would be more than great! Regards, Jamil. [[alternative HTML version deleted]]
On Sun, May 12, 2013 at 4:42 PM, Naser Jamil <jamilnaser79 at gmail.com> wrote:> Dear R-user, > May I seek your help over a issue, probably a simple one. I just one to > scan the following numbers, avoiding [1]s, [2]. By the way, I know how to > scan numbers in the absence of such [1] and [2]. > > > ------------------------------------------------------ > > [1] 18 18 17 14 17 13 13 18 13 16 16 14 > [1] 12 19 15 21 13 17 10 13 18 14 17 13 > [2] 13 15 20 14 18 15 10 12 20 17 17 17 > ------------------------------------------------------Try this: read.table("myfile")[-1] -- Statistics & Software Consulting GKX Group, GKX Associates Inc. tel: 1-877-GKX-GROUP email: ggrothendieck at gmail.com
Hi, You can do: vec1<-scan(text="[1] 18 18 17 14 17 13 13 18 13 16 16 14 [1] 12 19 15 21 13 17 10 13 18 14 17 13 [2] 13 15 20 14 18 15 10 12 20 17 17 17",what="character") as.numeric(vec1[-grep("\\[",vec1)]) # [1] 18 18 17 14 17 13 13 18 13 16 16 14 12 19 15 21 13 17 10 13 18 14 17 13 13 #[26] 15 20 14 18 15 10 12 20 17 17 17 A.K. ----- Original Message ----- From: Naser Jamil <jamilnaser79 at gmail.com> To: R help <r-help at r-project.org> Cc: Sent: Sunday, May 12, 2013 4:42 PM Subject: [R] scan in R Dear R-user, May I seek your help over a issue, probably a simple one. I just one to scan the following numbers, avoiding [1]s, [2]. By the way, I know how to scan numbers in the absence of such [1] and [2]. ------------------------------------------------------ [1] 18 18 17 14 17 13 13 18 13 16 16 14 [1] 12 19 15 21 13 17 10 13 18 14 17 13 [2] 13 15 20 14 18 15 10 12 20 17 17 17 ------------------------------------------------------ Any suggestion would be more than great! Regards, Jamil. ??? [[alternative HTML version deleted]] ______________________________________________ R-help at 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.
On May 12, 2013, at 22:42 , Naser Jamil wrote:> Dear R-user, > May I seek your help over a issue, probably a simple one. I just one to > scan the following numbers, avoiding [1]s, [2]. By the way, I know how to > scan numbers in the absence of such [1] and [2]. > > > ------------------------------------------------------ > > [1] 18 18 17 14 17 13 13 18 13 16 16 14 > [1] 12 19 15 21 13 17 10 13 18 14 17 13 > [2] 13 15 20 14 18 15 10 12 20 17 17 17 > ------------------------------------------------------ > > Any suggestion would be more than great!The most expedient way would seem to be remove the [1],[2], then scan() what remains. Something along the lines of scan(text=substring(readLines(file), 4)) or maybe replace the substring bit with sub("\[.*\]", "", readLines(....))> > > Regards, > Jamil. > > [[alternative HTML version deleted]] > > ______________________________________________ > R-help at 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.-- Peter Dalgaard, Professor, Center for Statistics, Copenhagen Business School Solbjerg Plads 3, 2000 Frederiksberg, Denmark Phone: (+45)38153501 Email: pd.mes at cbs.dk Priv: PDalgd at gmail.com