R-Studio. Error after installing lubridate: could

2019-08-21 08:09发布

问题:

First I installed lubridate:

install.packages("lubridate") Installing package into ‘C:/Users/Llorenc  Piera/AppData/Roaming/SPB_Data/R/win-library/3.4’ (as ‘lib’ is unspecified) trying URL  'https://cran.rstudio.com/bin/windows/contrib/3.4/lubridate_1.7.4.zip' Content type 'application/zip' length 1365606 bytes (1.3 MB) downloaded 1.3 MB

package ‘lubridate’ successfully unpacked and MD5 sums checked

Warning in install.packages : cannot remove prior installation of package ‘lubridate’

Then I try to run:

dmy_hm('01-01-2012 12:12')

and get:

Error in dmy_hm("01-01-2012 12:12") : could not find function "dmy_hm"

This used to work in my computer a few weeks ago, but not any more.

Howerver, if I run:

lubridate::dmy_hm('01-01-2012 12:12')

I get

[1] "2012-01-01 12:12:00 UTC"

But using 'lubridate::' is not good for me since it does not work inside other functions

回答1:

The

lubridate::dmy_hm('01-01-2012 12:12') 

means: run the dmy_hm function from lubridate package. but you need to have the library(lubridate)

if you are using Rstudio, then follow these steps:

Use easier options to install a package. Such as Packages -> Intall -> name of package

Then in the package tab, and search for the lubridate and make sure it is checked.

The below image shows how to do it.



标签: r lubridate