•   almost 9 years ago

bigR - strptime error when trying to convert character to datetime

I am trying to convert some string data into a date and am running into the following error

Error in strptime(as.character(mydata_top6$Created_Date), "%m/%d/%Y %H:%M:%S %p") :
invalid 'x' argument

mydata_top6 is of the following type

> class(mydata_top6)
[1] "bigr.frame"
[1] "bigr"

mydata_top6$Created_Date is of the following type
[1] "bigr.vector"
[1] "bigr"

mydata_top6 has only 6 records I am using for testing. Listed below are the contents of mydata_top6$Created_Date

[1] "12/07/2013 09:18:19 PM" "12/07/2013 09:18:00 PM" "12/07/2013 09:17:32 PM" "12/07/2013 09:17:23 PM"
[5] "12/07/2013 09:17:00 PM" "12/07/2013 09:16:51 PM"

Listed below is my attempt to convert the above to a datetime format using strptime and the error is listed below the command

> strptime(mydata_top6$Created_Date, "%m/%d/%Y %H:%M:%S %p")
Error in strptime(mydata_top6$Created_Date, "%m/%d/%Y %H:%M:%S %p") :
invalid 'x' argument

I have run this using RStudio locally and connecting to the Bluemix database and also directly from the BigInsights console where you can run adhoc R scripts and both give the same error.

Anyone have had similar issues? Look forward to some responses.



  •   •   almost 9 years ago

    Hi, Vinayak.

    As you showed in your example, object "mydata_top6$Created_Date" is a bigr.vector, as opposed to a character vector. As of right now, Big R does not support date types out of the box for bigr.vector objects. If you need to do simple operations such as extracting month, day, and year, you can use our string manipulation functions, such as substr(). You can even combine as.integer() and substr() to do simple date calculations.

    If you need to do some more complicated date calculations, you can always use groupApply() / rowApply() to chunk the original bigr.frame into smaller data.frame's, and then apply strptime() to each partition. You can refer to our documentation on how to use the *apply() functions offered in Big R.


  •   •   almost 9 years ago

    Hi Oscar

    Thanks for clarifying this. I will try and work with substr, *apply() and the other alternatives you suggested.


Comments are closed.