2016-09-16 90 views
1

我有一個數據如下所示DF如何刪除重複的字符串併合並所有列字符串?

df<- structure(list(V1 = structure(c(5L, 1L, 2L, 3L, 4L), .Label = c("DNAJC11;FGOTG", 
"MAPK14", "PPIB", "RBX1", "USP14"), class = "factor"), V2 = structure(c(4L, 
3L, 2L, 1L, 1L), .Label = c("", "DNAJC9", "MAPK14", "USP14"), class = "factor"), 
    V3 = structure(c(3L, 2L, 4L, 5L, 1L), .Label = c("", "DNAJC11;FGOTG", 
    "GCLC", "GSR", "STIP1"), class = "factor")), .Names = c("V1", 
"V2", "V3"), class = "data.frame", row.names = c(NA, -5L)) 

我想所有列合併成一個,然後保持獨特的人 例如輸出應該是這樣的

USP14 
DNAJC11;FGOTG 
MAPK14 
PPIB 
RBX1 
DNAJC9 
GCLC 
GSR 
STIP1 

我試着使用melt功能,但我不知道如何做到這一點,任何意見表示讚賞。由於

+1

'unlist'然後'unique'? – rawr

+0

@rawr感謝您的回覆,如果您不介意,請作出回答,但如果不值得,請不要擔心,我會嘗試使用unlist功能。再次感謝 – nik

回答

1
unique(as.vector(as.matrix(df))) 

要沒有字符刪除條目:

vec<-unique(as.vector(as.matrix(df))) 
vec[-which(vec=="")] 

,或者禮貌@rawr

Filter(nzchar, unique(as.vector(as.matrix(df)))) 
+2

或'Filter(nzchar,unique(as.vector(as.matrix(df))))'去除字符 – rawr

+0

cool - 不知道nzchar我自己。謝謝 – MCharles

相關問題