数据框已满<na>

时间:2018-11-23 21:15:12

标签: r

我有两个data.frame:df1

structure(list(trial = c("SA1", "SA1", "SA1", "SA1", "SA1", "SA1"), CID =c(2565L, 8640L, 8456L, 8631L, 9329L, 8683L), SID = c(3L, 87L, 11L, 17L, 6L, 16L), GID = c("GID16170", "GID449286", "GID62427", "GID345692", "GID41372", "GID451760"),TID = c(5428L, 5428L, 5428L, 5428L, 5428L, 5428L)), row.names = c(NA, 6L), class = "data.frame")

和df2

structure(list(GID = c("GID7173723", "GID4878677", "GID88208", "GID346403","GID268825", "GID7399578", "GID6624429"), `1A-1145442` = c(2L, 0L,2L, 2L, 0L, 2L, 2L), `1A-1158042` = c(2L, 0L, 2L, 2L, 0L, 2L, 2L), `1A-1158055` = c(2L, 2L, 2L, 2L, 2L, 2L, 2L), `1A-1229616` = c(2L, 2L, 2L, 2L, 2L, 2L, 2L), `1A-1236254` = c(2L, 2L, 2L, 2L, 2L, 2L, 2L), `1A-1238114` = c(2L, 2L, 2L, 2L, 2L, 2L, 2L)), row.names = c(NA, 7L), class = "data.frame")

当我做以下df2[df1$GID]时,我得到:

structure(list(GID = c(NA_character_, NA_character_, NA_character_,NA_character_, NA_character_, NA_character_, NA_character_), `1A-1145442` = c(NA_character_, NA_character_, NA_character_, NA_character_, NA_character_, NA_character_, NA_character_), `1A-1158042` = c(NA_character_, NA_character_, NA_character_, NA_character_, NA_character_, NA_character_, NA_character_), `1A-1158055` = c(NA_character_, NA_character_, NA_character_, NA_character_, NA_character_, NA_character_, NA_character_), `1A-1229616` =c(NA_character_, NA_character_, NA_character_, NA_character_, NA_character_, NA_character_, NA_character_), `1A-1236254` = c(NA_character_, NA_character_, NA_character_, NA_character_, NA_character_, NA_character_, NA_character_), `1A-1238114` = c(NA_character_, NA_character_, NA_character_, NA_character_, NA_character_, NA_character_, NA_character_)), row.names = c("NA", "NA.1", "NA.2", "NA.3", "NA.4", "NA.5", "NA.6"), class = "data.frame")

我的代码有什么问题?我想将df2中的行扩展到2700行。基本上df1有2700行,而df2有2180行。 df2 $ GID基本上也是unique(df1$GID),因此df2 $ GID的所有值都在df1 $ GID内。加上df2 $ GID的值重复。

致谢

0 个答案:

没有答案