Skip to content
Prev 138441 / 398506 Next

Best way to strsplit a column

try the following:

strg <- c("123:abc", "qwe:789f", "abcde", "a:fd", "567")
sapply(strsplit(strg, ":"), function(x){
    if (length(x) == 1) x <- c(x, NA)
    x
})


I hope it helps.

Best,
Dimitris

----
Dimitris Rizopoulos
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://med.kuleuven.be/biostat/
     http://www.student.kuleuven.be/~m0390867/dimitris.htm


----- Original Message ----- 
From: "Daniel Brewer" <daniel.brewer at icr.ac.uk>
To: <r-help at stat.math.ethz.ch>
Sent: Tuesday, March 04, 2008 2:54 PM
Subject: [R] Best way to strsplit a column