人到中年有点甜
新流行tidyr包用separate..它使用正则表达式,因此必须转义|df <- data.frame(ID=11:13, FOO=c('a|b', 'b|c', 'x|y'))separate(data = df, col = FOO, into = c("left", "right"), sep = "\\|") ID left right1 11 a b2 12 b c3 13 x y虽然在这种情况下,缺省值足够聪明,可以工作(它查找要拆分的非字母数字字符)。separate(data = df, col = FOO, into = c("left", "right"))