2016-09-28 136 views

回答

2

我們可以使用\\s{2,}相匹配的空間圖案爲2以上時在strsplit

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

這可以轉換爲data.frame使用as.data.frame.list

setNames(as.data.frame.list(v1), paste0("col", 1:4))