Data type conversion

Hi everyone,

I am trying to convert datetime columns from character to the right type using below method.
adata <- "X202007_divvy_tripdata.csv"

adata$started_at <- as.POSIXct("adata$started_at, %Y-%m-%d %H:%M:%S")

however it says....

Error in as.POSIXlt.character(x, tz, ...) :
character string is not in a standard unambiguous format

I am beginer and I have been strugling with this for a few days now, and it's really frustrating....

First you need to read the data from the csv into a variable and then convert the column. Try this

adata <- read.csv("X202007_divvy_tripdata.csv")

adata$started_at <- as.POSIXct(adata$started_at, "%Y-%m-%d %H:%M:%S")

I guessed that the csv file is in the current working directory and problems may arise due to the structure of the file, so do not hesitate to come back with any problems you encounter.

It looks like your are just reading the name " "X202007_divvy_tripdata.csv" into the variable adata. You are not reading data into R.

Try

print(adata)
```
to see what I mean.

you need to do something such as
```
adata <-   read.csv("X202007_divvy_tripdata.csv")
```
Then to get an idea what is in adata
```
head(adata)
```

This topic was automatically closed 21 days after the last reply. New replies are no longer allowed.

If you have a query related to it or one of the replies, start a new topic and refer back with a link.