2016-09-28 14 views
0

私の質問は以下の質問によく似ていますが、二重スペースで分割する必要があるという追加の問題があります。データフレーム内の複数文字の区切り文字で分割した列

Split column at delimiter in data frame

私は列に、このベクトルを分割したいと思います。

text <- "first  second and second  third and third and third    fourth" 

結果は、我々は、そのスペースのパターンと一致する\\s{2,}を使用することができる「第4」

答えて

2

、4列「最初の」読み取り、「第二及び」、「第三の第3及び第」でなければなりませんこれはas.data.frame.list

setNames(as.data.frame.list(v1), paste0("col", 1:4)) 
を用い data.frameに変換することができる strsplit

v1 <- strsplit(text, "\\s{2,}")[[1]] 
v1 
#[1] "first"      "second and second"  
#[3] "third and third and third" "fourth"  

2以上であります

関連する問題