[英]as.date not working in R script for Jupyter Books
I have been writing code in R studio and tried to move it over to Jupyer Books to share it with people.我一直在 R 工作室编写代码,并试图将其移至 Jupyer Books 与人们分享。
The code all works in R studio but when I run it in Jupyer Books, as.date() does not convert the date column which begins as a factor into a date which then means I have no data when I subset by date later on.该代码在 R 工作室中全部工作,但是当我在 Jupyer Books 中运行它时, as.date() 不会将作为一个因素开始的日期列转换为日期,这意味着当我稍后按日期进行子集时我没有数据。
Has anyone had this happen and know a solution?有没有人发生过这种情况并知道解决方案? Or will I just need to use lubridate or similar to convert the date?
还是我只需要使用 lubridate 或类似工具来转换日期?
Thanks, Dave谢谢,戴夫
My guess is that you are running different R versions in both places.我的猜测是您在两个地方都运行不同的 R 版本。 Run
R.version.string
at both the places to check which version of R you are running at each of them.在这两个地方运行
R.version.string
以检查您在每个地方运行的 R 版本。 Since R 4.0.0 the default behaviour of R changed when importing string data into R.由于 R 4.0.0 将字符串数据导入 R 时,R 的默认行为发生了变化。 Previously they were imported as factors and now (since 4.0.0) they are imported as characters.
以前它们是作为因子导入的,现在(从 4.0.0 开始)它们是作为字符导入的。
The solution is to import your dataset with stringsAsFactors = FALSE
in both the places to see the same output at both the places.解决方案是在两个地方都使用
stringsAsFactors = FALSE
导入数据集,以便在两个地方看到相同的 output。
data <- read.csv('filename.csv', stringsAsFactors = FALSE)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.