Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7578303
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T17:23:59+00:00 2026-05-30T17:23:59+00:00

My Code is reading in a CSV file and converting the time stamp column

  • 0

My Code is reading in a CSV file and converting the time stamp column to the R time format

DF <- read.csv("DF.CSV",head=TRUE,sep=",")

DF[51082,1]
[1] 03/01/2012 19:29


DF[1,1]
[1] 02/24/12 00:29

It reads it in properly and the above 2 rows are displayed as expected

DF$START <- as.POSIXct(strptime(paste(DF$START),format="%m/%d/%y %H:%M"))

DF[1,1]
[1] "2012-02-24 00:29:00 GMT"

DF[51082,1]
[1] NA

After converting them to the R time format using strptime and then displaying them again some of the values have NA and there was no error message displayed or reason for it that I can figure out

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-30T17:24:00+00:00Added an answer on May 30, 2026 at 5:24 pm

    You have (at least) two different date formats,
    one in %Y (4-digit years), one in %y (2-digit years).
    Unless 12 really means 12AD, you need to try both.

    DF <- data.frame( 
      START = c(
        "03/01/2012 19:29",
        "02/24/12 00:29"
      ), 
      stringsAsFactors = FALSE 
    )
    coalesce <- function (x, ...) {
      z <- class(x)
      for (y in list(...)) {
        x <- ifelse(is.na(x), y, x)
      }
      class(x) <- z
      x
    }
    DF$START <- coalesce(
      as.POSIXct(strptime(DF$START, format="%m/%d/%y %H:%M")),
      as.POSIXct(strptime(DF$START, format="%m/%d/%Y %H:%M"))
    )
    #                 START
    # 1 2012-03-01 19:29:00
    # 2 2012-02-24 00:29:00
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

With the following file reading code: using (FileStream fileStream = new FileStream(fileName, FileMode.Open, FileAccess.Read,
i have a code. on localhost i have not problem with reading csv file
I have this code to read a csv file NSString *fileString = [NSString stringWithContentsOfFile:pathToFile
I'm using BufferedReader to read a .csv file. I have no problem reading the
I have a C# winforms that is reading a column from a csv file.
To simplify, I'm trying to read the content of a CSV-file using the ifstream
I am reading a CSV file with php. Many of the rows have a
I'm reading a csv file and insert the information in a sql 2005 database.
All, I'm reading a csv file and adding the data to a MySQL DB
The following code snippet works fine for CSV file sizes larger than 10 K.

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.