What is the best way to round a vector that consists of numbers, NA, and NaN. I don't want to omit the NA or NaN because I want to retain the order of the numbers.
x = c(2,3,4,NA,"NaN",3, 5)
round(x,2) #does not work
Edits: Error in round(x, 2) : Non-numeric argument to mathematical function
x is a character vector because it contains a character "NaN". Converting x to numeric will help.
x = c(2,3,4,NA,"NaN",3, 5)
class(x) # To see the class of x
round(as.numeric(x),2)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With