dataframe - Cleaning all columns of Data Frame at once in R -
i'm trying write line or 2 of code @ every column data frame blanks or non-numeric values, such n/a or nan, , replace them 0.
here attempts:
given data frame=df, total columns n tried:
df[,c(1:n)]<-sub("nan","0",df[,c(1:n)]) and attempt filter entire data frame:
df[df[,c(1:n)]=='nan',"c(1:n)"] my goal without using loop.
try df[is.na(df)] <- 0 , df[df == nan] <- 0
Comments
Post a Comment