Converting factor date time columns into POSIXct in R
NickName:Hanna Ask DateTime:2019-01-22T22:42:52

Converting factor date time columns into POSIXct in R

I have another problem. I have a date time column in a data frame, which when i upload it comes as factor and I want it to be POSIXct

str(ida$DATA_TRAMA)
 Factor w/ 1122932 levels "1-1-2010 00:00:51",..: 629101 629120 629128 629132 629139 629149

And i want it to be POSIXct (%Y-%m-%d %H:%M:%S) format. I already tried all of these methods but none of them seem to work. Whichever i apply it gets NA values.

ida$DATA_TRAMA<- as.POSIXct(ida$DATA_TRAMA,format='%d/%m/%Y %H:%M:%S')

ida$DATA_TRAMA<- as.POSIXct(as.character(ida$DATA_TRAMA), format = "%d/%m/%Y %H:%M") 
ida$DATA_TRAMA <-format(ida$DATA_TRAMA, "%Y-%m-%d")
ida$DATA_TRAMA <- as.POSIXct(ida$DATA_TRAMA, format = '%Y-%m-%d:%H:%M:%S')

ida$DATA_TRAMA <- as.POSIXlt(as.character(ida$DATA_TRAMA), format="%m/%d/%Y %H:%M:%S")

ida$DATA_TRAMA <- strptime(ida$DATA_TRAMA,"%Y-%m-%d %H:%M:%S")

Do you know how to do it?

Copyright Notice:Content Author:「Hanna」,Reproduced under the CC 4.0 BY-SA copyright license with a link to the original source and this disclaimer.
Link to original article:https://stackoverflow.com/questions/54310692/converting-factor-date-time-columns-into-posixct-in-r

More about “Converting factor date time columns into POSIXct in R” related questions

R - converting date and time fields to POSIXct with HHMMSS format

I have a data file which has three columns thus: 20010101 000000 0.833 20010101 000500 0.814 20010101 001000 0.794 20010101 001500 0.772 ... As is fairly clear to human eyes, the first two ar...

Show Detail

Converting factor date time columns into POSIXct in R

I have another problem. I have a date time column in a data frame, which when i upload it comes as factor and I want it to be POSIXct str(ida$DATA_TRAMA) Factor w/ 1122932 levels "1-1-2010 00:00:...

Show Detail

Combine a date and a factor to make a POSIXct date time and strip into columns

I have a POSIXct object and I want to combine only the date from that object with the time that is stored in a factor object. here is the code: originalDate&lt;- as.POSIXct("2014-10-27 13:39:01.8...

Show Detail

Combine date as integer and time as factor to POSIXct in R

I know this has been asked several times and I looked at the questions and followed the suggestions. However, I couldn't solve this one. The datetime.csv can be found on https://www.dropbox.com/s/

Show Detail

Converting date column from factor into posixct makes my dataframe have a length and size of zero

I am trying to figure out a problem I'm having with converting a date column from factor to posixct. I have a script which I have run several times with no issue. When I read my .csv file, it has a...

Show Detail

Converting factor to Date/time in R?

I am trying to convert a column in R that is a factor to a date time. When I use lubridate, my values are changed to POSIXCt, but the times are dropped. Is there a solution that I am not seeing? Im...

Show Detail

Converting factor to date and time in R

I have two columns in my dataset that are factors and are on the form "10may2010 5p.m. to 7p.m." I want R to read the above factor as a date/ time object. Next, I would like to know if the date...

Show Detail

Converting character to POSIXct in R Markdown is Making Me Sad

I'm learning to use R as part of a certificate program and I've been trying to compile a report from a practice project in R Markdown and getting my date-times back to POSIXct rather than being

Show Detail

Converting dates with R using as.POSIXct

I’m working with dates and R and I’m converting dates using the as.POSIXct function. I have a pretty good understanding of how to convert dates by just looking at the ?strptime docs. However I’m co...

Show Detail

Extract Time and date from POSIXct

I have a vector with DateTime character ("2014-04-17 23:33:00") and want to make a matrix with date and time as my columns. This is my code: dat &lt;- as.POSIXct(dates) date = data.frame( ...

Show Detail