Search code examples
rassign

Convert blanks in a column to NAs


I'm trying to put NA into the blank spaces in the AWC_Code column in this dataframe (there's 4 rows here but I have 4k of them).

Region, LocationID, DistrictID,SubDistrictID,Area,AWC_Code
Yukon, 1,2,3,2,106-2
Yukon,1,2,4,5,
Kodiak,4,5,6,8,
Kodiak,6,8,9,5,333-1

Solution

  • Assuming your dataframe is called df, try this:

    df$AWC_Code[is.null(df$AWC_Code)] <- "NA"