[R] how to separate char and num within a variable

Bill Hyman billhyman1 at yahoo.com
Fri Feb 6 01:46:09 CET 2009


Thx a lot! It works



----- Original Message ----
From: Wacek Kusnierczyk <Waclaw.Marcin.Kusnierczyk at idi.ntnu.no>
To: Bill Hyman <billhyman1 at yahoo.com>
Cc: R help <R-help at stat.math.ethz.ch>
Sent: Thursday, February 5, 2009 3:38:34 PM
Subject: Re: [R] how to separate char and num within a variable

Bill Hyman wrote:
> Hi all,
>
> I read in a column which looks like "chr1:000889594-000889638", and need to break them into three columns like "chr1:", "000889594" and "000889638". How shall I do in R. Thanks a lot for your suggestions!
>
>  

if strings is your vector of strings, this should do (assuming the
format is stable across all entries):

strsplit(strings, split=':|-')

vQ




More information about the R-help mailing list