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

Christian Schulz chschulz at email.de
Tue May 3 08:28:10 CEST 2011


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



More information about the R-help mailing list