-2
請幫助重新排列行和cloumns 。 我有兩個表(墊和MAT1) 表1是墊如何重新排列R中的行和列
mat <- matrix("", 5, 7)
mat[c(1),] <- sample(c("AA", "AG", "GG", "--"), 7, TRUE)
mat[c(2),] <- sample(c("AA", "AT", "TT", "--"), 7, TRUE)
mat[c(3),] <- sample(c("CC", "CG", "GG", "--"), 7, TRUE)
mat[c(4,5),] <- sample(c("CC", "CG", "GG", "--"), 7, TRUE)
colnames(mat)= c("Line_1", "Line_2", "Line_3", "Line_4", "Line_5", "Line_6", "Line_7")
row.names(mat)= c("Marker_1", "Marker_2", "Marker_3", "Marker_4", "Marker_5")
表2是MAT1
mat1<-matrix(c("1", "1","3","8","10", 2.3, 4.3, 45.5, 102.8, 74.8), nrow = 5)
row.names(mat1)= c("Marker_1", "Marker_2", "Marker_3", "Marker_4", "Marker_5")
colnames(mat1)= c("Linkage_Group", "Map_Position")
我用cbind到兩個表
mat2 <- cbind(mat, mat1)
然而結合我需要通過比較每條線來重新獲得數據,並用以下格式的比較附加列來得到結果。如果TEH標記數據匹配它是「單聲道,如果一個或兩個已經丟失它是‘誤’,如果不匹配它是‘聚’
Comparison Marker Linkage_Group Map_Position LineX1 LineX2 Mon/Poly
Line_1/Line_2 "Marker_1" "1" "2.3" "AA" "--" Mis
Line_1/Line_3 "Marker_1" "1" "2.3" "AA" "TT" Poly
Line_1/Line_4 "Marker_1" "1" "2.3" "AA" "TT" Poly
Line_1/Line_5 "Marker_1" "1" "2.3" "AA" "AT" Poly
Line_1/Line_6 "Marker_1" "1" "2.3" "AA" "--" Mis
Line_1/Line_7 "Marker_1" "1" "2.3" "AA" "AA" Mono
.
.
.
將有上述實施例21個的組合。
這裏有很多R大師......請幫幫我!
謝謝akrub!...你救了我的一天! – user3543621
'user3543621'。沒問題......如果你對答案滿意,你可以接受它。 – akrun
akrun:在代碼中存在一個小問題,因爲當兩行都具有' - '時它不會正確區分。它應該在最後一欄中被分類爲「錯誤」而不是「單聲道」 – user3543621