0

I have this csv, I read it from excel and paste the values here:

enter image description here

After being read from a csv with read.csv("My_CSV.csv"), this is the table I get:

  nobleDispoCode callEndDate
1             NS     25:17.3
2             NS     30:18.3
3             DC     40:44.3
4             NS     49:25.3
5             LM     50:05.2
6             NS     32:41.6

I tried this suggested line, but still doesn't appear the date:

readLines("My_CSV.csv", 10)
[1] "nobleDispoCode,callEndDate" "NS,7/12/18 17:25"           "NS,7/16/18 11:30"          
[4] "DC,7/16/18 11:40"           "NS,7/16/18 11:49"           "LM,7/16/18 11:50"  

My problem is that for example when I open the csv on excel the real value of "callEndDate" is "7/12/2018 5:25:17 PM", but it's read as "25:17.3"

Or for example the second row, the real value is "7/16/2018 11:30:18 AM" but it's read as "30:18.3"

Please, how can I use read.csv to parse a date time column to the right format? Any help will be greatly appreciated.

Alexis
  • 2,104
  • 2
  • 19
  • 40
  • This is a little vague, we should see a few entries of the .csv, and the code you read it in. Make a reproducible question please. Read: https://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example – jay.sf May 18 '21 at 17:30
  • Sure @jay.sf, let me past some of the cells of the csv to improve this question. – Alexis May 18 '21 at 17:40
  • What is your read.csv code? – TarJae May 18 '21 at 17:48
  • It's `read.csv("My_CSV.csv")` – Alexis May 18 '21 at 17:48
  • Try this one (I am not sure): `read.csv("My_CSV.csv", header=TRUE,format='%m/%d/%Y %H:%M:%S')` – TarJae May 18 '21 at 17:51
  • It gives me `Error in read.table(file = file, header = header, sep = sep, quote = quote, : unused argument (format = "%m/%d/%Y %H:%M:%S")` – Alexis May 18 '21 at 17:56
  • Is that really a csv file? Could you open it using a text editor instead of excel and paste the results – Onyambu May 18 '21 at 18:09
  • Sure @Onyambu, I'll paste the values to improve this question. – Alexis May 18 '21 at 18:10
  • Or try `readLines("My_CSV.csv", 10)` and paste the results into your question. We need to see what the lines look like before you use `read.csv`. Your spreadsheet is exporting the date/time column in one format and R is trying to read it using another. – dcarlson May 18 '21 at 18:58

0 Answers0