列に分割する必要がある「」で区切られたデータの文字列がいくつかあります。n番目ごとの区切り文字でデータを分割する簡単な方法はありますか?たとえば、xの最初の値は、yの最初の4つの値が最初の試行に対応することを示しています。xの2番目の値は、yの次の3つの値が2番目の試行に対応することを示します。
x <- c("4 3 3", "3 3 3 2 3")
y <- c("110 88 77 66 55 44 33 22 33 44 11 22 11", "44 55 66 33 22 11 22 33 44 55 66 77 88 66 77 88")
目標は次のようなものです。
structure(list(session = 1:2, trial.1 = structure(1:2, .Label = c("110 88 77",
"44 55 66"), class = "factor"), trial.2 = structure(c(2L, 1L), .Label = c("33 22 11",
"66 55 44"), class = "factor"), trial.3 = structure(1:2, .Label = c("22 33 44",
"23 33 44"), class = "factor"), trial.4 = structure(c(NA, 1L), .Label = "55 66", class = "factor"),
trial.5 = structure(c(NA, 1L), .Label = "77 88 66", class = "factor")), .Names = c("session",
"trial.1", "trial.2", "trial.3", "trial.4", "trial.5"), class = "data.frame", row.names = c(NA,
-2L))
理想的には、yからの余分な値は、結果のデータフレームから削除する必要があり、不均一な行の長さはNAで埋める必要があります。