有没有办法删除没有任何数值的数据行?

问题描述 投票:0回答:1

我有两列数据。数据的每一列都有数字值,但其中一些没有任何数值。我要删除没有任何数值的行。实际上,数据有1000行,但为简化起见,我在这里将数据文件制作得较小。谢谢!

a <- c(1, 2, 3, 4, "--") b <- c("--", 2, 3, "--", 5) data <- data.frame(a,b)

r numeric data-cleaning
1个回答
0
投票
library(dplyr) data %>% filter_all(all_vars(!is.na(as.numeric(.)))) # a b #1 2 2 #2 3 3

数据

data <- data.frame(a,b, stringsAsFactors = FALSE)

0
投票
data[!is.na(Reduce(`+`, lapply(data, as.numeric))), ] a b 2 2 2 3 3 3
© www.soinside.com 2019 - 2024. All rights reserved.