Skip to content
Prev 79865 / 398502 Next

splitting a character field in R

try the following:

A <- c("dgabcrt", "fgrtabc", "sabcuuu")
B <- strsplit(A, "abc")

x1 <- sapply(B, "[", 1); x1[is.na(x1)] <- ""
x2 <- sapply(B, "[", 2); x2[is.na(x2)] <- ""
x1
x2

I hope it helps.

Best,
Dimitris

----
Dimitris Rizopoulos
Ph.D. Student
Biostatistical Centre
School of Public Health
Catholic University of Leuven

Address: Kapucijnenvoer 35, Leuven, Belgium
Tel: +32/(0)16/336899
Fax: +32/(0)16/337015
Web: http://www.med.kuleuven.be/biostat/
     http://www.student.kuleuven.be/~m0390867/dimitris.htm



----- Original Message ----- 
From: <ManuelPerera-Chang at fmc-ag.com>
To: <jholtman at gmail.com>
Cc: <r-help at stat.math.ethz.ch>
Sent: Friday, October 28, 2005 4:38 PM
Subject: Re: [R] splitting a character field in R
Disclaimer: http://www.kuleuven.be/cwis/email_disclaimer.htm