I have a data frame in R, where some columns have values in some rows NA
or Empty strings ""
I want to convert them to NULL
values
So I need any cell in my data frame that is < Code> NA or ""
should be NULL
How can I do this?
When I try:
DF [, DF $ column == NA] -
or < / P>
df [, df $ column == ""]
I get an error: are missing values
DF [, is.na (df $ column)]
/ code>
I get an error: Duplicate subscript for columns < / Code>
If I try:
is.na (df $ column) & lt; - NULL
or
DF [DF == NA] & lt; - NULL
I have not found any errors, but nothing has changed in my dataframe.
There is actually no zero in the value in vector NA is placeholder if you want to remove the whole column (Which is what will happen), when its values are all NA, then it will be successful:
df [, sapply (df, function (x) all (If.na (x) ))) & Lt; - NULL
If you want to create an object where you only place those lines with NA values:
df [apply (DF) , 1, function (rw)! Any (is.na (rw)),]
Comments
Post a Comment