r - Remove NA values from a vector -
how can remove na values vector?
i have huge vector has couple of na values, , i'm trying find max value in vector (the vector numbers), can't because of na values.
how can remove na values can compute max?
trying ?max, you'll see has na.rm = argument, set default false. (that's common default many other r functions, including sum(), mean(), etc.)
setting na.rm=true you're asking for:
d <- c(1, 100, na, 10) max(d, na.rm=true) if want remove of nas, use idiom instead:
d <- d[!is.na(d)] a final note: other functions (e.g. table(), lm(), , sort()) have na-related arguments use different names (and offer different options). if na's cause problems in function call, it's worth checking built-in solution among function's arguments. i've found there's usually 1 there.
Comments
Post a Comment