0

我有一个包含多个国家的数据集(例如,阿富汗 2014、2015、2016、2017、2018),我想删除任何国家(集体),如果他们的行/列之一有 NA。

在这种情况下,如果(阿富汗有 2015,2016,2019)只有它的所有数据应该从列表中删除。

install.packages('BiocManager')
require(pacman)  # Gives a confirmation message.
library(pacman)  # No message.
require(graphics)

# Or, by using "pacman::p_load" you can use the p_load
# function from pacman without actually loading pacman.
# These are packages I load every time.
pacman::p_load(pacman, dplyr, GGally, ggplot2, ggthemes, 
               ggvis, httr, lubridate, plotly, rio, rmarkdown, shiny, 
               stringr, tidyr, LogisticDx, WDI, tibble, tidyverse, DT, factoextra, cluster, purrr, Amelia, dendextend,
               corrplot)
#Code below will pull all the indicators as mentioned above from WDI directly and filtered values that is not country within the data such as (World, Asia, etc..)
data1 <-WDI(indicator= c("IT.NET.USER.ZS","SL.UEM.TOTL.ZS", "IT.NET.SECR.P6" , "SP.POP.1564.TO.ZS", "EG.ELC.ACCS.ZS", "IT.NET.BBND.P2","GE.PER.RNK", "RQ.PER.RNK"), start = 2014, end = 2018, extra = FALSE)%>%
  rename (internet.user = "IT.NET.USER.ZS",
          unemployment = "SL.UEM.TOTL.ZS",
          secure.internet = "IT.NET.SECR.P6",
          population.15.64 = "SP.POP.1564.TO.ZS",
          access.electricity = "EG.ELC.ACCS.ZS",
          fixed.broadband = "IT.NET.BBND.P2",
          govt.effectiveness = "GE.PER.RNK",
          regulatory.quality = "RQ.PER.RNK",
          countries = "country") %>%
  group_by(countries) %>%                         
  mutate(sum.secure.internet = sum(secure.internet)) %>% 
  filter(!iso2c %in% c("1A","1W","4E","7E","8S","B8", "CF", "EU","F1","JG","OE", "S1","S2", "S3", "S4","T2", "T3", "T4","T5", "T6","T7","V1","V2", "V3","V4","XC",
                       "XD", "XE", "XF","XG","XH","XI","XJ","XL","XM", "XN","XO","XP","XQ", "XT","XU","XY", "Z4","Z7","ZF","ZG","ZJ","ZQ","ZT"))

# data 1 summary
str(data1)
summary(data1)
data1$countries <- as.character(gsub(",","",data1$countries))
view(data1)
data2 <- na.omit(data1, year = 2018)
view(data2)```
4

0 回答 0