我对R很陌生。
我正在对代码进行改造,从下面的代码中使用“ 10,Total All Industries”到“ 1013 Manufacturing”作为过滤器。
整个过程是我从两个.csv
文件中获取数据,按年计算平均值,然后根据ID进行排名。
我收到以下错误。
"Error: Can't find columns `JulyEmployment`, `AugustEmployment`,
`SeptemberEmployment` in `.data`."
我的主要问题是,是否应该调整继续单词/短语的c和l,保持?
在以前的版本中,变量是当前变量,最后一个变量不带m。
currentm %>%
filter(AreaType=="State" & Ownership=="Private" & Industry=="1013
Manufacturing")->currentm
lastm %>%
filter(AreaType=="State" & Ownership=="Private" & Industry=="1013
Manufacturing")->lastm
keepsc <-
c("St","Year","JulyEmployment","AugustEmployment","SeptemberEmployment")
current<- current[keepsc]
keepsl <- c("St","JulyEmployment","AugustEmployment","SeptemberEmployment")
last<- last[keepsl]
sample data
structure(list(`Area
Code` = c("1000", "2000", "4000", "5000",
"6000", "8000"), St = c("1", "2", "4", "5", "6", "8"), Cnty = c(0,
0, 0, 0, 0, 0), Own = c(5, 5, 5, 5, 5, 5), NAICS = c(1013, 1013,
1013, 1013, 1013, 1013), Year = c(2018, 2018, 2018, 2018, 2018,
2018), Qtr = c(3, 3, 3, 3, 3, 3), AreaType = c("State", "State",
"State", "State", "State", "State"), StName = c("Alabama", "Alaska",
"Arizona", "Arkansas", "California", "Colorado"), Area = c("Alabama --
Statewide",
"Alaska -- Statewide", "Arizona -- Statewide", "Arkansas -- Statewide",
"California -- Statewide", "Colorado -- Statewide"), Ownership =
c("Private",
"Private", "Private", "Private", "Private", "Private"), Industry = c("1013
Manufacturing",
"1013 Manufacturing", "1013 Manufacturing", "1013 Manufacturing",
"1013 Manufacturing", "1013 Manufacturing"), StatusCode = c(NA_character_,
NA_character_, NA_character_, NA_character_, NA_character_, NA_character_
), EstablishmentCount = c(5582, 590, 5006, 2923, 43616, 5807),
JulyEmployment = c(267000, 23611, 170553, 160677, 1330268,
148444), AugustEmployment = c(267558, 19253, 170715, 160761,
1334919, 148235), SeptemberEmployment = c(267609, 13392,
170936, 161102, 1332249, 147649), TotalQuarterlyWages = c(3684759051,
252044635, 3013769930, 1905042213, 29819289717, 2502830607
), AverageWeeklyWage = c(1060, 1034, 1358, 911, 1721, 1300
), EmploymentLocationQuotientRelativetoU.S. = c(1.57, 0.46,
0.7, 1.52, 0.88, 0.64), TotalWageLocationQuotientRelativetoU.S. = c(1.58,
0.52, 0.83, 1.46, 1.02, 0.63)), class = c("tbl_df", "tbl",
"data.frame"), row.names = c(NA, -6L), .Names = c("Area\nCode",
"St", "Cnty", "Own", "NAICS", "Year", "Qtr", "AreaType", "StName",
"Area", "Ownership", "Industry", "StatusCode", "EstablishmentCount",
"JulyEmployment", "AugustEmployment", "SeptemberEmployment",
"TotalQuarterlyWages", "AverageWeeklyWage",
"EmploymentLocationQuotientRelativetoU.S.",
"TotalWageLocationQuotientRelativetoU.S."))