【发布时间】:2018-11-01 10:08:21
【问题描述】:
我正在尝试过滤我的数据集,使其仅包含 1996-2015 年的行,并且仅包含 orgid、stdate、locid、charnam 列。整个数据集包含从 1988 年到 2015 年的年份以及大量不同的列。我最近刚刚了解了 dplyr 包,并认为这将是可行的方法。但是,我不断收到此错误,我不明白为什么会收到此错误。我不断收到的错误是Error in is_character(x) : object 'rlang_is_character' not found
这是我目前的代码:
########## download necessary packages to make script run #########################################################################
if (!require(pacman)) {
install.packages('pacman')
}
pacman::p_load("tidyverse")
#### Read in the necessary data ######
roadsalt_data<-read.table("QADportaldata_1988-2015.tsv",header=T,sep="\t",fill=T,stringsAsFactors = F)
#Convert date column from a character class to a date class so ggplot can display as a continuous variable ###
roadsalt_data$stdate <- as.Date(roadsalt_data$stdate)
## Filter dataset to only contain years 1996-2015 ########
roadsalt_data_sub<-roadsalt_data %>%
select(orgid,stdate,locid,charnam) %>%
filter(between(roadsalt_data, as.Date("1996-01-01"), as.Date("2015-07-01")))
这是数据集的预览:
structure(list(orgid = c("USGS-NJ", "USGS-NJ", "USGS-NJ", "USGS-NJ",
"USGS-NJ", "USGS-NJ", "USGS-NJ", "USGS-NJ", "USGS-NJ", "USGS-NJ"
), actid = c("nwisnj.01.01300274", "nwisnj.01.01300273", "nwisnj.01.01300247",
"nwisnj.01.01300242", "nwisnj.01.01300238", "nwisnj.01.01300237",
"nwisnj.01.01300189", "nwisnj.01.01300189", "nwisnj.01.01300189",
"nwisnj.01.01300190"), actyp = c("Sample-Routine", "Sample-Routine",
"Sample-Routine", "Sample-Routine", "Sample-Routine", "Sample-Routine",
"Sample-Routine", "Sample-Routine", "Sample-Routine", "Sample-Routine"
), stdate = structure(c(15755, 15755, 15748, 15748, 15748, 15748,
15740, 15740, 15740, 15740), class = "Date"), sttime = c("09:30:00",
"11:00:00", "10:30:00", "12:00:00", "11:00:00", "11:30:00", "09:25:00",
"09:25:00", "09:25:00", "09:30:00"), actdep = c(NA_real_, NA_real_,
NA_real_, NA_real_, NA_real_, NA_real_, NA_real_, NA_real_, NA_real_,
NA_real_), actdepun = c("", "", "", "", "", "", "", "", "", ""
), locid = c("USGS-01407760", "USGS-01445030", "USGS-01380075",
"USGS-01368820", "USGS-01409815", "USGS-01411400", "USGS-01458570",
"USGS-01458570", "USGS-01458570", "USGS-01445160"), actcom = c("A-0520044 TPCN = 64mL filtered",
"A-0520046 TPCN = 124mL filtered", "A-0460036 TPCN = 124mL filtered L-0460036 Received February 14, 2013",
"A-0460025 TPCN = 125mL filtered L-0460025 Received February 14, 2013",
"A-0460027 TPCN = 64mL filtered. ATTN: H.Ardourel, LL ANC and LL pH L-0460027 Received February 14, 2013",
"A-0460028 TPCN = 125mL filtered. L-0460028 Received February 14, 2013",
"A-0370012 TPCN = 125mL filtered", "A-0370012 TPCN = 125mL filtered",
"A-0370012 TPCN = 125mL filtered", "A-0370011 TPCN = 125mL filtered"
), hydcond = c("Stable, normal stage", "Stable, normal stage",
"Stable, normal stage", "Stable, normal stage", "Stable, high stage",
"Falling stage", "Stable, normal stage", "Stable, normal stage",
"Stable, normal stage", "Stable, high stage"), hydev = c("Routine sample",
"Routine sample", "Routine sample", "Routine sample", "Routine sample",
"Routine sample", "Routine sample", "Routine sample", "Routine sample",
"Routine sample"), metcont = c("USGS parameter code 82398", "USGS parameter code 82398",
"USGS parameter code 82398", "USGS parameter code 82398", "USGS parameter code 82398",
"USGS parameter code 82398", "USGS parameter code 82398", "USGS parameter code 82398",
"USGS parameter code 82398", "USGS parameter code 82398"), metnam = c("Multiple verticals",
"Multiple verticals", "Multiple verticals", "Multiple verticals",
"Single vertical", "Multiple verticals", "Grab sample (dip)",
"Grab sample (dip)", "Grab sample (dip)", "Multiple verticals"
), detcond = c("", "", "", "", "Not Detected", "", "", "", "",
""), charnam = c("Nitrogen, mixed forms (NH3), (NH4), organic, (NO2) and (NO3)",
"Nitrogen, mixed forms (NH3), (NH4), organic, (NO2) and (NO3)",
"Nitrogen, mixed forms (NH3), (NH4), organic, (NO2) and (NO3)",
"Nitrogen, mixed forms (NH3), (NH4), organic, (NO2) and (NO3)",
"Nitrogen, mixed forms (NH3), (NH4), organic, (NO2) and (NO3)",
"Nitrogen, mixed forms (NH3), (NH4), organic, (NO2) and (NO3)",
"Inorganic nitrogen (nitrate and nitrite)", "Phosphorus", "Phosphorus",
"Kjeldahl nitrogen"), samfrac = c("Dissolved", "Dissolved", "Dissolved",
"Dissolved", "Dissolved", "Dissolved", "Dissolved", "Total",
"Dissolved", "Dissolved"), val = c("0.84", "1.2", "0.46", "0.28",
"", "0.66", "3.10", "0.032", "0.028", "0.21"), valunit = c("mg/l",
"mg/l", "mg/l", "mg/l", "", "mg/l", "mg/l as N", "mg/l as P",
"mg/l as P", "mg/l as N"), valqual = c("", "", "", "", "", "",
"", "", "", ""), valstat = c("Accepted", "Accepted", "Accepted",
"Accepted", "Accepted", "Accepted", "Accepted", "Accepted", "Accepted",
"Accepted"), statcode = c("", "", "", "", "", "", "", "", "",
""), valtype = c("Actual", "Actual", "Actual", "Actual", "Actual",
"Actual", "Actual", "Actual", "Actual", "Actual"), precval = c(NA_real_,
NA_real_, NA_real_, NA_real_, NA_real_, NA_real_, NA_real_, NA_real_,
NA_real_, NA_real_), valcom = c("", "", "", "", "", "", "Report level code updated Oct., Nov. 2015. Reference: NWQL Rapi-Note 2011-21 (RLC: IRL => LT-MDL)",
"", "", ""), valdep = c(NA_real_, NA_real_, NA_real_, NA_real_,
NA_real_, NA_real_, NA_real_, NA_real_, NA_real_, NA_real_),
valdepun = c("", "", "", "", "", "", "", "", "", ""), valmetnam = c("Computation by NWIS algorithm",
"Computation by NWIS algorithm", "Computation by NWIS algorithm",
"Computation by NWIS algorithm", "Computation by NWIS algorithm",
"Computation by NWIS algorithm", "NO3+NO2, wf, FCC,NaR, DA",
"P, wu, WCA, persulfate CF color", "P, wf, FCA, persulfate CF color",
"NH3+org-N, wf, FCA, Kjeldahl, CF"), metdesc = c("NWIS User's Manual, QW System, Section 3.6.7",
"NWIS User's Manual, QW System, Section 3.6.7", "NWIS User's Manual, QW System, Section 3.6.7",
"NWIS User's Manual, QW System, Section 3.6.7", "NWIS User's Manual, QW System, Section 3.6.7",
"NWIS User's Manual, QW System, Section 3.6.7", "", "", "",
"USGS OF 00-170"), labcom = c("", "", "", "", "", "", "",
"", "", ""), detlimnam = c("", "", "", "", "Historical Lower Reporting Limit",
"", "Long Term Method Detection Level", "Long Term Method Detection Level",
"Long Term Method Detection Level", "Long Term Method Detection Level"
), detlimval = c("", "", "", "", "0.23", "", "0.04", "0.004",
"0.0040", "0.07"), detlimun = c("", "", "", "", "mg/l", "",
"mg/l as N", "mg/l as P", "mg/l as P", "mg/l as N"), V63 = c("NWIS",
"NWIS", "NWIS", "NWIS", "NWIS", "NWIS", "NWIS", "NWIS", "NWIS",
"NWIS")), .Names = c("orgid", "actid", "actyp", "stdate",
"sttime", "actdep", "actdepun", "locid", "actcom", "hydcond",
"hydev", "metcont", "metnam", "detcond", "charnam", "samfrac",
"val", "valunit", "valqual", "valstat", "statcode", "valtype",
"precval", "valcom", "valdep", "valdepun", "valmetnam", "metdesc",
"labcom", "detlimnam", "detlimval", "detlimun", "V63"), row.names = c(NA,
10L), class = "data.frame")
任何帮助将不胜感激!提前致谢!
【问题讨论】:
-
您拥有哪个版本的
rlang?重装rlang到新版本后试试 -
我有版本'0.2.0.9001' @akrun
-
在过滤步骤中,您使用的是整个数据集而不是列?应该是
filter(between(stdate, as.Date("1996-01-01"), as.Date("2015-07-01"))) -
我不确定是否建议升级 R 版本以尝试解决依赖性问题,R 3.5.0 的更新仍然相对较新,并且有些软件包在获取更新版本时遇到了问题在 CRAN 上发布 3.5.0。兼容性问题存在于
dplyrrlang工具链中,因为当我使用 R 3.4.3、dplyr 0.7.4 和 rlang 0.2.0.9000 运行 @akrun 的dplyr代码时,它适用于我。 -
我总是安装单独的包而不是组合包