0

次のような data.frame があるとします。

structure(list(HUGO.Int1 = c("AATF", "AATF", "AATF", "ABHD16A", 
"ABHD16A", "ABHD16A"), Mut.Int1 = c(0, 0, 0, 0, 0, 0), HUGO.Int2 = c("DAPK3", 
"PAWR", "CHEK1", "RNF5", "ATP5G3", "HM13"), Mut.Int2 = c(0, 0, 
0, 0, 0, 0)), .Names = c("HUGO.Int1", "Mut.Int1", "HUGO.Int2", 
"Mut.Int2"), row.names = c(12223L, 15033L, 31655L, 11280L, 11463L, 
14106L), class = "data.frame")

そして私はになりたいHUGO.Int2と思っMut.Int2ています HUGO.Int1Mut.Int1

私はもう試した

data.frame(rbind(c(plots$HUGO.Int1, plots$Mut.Int1), 
           c(plots$HUGO.Int2, plots$Mut.Int2)))

しかし、その後、2列しか返されませHugo.int1Mut.int1。1列目と2列目の下に3列目と4列目を適切に貼り付ける方法を知りたいです。

4

4 に答える 4

2

別の方法:

names(x) <- chartr('12', 'XX', names(x)) # replaces 1s and 2s in names with 'X'
rbind(x[1:2], x[3:4])
于 2013-01-18T19:27:56.383 に答える
2

問題はrbind、ランダムに、そこにとどまっていることです。これはおそらくあなたの試みがどのように見えるべきかでした:

dat <- structure(list(HUGO.Int1 = c("AATF", "AATF", "AATF", "ABHD16A", 
+ "ABHD16A", "ABHD16A"), Mut.Int1 = c(0, 0, 0, 0, 0, 0), HUGO.Int2 = c("DAPK3", 
+ "PAWR", "CHEK1", "RNF5", "ATP5G3", "HM13"), Mut.Int2 = c(0, 0, 
+ 0, 0, 0, 0)), .Names = c("HUGO.Int1", "Mut.Int1", "HUGO.Int2", 
+ "Mut.Int2"), row.names = c(12223L, 15033L, 31655L, 11280L, 11463L, 
+ 14106L), class = "data.frame")
> data.frame(col1 = c(dat[,1],dat[,3]),col2 = c(dat[,2],dat[,4]))
      col1 col2
1     AATF    0
2     AATF    0
3     AATF    0
4  ABHD16A    0
5  ABHD16A    0
6  ABHD16A    0
7    DAPK3    0
8     PAWR    0
9    CHEK1    0
10    RNF5    0
11  ATP5G3    0
12    HM13    0
于 2013-01-18T19:17:33.600 に答える
1

これがあなたが望むものであるかどうかはわかりませんが、それは機能します:

data1 <- structure(list(HUGO.Int1 = c("AATF", "AATF", "AATF", "ABHD16A", 
"ABHD16A", "ABHD16A"), Mut.Int1 = c(0, 0, 0, 0, 0, 0), HUGO.Int2 = c("DAPK3", 
"PAWR", "CHEK1", "RNF5", "ATP5G3", "HM13"), Mut.Int2 = c(0, 0, 
0, 0, 0, 0)), .Names = c("HUGO.Int1", "Mut.Int1", "HUGO.Int2", 
"Mut.Int2"), row.names = c(12223L, 15033L, 31655L, 11280L, 11463L, 
14106L), class = "data.frame")

data2 <- cbind(data1$HUGO.Int2, data1$Mut.Int2)
data1$HUGO.Int2 <- NULL
data1$Mut.Int2 <- NULL
colnames(data2) <- colnames(data1)
data3 <- rbind(data1,data2)


> data3 
      HUGO.Int1 Mut.Int1
12223      AATF        0
15033      AATF        0
31655      AATF        0
11280   ABHD16A        0
11463   ABHD16A        0
14106   ABHD16A        0
7         DAPK3        0
8          PAWR        0
9         CHEK1        0
10         RNF5        0
11       ATP5G3        0
12         HM13        0
于 2013-01-18T19:16:37.100 に答える
1
df <- structure(list(HUGO.Int1 = c("AATF", "AATF", "AATF", "ABHD16A", 
"ABHD16A", "ABHD16A"), Mut.Int1 = c(0, 0, 0, 0, 0, 0), HUGO.Int2 = c("DAPK3", 
"PAWR", "CHEK1", "RNF5", "ATP5G3", "HM13"), Mut.Int2 = c(0, 0, 
0, 0, 0, 0)), .Names = c("HUGO.Int1", "Mut.Int1", "HUGO.Int2", 
"Mut.Int2"), row.names = c(12223L, 15033L, 31655L, 11280L, 11463L, 
14106L), class = "data.frame")

df2 <- df[,1:2]
df2[7:12,1:2] <- df[,3:4]
于 2013-01-18T19:21:27.457 に答える