Re: [R] UNIX-like cut command in R

2011-05-03 Thread Mike Miller
On Mon, 2 May 2011, P Ehlers wrote: Use str_sub() in the stringr package: require(stringr) # install first if necessary s - abcdefghijklmnopqrstuvwxyz str_sub(s, c(1,12,17), c(3,15,-1)) #[1] abclmno qrstuvwxyz Thanks. That's very close to what I'm looking for, but it seems

Re: [R] UNIX-like cut command in R

2011-05-03 Thread Christian Schulz
On Mon, 2 May 2011, P Ehlers wrote: Use str_sub() in the stringr package: require(stringr) # install first if necessary s - abcdefghijklmnopqrstuvwxyz str_sub(s, c(1,12,17), c(3,15,-1)) #[1] abclmno qrstuvwxyz Thanks. That's very close to what I'm looking for, but it

Re: [R] UNIX-like cut command in R

2011-05-03 Thread Mike Miller
On Tue, 3 May 2011, Christian Schulz wrote: On Mon, 2 May 2011, P Ehlers wrote: Use str_sub() in the stringr package: require(stringr) # install first if necessary s - abcdefghijklmnopqrstuvwxyz str_sub(s, c(1,12,17), c(3,15,-1)) #[1] abclmno qrstuvwxyz Thanks. That's

Re: [R] UNIX-like cut command in R

2011-05-03 Thread Petr Savicky
On Tue, May 03, 2011 at 01:39:49AM -0500, Mike Miller wrote: On Tue, 3 May 2011, Christian Schulz wrote: [...] x - this is a string unlist(strsplit(x, ))[c(1,4)] Thanks. I did figure that one out a couple of messages back, but to get it do behave like cut -d' ' -f1,4, I had to add a

[R] UNIX-like cut command in R

2011-05-02 Thread Mike Miller
The R cut command is entirely different from the UNIX cut command. The latter retains selected fields in a line of text. I can do that kind of manipulation using sub() or gsub(), but it is tedious. I assume there is an R function that will do this, but I don't know its name. Can you tell

Re: [R] UNIX-like cut command in R

2011-05-02 Thread Andrew Robinson
Hi Mike, try substr() Cheers Andrew On Mon, May 02, 2011 at 03:53:58PM -0500, Mike Miller wrote: The R cut command is entirely different from the UNIX cut command. The latter retains selected fields in a line of text. I can do that kind of manipulation using sub() or gsub(), but it is

Re: [R] UNIX-like cut command in R

2011-05-02 Thread Mike Miller
On Tue, 3 May 2011, Andrew Robinson wrote: try substr() OK. Apparently, it allows things like this... substr(abcdef,2,4) [1] bcd ...which is like this: echo abcdef | cut -c2-4 But that doesn't use a delimiter, it only does character-based cutting, and it is very limited. With cut -c

Re: [R] UNIX-like cut command in R

2011-05-02 Thread Gabor Grothendieck
On Mon, May 2, 2011 at 10:32 PM, Mike Miller mbmille...@gmail.com wrote: On Tue, 3 May 2011, Andrew Robinson wrote: try substr() OK.  Apparently, it allows things like this... substr(abcdef,2,4) [1] bcd ...which is like this: echo abcdef | cut -c2-4 But that doesn't use a delimiter,

Re: [R] UNIX-like cut command in R

2011-05-02 Thread Mike Miller
On Mon, 2 May 2011, Gabor Grothendieck wrote: On Mon, May 2, 2011 at 10:32 PM, Mike Miller mbmille...@gmail.com wrote: On Tue, 3 May 2011, Andrew Robinson wrote: try substr() OK.  Apparently, it allows things like this... substr(abcdef,2,4) [1] bcd ...which is like this: echo abcdef

Re: [R] UNIX-like cut command in R

2011-05-02 Thread P Ehlers
Mike Miller wrote: On Mon, 2 May 2011, Gabor Grothendieck wrote: On Mon, May 2, 2011 at 10:32 PM, Mike Miller mbmille...@gmail.com wrote: On Tue, 3 May 2011, Andrew Robinson wrote: try substr() OK. Apparently, it allows things like this... substr(abcdef,2,4) [1] bcd ...which is like