How to replace all NaN with a value in R

r
data_wrangling

#1

hello,

While trying to solve a classification problem I came across the below code in Python that replaces all NaN with -1.

I want to know what is the equivalent code in R to achieve the same.??


#2

try gsub function in R


#3

@hackers try the following code with train as data set and val as the variable.
is.na(train$val) //for checking the nan value in the variable train$val[which(is.nan(train$val))]=-1 //which gives the variables serial no that are nan


#4

Hey @hackers

Use this code

data[is.na(data)] = -1 ( ANY VALUE)

Hope this helps.

Regards,
Rohit


#5

Clean :slightly_smiling: