r subset rows by criteria and by factor group
问题 I have this data.frame with a lot of NAs: df <- data.frame(a = rep(letters[1:3], each = 3), b = c(NA, NA, NA, 1, NA, 3, NA, NA, 7)) df > df a b 1 a NA 2 a NA 3 a NA 4 b 1 5 b NA 6 b 3 7 c NA 8 c NA 9 c 7 I would like to subset this dataframe to obtain only factor group rows that have no less than two values, such as this: a b 1 b 1 2 b NA 3 b 3 I have tried this function but it doesn't work: subset(df, sum(!is.na(b)) < 1, by = a) > [1] a b <0 rows> (or 0-length row.names) Any suggestion?