Hi everyone,
I have a data frame with NA value and I need to remove it.
I tried all function like "na.omit" or "is.na" or "complete.cases" or "drop_na" in tidyr.
All of these function work but the problem that they remove all data.
For example:
> DF <- data.frame(x = c(1, 2, 3, 7, 10), y = c(0, 10, 5,5,12), z=c(NA, 33, 22,27,35))
> DF %>% drop_na(y)
x y z
1 1 0 NA
2 2 10 33
3 3 5 22
4 7 5 27
5 10 12 35
> DF %>% drop_na(z)
x y z
2 2 10 33
3 3 5 22
4 7 5 27
5 10 12 35
With these function, I'm removing all values in row 1.
What I want to do is to remove only NA values from column z without deleting/removing values for x and y. Maybe to have something like below or masking this values. Because later I need to do a PCA and I can't remove such an important data in x and y.
x y z
1 1 0
2 2 10 33
3 3 5 22
4 7 5 27
5 10 12 35
Hope I was clear enough by explaining my problem
Thanks in advance