我有所附的文件。我已经将xlxs文档导入到了R中,我想去掉包含NA的所有行。我试过以下几种方法,但不起作用。
# install packages Note# tidyverse installs packages for dplyr and ggplot2
install.packages("tidyverse")
install.packages("readxl")
#open the library
library(tidyverse)
library(readxl)
setwd("~/Documents/UofL/Data_Science/CECS_635/week_3/")
un <- read_excel("UnitedNations.xlsx")
un1 %>% drop_na(un,)
发布于 2019-01-27 09:07:21
它应该是有效的
data_set<-na.omit(un)
如果想要处理NA的意思或中间值:
na.mean(un, option = "mean")
来源:https://www.rdocumentation.org/packages/imputeTS/versions/2.7/topics/na.mean
发布于 2019-01-27 13:10:31
通过将xlsx文件转换为csv文件,我能够让应用程序删除NA值。一旦csv上传到R,我就可以省略NA行。
# to remove the NA values I converted the xlsx file to csv
united_nations <- read_csv("UnitedNations.csv", col_names = TRUE)
# used the na.omit option to remove rows with NA
united_nations = na.omit(united_nations)
发布于 2019-06-26 16:33:16
或在数据框架中:
mydata <- data.frame(c(1,2,NA,3))
mydata <- mydata[complete.cases(mydata),]
https://datascience.stackexchange.com/questions/44621
复制相似问题