0
$\begingroup$

I have the attached document. I've imported an xlxs document into R. I would like to get rid of all rows containing NA. I've tried the following but it isn't working.

# 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,)

enter image description here

$\endgroup$
0
$\begingroup$

its should be working

data_set<-na.omit(un)

If want to handle NA's to mean or median:

na.mean(un, option = "mean")

Source: https://www.rdocumentation.org/packages/imputeTS/versions/2.7/topics/na.mean

| improve this answer | |
$\endgroup$
0
$\begingroup$

I was able to get the application to drop the NA values by converting the xlsx file to a csv file. Once the csv was uploaded into R, I was able to omit the NA rows.

# 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)

enter image description here

| improve this answer | |
$\endgroup$
0
$\begingroup$

Or in a data frame:

mydata <- data.frame(c(1,2,NA,3))
mydata <- mydata[complete.cases(mydata),]
| improve this answer | |
$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.