尝试根据 R 中的日期进行过滤,在 charToDate(x) 中收到错误:字符串不是标准的明确格式
Trying to filter based on Date in R, receiving Error in charToDate(x) : character string is not in a standard unambiguous format
我正在尝试将我的数据框过滤为财政年度 (10-01-2018 / 09-31-2019) 内的日期。
原以为这样会更简单,但我一直收到错误消息。
Error in charToDate(x) :
character string is not in a standard unambiguous format
这是我正在尝试的:
数据集:
toStata <- structure(list(`Advance Identifier` = c("A00010001", "A00010001",
"A00010001", "A00010001", "A00010001"), `Date Due` = structure(c(1312934400,
1317772800, 1325721600, 1333584000, 1341446400), class = c("POSIXct",
"POSIXt"), tzone = "UTC"), Disbursement = c(85740440.38, 0, 0,
0, 0), `Principal Due` = c(0, 0, 0, 0, 0), `Interest Due` = c(0,
425817.56, 699557.43, 691953.54, 691953.54), `Capitalized Interest Due` = c(0,
0, 0, 0, 0), `Repayment Timing` = c("Beginning", "Beginning",
"Beginning", "Beginning", "Beginning"), `Disbursement Timing` = c("Beginning",
"Beginning", "Beginning", "Beginning", "Beginning"), `Capitalized Interest` = c(0,
0, 0, 0, 0), Payment = c(0, 425817.56, 699557.43, 691953.54,
691953.54), `Cash Grant Amount` = c(0, 0, 0, 0, 0), `Cash Grant Prepayment Effect Principal` = c(0,
0, 0, 0, 0), `Cash Grant Prepayment Effect Interest` = c(0, 0,
0, 0, 0), `Cash Grant Prepayment Effect Capitalized Interest` = c(0,
0, 0, 0, 0), `Interest Rate` = c(0.03237, 0.03237, 0.03237, 0.03237,
0.03237), `Payment Frequency` = c("Quarterly", "Quarterly", "Quarterly",
"Quarterly", "Quarterly"), `Modification Principal` = c(NA_real_,
NA_real_, NA_real_, NA_real_, NA_real_), `Modification Interest` = c(NA_real_,
NA_real_, NA_real_, NA_real_, NA_real_), `Modification Capitalized Interest` = c(NA_real_,
NA_real_, NA_real_, NA_real_, NA_real_)), row.names = c(NA, -5L
), class = c("tbl_df", "tbl", "data.frame"))
library(tidyverse)
file <- toStata %>%
filter('Date Due' >= as.Date("2010-10-01", format = "%Y-%m-%d") & 'Date Due' <= as.Date("2011-09-31", format = "%Y-%m-%d"))
也许我的细节太多了?不确定,不管我每次都收到错误;任何替代方案都会有所帮助!
9 月、4 月、6 月和 11 月共 30 天...检查您在 filter()
中的第二次约会
此外,如果变量名称中包含非法字符(如空格),则需要使用反引号。
我正在尝试将我的数据框过滤为财政年度 (10-01-2018 / 09-31-2019) 内的日期。
原以为这样会更简单,但我一直收到错误消息。
Error in charToDate(x) :
character string is not in a standard unambiguous format
这是我正在尝试的:
数据集:
toStata <- structure(list(`Advance Identifier` = c("A00010001", "A00010001",
"A00010001", "A00010001", "A00010001"), `Date Due` = structure(c(1312934400,
1317772800, 1325721600, 1333584000, 1341446400), class = c("POSIXct",
"POSIXt"), tzone = "UTC"), Disbursement = c(85740440.38, 0, 0,
0, 0), `Principal Due` = c(0, 0, 0, 0, 0), `Interest Due` = c(0,
425817.56, 699557.43, 691953.54, 691953.54), `Capitalized Interest Due` = c(0,
0, 0, 0, 0), `Repayment Timing` = c("Beginning", "Beginning",
"Beginning", "Beginning", "Beginning"), `Disbursement Timing` = c("Beginning",
"Beginning", "Beginning", "Beginning", "Beginning"), `Capitalized Interest` = c(0,
0, 0, 0, 0), Payment = c(0, 425817.56, 699557.43, 691953.54,
691953.54), `Cash Grant Amount` = c(0, 0, 0, 0, 0), `Cash Grant Prepayment Effect Principal` = c(0,
0, 0, 0, 0), `Cash Grant Prepayment Effect Interest` = c(0, 0,
0, 0, 0), `Cash Grant Prepayment Effect Capitalized Interest` = c(0,
0, 0, 0, 0), `Interest Rate` = c(0.03237, 0.03237, 0.03237, 0.03237,
0.03237), `Payment Frequency` = c("Quarterly", "Quarterly", "Quarterly",
"Quarterly", "Quarterly"), `Modification Principal` = c(NA_real_,
NA_real_, NA_real_, NA_real_, NA_real_), `Modification Interest` = c(NA_real_,
NA_real_, NA_real_, NA_real_, NA_real_), `Modification Capitalized Interest` = c(NA_real_,
NA_real_, NA_real_, NA_real_, NA_real_)), row.names = c(NA, -5L
), class = c("tbl_df", "tbl", "data.frame"))
library(tidyverse)
file <- toStata %>%
filter('Date Due' >= as.Date("2010-10-01", format = "%Y-%m-%d") & 'Date Due' <= as.Date("2011-09-31", format = "%Y-%m-%d"))
也许我的细节太多了?不确定,不管我每次都收到错误;任何替代方案都会有所帮助!
9 月、4 月、6 月和 11 月共 30 天...检查您在 filter()
此外,如果变量名称中包含非法字符(如空格),则需要使用反引号。