[R] Extract number from string

2011-02-07 Thread Roy Mathew
Dear R Users, if I have a string as follows x<-"jsda23tth" How can I extract out 23 as a numeral? I found substr(x,5,6) but, this doesnt work if the number of alphabets differ. This is another example where the numbers need to be extracted. x<-c("jsda23tth","fgd54fgd","j3ngh","gfdjh564") any id

Re: [R] crazy loop error.

2011-01-25 Thread Roy Mathew
it. All these files have a certain variable k which maybe 2, or 3 or 5 etc. The vector a shows the k values of 8 of such files. I want the contents of all files with k value 5 to be written into one file. Thanks, Roy On Mon, Jan 24, 2011 at 11:43 PM, Erik Iverson wrote: > > > R

Re: [R] crazy loop error.

2011-01-25 Thread Roy Mathew
:43 PM, Erik Iverson wrote: > > > Roy Mathew wrote: > >> Thanks for the reply Erik, As you mentioned, grouping consecutive elements >> of 'a' was my idea. I am unaware of any R'ish way to do it. It would be nice >> if someone in the community knows t

Re: [R] crazy loop error.

2011-01-24 Thread Roy Mathew
Thanks for the reply Erik, As you mentioned, grouping consecutive elements of 'a' was my idea. I am unaware of any R'ish way to do it. It would be nice if someone in the community knows this. The error resulting in the NA was pretty easy to fix, and my loop works, but the results are still wrong (

[R] crazy loop error.

2011-01-24 Thread Roy Mathew
Dear R-users, This is a loop which is part of a bigger script. I managed to isolate the error in this loop and simplified it to the bare minimum and made it self-contained. a<-c(2,3,4,5,5,5,6,6,6,7) for(n in 1:10) { print(paste("n: ",n)) z1<-a[n] #make a list container ldata<-list() t=1 while(z1