In the dataset below the variable Region
before subsetting has the following structure:
> levels(corona$Region)
[1] " Montreal, QC"
[2] "Alabama"
[3] "Alameda County, CA"
[4] "Alaska"
[5] "Alberta"
[6] "American Samoa"
[7] "Anhui" ...
including both United States states as well as counties, and cities, etc.
I want to subset just the states in the United States running the code:
require(RCurl)
require(foreign)
require(tidyverse)
corona = read.csv("https://coviddata.github.io/covid-api/v1/regions/cases.csv", sep =",",header = T)
cor <- corona[corona$Country=="United States" & corona$Region %in% state.name,]
which works, in a way, but somehow keeps the original levels for Region
:
> levels(cor$Region)
[1] " Montreal, QC"
[2] "Alabama"
[3] "Alameda County, CA"
[4] "Alaska"
[5] "Alberta"
[6] "American Samoa"
[7] "Anhui"
[8] "Arizona"
[9] "Arkansas"
[10] "Aruba" ...
as though the subsetting never happened. How can I keep only the levels subsetted (the states)?