I am quite new to R and I am working on a data frame with several NULL values. So far I am not able to replace those, and I can't wrap my head about a solution so it would be amazing if anybody could help me.
All the variables where the NULL value comes up are classified as factor.
If I use the function is.null(data) the answer is FALSE, which means that the have to replaced to be able to make a decent graph.
Can I use set.seed to replace all the NULL values, or I need to use a different function?
You can use dplyr and replace
Data
df <- data.frame(A=c("A","NULL","B"), B=c("NULL","C","D"), stringsAsFactors=F)
solution
library(dplyr)
ans <- df %>% replace(.=="NULL", NA) # replace with NA
Output
A B
1 A <NA>
2 <NA> C
3 B D
Another example
ans <- df %>% replace(.=="NULL", "Z") # replace with "Z"
Output
A B
1 A Z
2 Z C
3 B D
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