简体   繁体   中英

Removing NA from a variable in R

I want to know if I can remove NAs from a variable without creating a new subset?

The only solutions I find are making me create a new dataset. But I want to delete those rows that have NA in that variable right from the original dataset.

From:

Title Length

1- A NA

2- B 2

3- C 7

Title Length

2- B 2

3- C 7

Is it even possible?

The best solution I found was this one (but as I sad it creates a new dataset): completerecords <- na.omit(data$emp_length)

Thank you,

Dani

You can reuse the same dataset name to overwrite the original one:

In your example, it would be:

data <- data[!is.na(data$emp_length),]

Note that this way you would remove only the rows that have NA in the column you're interested in, as requested. If some other rows have NA values in different columns, these rows will not be affected.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM