我的数据如下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
功能,但我无法弄清楚如何执行此操作,任何评论都表示赞赏。谢谢
答案 0 :(得分: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))))