根据其他 16 个数字列创建一个额外的列

create an extra column based on 16 other numeric columns

我有 16 个数字变量,当这 16 个变量中有 3 个或更多变量的值大于 1015 时,我需要创建一个额外的列为 YES(否则为 NO)。

我该怎么做?

谢谢

你可以试试 rowSums :

cols <- 1:16
df$res <- ifelse(rowSums(df[cols] > 1015, na.rm = TRUE) >= 3, 'Yes', 'No')