【发布时间】:2020-08-19 09:18:27
【问题描述】:
我有一个包含参与者 ID 和观察结果的数据框。我还有一些需要从该数据框中删除的参与者的 ID 列表 - 我想删除与该参与者 ID 关联的整行。我尝试了以下方法:
ListtoRemove <- as.list(ListtoRemove)
NewDataFrame <-
subset(OldDataFrame,OldDataFrame$ParticipantsIDs!=ListtoRemove)
这会给出两个警告并且不会删除行。
1: In `!=.default`(DemographicsALL$subject_label, AllSibs) :
longer object length is not a multiple of shorter object length
2: In is.na(e1) | is.na(e2) :
longer object length is not a multiple of shorter object length
>
数据示例:
structure(list(ParticipantsIDs = structure(c(2L, 1L, 3L, 4L,
6L, 5L), .Label = c("B0002", "B001", "B003", "B004", "L004",
"M003"), class = "factor"), Age = structure(c(3L, 1L, 4L, 2L,
5L, 6L), .Label = c("15", "23", "45", "53", "65", "98"), class =
"factor")), class = "data.frame", row.names = c(NA,
-6L))
ListtoRemove <- as.list(B004,M003)
【问题讨论】:
-
是来自
NewDataFrame的dput -
B004和M003是什么?变量(如所写)或字符串(当前存在语法错误)?
标签: r dataframe conditional-statements rows