-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy path35 DPLYR select_remove_variables.R
More file actions
39 lines (27 loc) · 1.27 KB
/
35 DPLYR select_remove_variables.R
File metadata and controls
39 lines (27 loc) · 1.27 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
# 35 DPLYR select_remove_variables
library(here)
library(tidyverse)
library(janitor)
# LEAFLET_MAPS_DATA.csv
# 1. When loading intial dataset
map_data <-read.table(here("data", "LEAFLET_MAPS_DATA.csv"),
header =TRUE, sep =',',stringsAsFactors =TRUE) %>%
clean_names()
map_data
names(map_data)
# [1] "x" "country" "lat" "long" "date" "confirmed" "recovered" "deaths" "year"
# [10] "population"
# 2. Sometimes we want to omit certain variables
# As an example, let's exclude variables (x,recovered,deaths,year) from our original data set
# We use select(!c("x","recovered","deaths","year")), to remove these four variable("x","recovered","deaths","year")
data_subset <-read.table(here("data", "LEAFLET_MAPS_DATA.csv"),
header =TRUE, sep =',',stringsAsFactors =TRUE) %>%
clean_names() %>%
select(!c("x","recovered","deaths","year")) # Use select(!c("variable1","variable2",...))
data_subset
names(data_subset)
str(data_subset)
# We have excluded these variables from our final data frame
# Also, we can select several columns in one go using this select verb form:
# select(!(name:mass))
# [1] "country" "lat" "long" "date" "confirmed" "population"