df <- data.frame(category = c("X", "Y"), sequence = c("AAT.G", "CCG-T"), stringsAsFactors = FALSE)
df
category sequence
1 X AAT.G
2 Y CCG-T
sequence
列を 5 つの列 (文字ごとに 1 つ)に分割したいと考えています。私はそれをやろうとしましたが、空の文字列をセパレーターとして受け入れないtidyr::separate
内部的に使用します(ただし、引数は正規表現を取る必要があります)。stringi::stri_split_regex
sep
library(tidyr)
separate(df, sequence, into = paste0("V", 1:5), sep="")
Error: Values not split into 5 pieces at 1, 2
In addition: Warning messages:
1: In stringi::stri_split_regex(value, sep, n_max) :
empty search patterns are not supported
2: In stringi::stri_split_regex(value, sep, n_max) :
empty search patterns are not supported
予想される出力は次のようになります。
category V1 V2 V3 V4 V5
1 X A A T . G
2 Y C C G - T