Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Remove N/A from the Data Frame

Tags:

r

na

Data frame is like enter image description here

Where i have to remove the rows having atleast one N/A in any column of data frame.

Tried These

   frame1 <- na.omit(frame1)
   is.null(frame1)
   [1] FALSE

Guess there's a difference between NA and N/A How can i remove the rows as explained

like image 403
Shivpe_R Avatar asked Feb 02 '26 13:02

Shivpe_R


1 Answers

A  <- data.frame(x=c(1,2,3,4),
                 y=c(1,2,3,4),
                 z=c(1,"N/A",3,4))

A[A == "N/A"]  <- NA
na.omit(A)

The trick is to change your character values, "N/A" to what R understands to be NA.

like image 156
DarrenRhodes Avatar answered Feb 05 '26 05:02

DarrenRhodes



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!