在一个特定的列中删除具有空白值的行 [英] Delete rows with blank values in one particular column

查看:152
本文介绍了在一个特定的列中删除具有空白值的行的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在处理一个大型数据集,其中包含NAs和其他空格的行:

I am working on a large dataset, with some rows with NAs and others with blanks:

df <- data.frame(ID = c(1:7),                                   
         home_pc = c("","CB4 2DT", "NE5 7TH", "BY5 8IB", "DH4 6PB","MP9 7GH","KN4 5GH"),               
         start_pc = c(NA,"Home", "FC5 7YH","Home", "CB3 5TH", "BV6 5PB",NA),               
         end_pc = c(NA,"CB5 4FG","Home","","Home","",NA))

如何一次删除NAs和空白(在start_pc和end_pc列中)?我以前使用过:

How do I remove the NAs and blanks in one go (in the start_pc and end_pc columns)? I have in the past used:

df<- df[-which(is.na(df$start_pc)), ]

...删除NAs - 是否有类似的命令来删除空格?

... to remove the NAs - is there a similar command to remove the blanks?

推荐答案

 df[!(is.na(df$start_pc) | df$start_pc==""), ]

这篇关于在一个特定的列中删除具有空白值的行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆