Ale*_*lex 9 posix r date character
可能重复:
为什么as.Date在字符向量上变慢?
我data.frame从数据库中读取了一个大的(大约60密耳的观察结果)RMySQL.日期是作为字符引入的(似乎没有办法改变这个)所以我用它as.Date来转换日期.然而,这需要很长时间才能进行如此多的观察.有什么办法可以让它更快吗?
Dir*_*tel 20
Simon Urbanek的快速库对于可解析的日期时间来说非常快:
R> now <- Sys.time()
R> now
[1] "2012-10-15 10:07:28.981 CDT"
R> fasttime::fastPOSIXct(format(now))
[1] "2012-10-15 05:07:28.980 CDT"
R> as.Date(fasttime::fastPOSIXct(format(now)))
[1] "2012-10-15"
R>
Run Code Online (Sandbox Code Playgroud)
但是,它仅解析ISO格式并将UTC视为时区.
3年半后编辑: 一些评论者似乎认为快速软件包很难安装.我不敢苟同.这里是(再一次)使用install.r,它只是一个使用littler的简单包装器(也作为一个例子提供):
edd@max:~$ install.r fasttime
trying URL 'https://cran.rstudio.com/src/contrib/fasttime_1.0-1.tar.gz'
Content type 'application/x-gzip' length 2646 bytes
==================================================
downloaded 2646 bytes
* installing *source* package ‘fasttime’ ...
** package ‘fasttime’ successfully unpacked and MD5 sums checked
** libs
ccache gcc -I/usr/share/R/include -DNDEBUG -fpic -g -O2 -fstack-protector-strong -Wformat -Werror=format-security -D_FORTIFY_SOURCE=2 -g -O3 -Wall -pipe -pedantic -std=gnu99 -c tparse.c -o tparse.o
ccache gcc -shared -L/usr/lib/R/lib -Wl,-Bsymbolic-functions -Wl,-z,relro -o fasttime.so tparse.o -L/usr/lib/R/lib -lR
installing to /usr/local/lib/R/site-library/fasttime/libs
** R
** preparing package for lazy loading
** help
*** installing help indices
** building package indices
** testing if installed package can be loaded
* DONE (fasttime)
The downloaded source packages are in
‘/tmp/downloaded_packages’
edd@max:~$
Run Code Online (Sandbox Code Playgroud)
正如您所看到的,该软件包具有零外部依赖性,一个源文件和构建没有丝毫任何障碍.我们还可以看到快速时间现在在CRAN上,而在撰写答案时并非如此.有了这个,Windows和OS X二进制文件现在确实存在于该页面,即使您不从源代码安装,安装也将像我一样简单.