1

I want to create a sequence but my variable has missing values like this

a <-  as.numeric(c(19,20,22,"NA",44,55,10,40))
seq(min(a),max(a),10)

I get this error

Error in seq.default(min(a), max(a), 10) : 
  'from' cannot be NA, NaN or infinite

Can I exclude the missing values from seq function? Without modifying the variables?

Charlotte
  • 391
  • 1
  • 4
  • 16

1 Answers1

3

The min and max functions have a na.rm argument, which can be used to ignore the NA values - see ?min:

> seq(min(a, na.rm = TRUE), max(a, na.rm = TRUE), 10)
[1] 10 20 30 40 50
Peter Diakumis
  • 3,942
  • 2
  • 28
  • 26