第一個字符串我有這樣如何保持每行
df1 <- structure(list(V1 = structure(c(1L, 2L, 3L, 5L, 4L), .Label = c("A0A061ACH4;Q95Q10;Q9U1W6",
"A0A061ACL3;Q965I6;O76618", "A0A061ACR1;Q2XN02;F5GUA3;Q22498",
"A0A061AL01", "H2FLH3;H2FLH2;A0A061ACT3;A0A061AE24;Q23551-2;Q23551;Q23551-4;Q23551-3;Q23551-5"
), class = "factor"), V2 = c(1L, 5L, 100L, 645L, 11L), V3 = c(67L,
10L, 33L, 99L, 10L), V4 = c(7L, 16L, 0L, 1L, 5L)), .Names = c("V1",
"V2", "V3", "V4"), class = "data.frame", row.names = c(NA, -5L
))
我要的是一個數據,保證把所有的琴絃下對方,在每行前面複製的價值,前面在該行每個字符串
預期的輸出應該喜歡這個
output <- structure(list(V1 = structure(c(1L, 18L, 20L, 2L, 19L, 19L, 10L,
3L, 17L, 7L, 11L, 9L, 8L, 4L, 5L, 13L, 12L, 15L, 14L, 16L, 6L
), .Label = c("A0A061ACH4", "A0A061ACL3", "A0A061ACR1", "A0A061ACT3",
"A0A061AE24", "A0A061AL01", "F5GUA3", "H2FLH2", "H2FLH3", "O76618",
"Q22498", "Q23551", "Q23551-2", "Q23551-3", "Q23551-4", "Q23551-5",
"Q2XN02", "Q95Q10", "Q965I6", "Q9U1W6"), class = "factor"), V2 = c(1L,
1L, 1L, 5L, 5L, 5L, 5L, 100L, 100L, 100L, 100L, 645L, 645L, 645L,
645L, 645L, 645L, 645L, 645L, 645L, 11L), V3 = c(67L, 67L, 67L,
10L, 10L, 10L, 10L, 33L, 33L, 33L, 33L, 99L, 99L, 99L, 99L, 99L,
99L, 99L, 99L, 99L, 10L), V4 = c(7L, 7L, 7L, 16L, 16L, 16L, 16L,
0L, 0L, 0L, 0L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 5L)), .Names = c("V1",
"V2", "V3", "V4"), class = "data.frame", row.names = c(NA, -21L
))
例如,如果我們看一下DF1第一線,它看起來像這樣
A0A061ACH4;Q95Q10;Q9U1W6 1 67 7
然後我分割後的字符串;並將它們置於彼此之下並將值複製到它們的前面。所以對於DF1的第一行,我會
A0A061ACH4 1 67 7
Q95Q10 1 67 7
Q9U1W6 1 67 7
請注意,您的預期產出存在輕微錯誤。結果應該是20行。 –