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

From: Christian Schulz <chschulz_at_email.de>
Date: Tue, 03 May 2011 08:28:10 +0200

> 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] "abc" "lmno" "qrstuvwxyz"
>
>
> Thanks. That's very close to what I'm looking for, but it seems to
> correspond to "cut -c", not to "cut -f". Can it work with delimiters
> or only with character counts?
>
> Mike
>

x <- "this is a string"
unlist(strsplit(x," "))[c(1,4)]

HTH Christian

> ______________________________________________
> 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.
>



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. Received on Thu 05 May 2011 - 06:25:10 GMT

Archive maintained by Robert King, hosted by the discipline of statistics at the University of Newcastle, Australia.
Archive generated by hypermail 2.2.0, at Thu 05 May 2011 - 07:00:06 GMT.

Mailing list information is available at https://stat.ethz.ch/mailman/listinfo/r-help. Please read the posting guide before posting to the list.

list of date sections of archive