我找的到了unpivot一個基礎R解決方案,我的子串原始數據集。下面的例子;的R - 逆透視及子
ID L1 L2 L3
1 AABBCC BACA
2 AAAAAA BACBA CACCC
3 BBACB BACA CABAC
4
5 BCBDAB ACAA CBABA
dput(original_data):
structure(list(ID = 1:5, L1 = structure(c(3L, 2L, 4L, 1L, 5L), .Label = c("","AAAAAA", "AABBCC", "BBACB", "BCBDAB"), class = "factor"), L2 = structure(c(3L,4L, 3L, 1L, 2L), .Label = c("", "ACAA", "BACA", "BACBA"), class = "factor"),L3 = structure(c(1L, 3L, 2L, 1L, 4L), .Label = c("", "CABAC","CACCC","CBABA"), class = "factor")), .Names = c("ID", "L1","L2", "L3"),class = "data.frame", row.names = c(NA, -5L))
將一個較長的表,同時採取3個重疊的連續字符的子串,下面的例子;
ID Column Position Substring
1 L1 1 AAB
1 L1 2 ABB
1 L1 3 BBC
1 L1 4 BCC
1 L1 5 CC
1 L1 6 C
1 L2 1 BAC
1 L2 2 ACA
1 L2 3 AC
1 L2 4 A
2 L1 1 AAA
2 L1 2 AAA
2 L1 3 AAA
2 L1 4 AAA
2 L1 5 AA
2 L1 6 A
2 L2 1 BAC
2 L2 2 ACB
2 L2 3 CBA
2 L2 4 BA
2 L2 5 A
2 L3 1 CAC
2 L3 2 ACC
2 L3 3 CCC
2 L3 4 CC
2 L3 5 C
有沒有人有任何想法如何做到這一點?我的問題是我不能使用外部庫,如reshap2。我需要在基地r做到這一點。
你的「結構」爲您的樣本數據被打破,它不糊成R正確。你可以再試一次嗎? – Spacedman
謝謝,我想我已經糾正了這一點。現在怎麼樣? –