Re: [R] Date read correctly from CSV, then reformatted incorrectly by R

2021-11-23 Thread peter dalgaard
It reads other formats _if you specify them_. After all, no computer (or human) can tell whether 11/03/1959 is November 3 or March 11 without further hinting. So it tries the two ISO-like formats and leaves other cases for the user. -pd > On 20 Nov 2021, at 21:22 , Philip Monk wrote: > >

Re: [R] Date read correctly from CSV, then reformatted incorrectly by R

2021-11-22 Thread Spencer Graves
data is what you expect or alter it to be what you need. -Original Message- From: R-help On Behalf Of Philip Monk Sent: Saturday, November 20, 2021 3:28 PM To: Jeff Newmiller Cc: R-help Mailing List Subject: Re: [R] Date read correctly from CSV, then reformatted incorrectly by R Tha

Re: [R] Date read correctly from CSV, then reformatted incorrectly by R

2021-11-22 Thread Robert Knight
Richard, This response was awe-inspiring. Thank you. -Original Message- From: R-help On Behalf Of Richard O'Keefe Sent: Sunday, November 21, 2021 8:55 PM To: Philip Monk Cc: R Project Help Subject: Re: [R] Date read correctly from CSV, then reformatted incorrectly by R CSV data

Re: [R] Date read correctly from CSV, then reformatted incorrectly by R

2021-11-21 Thread Richard O'Keefe
CSV data is very often strangely laid out. For analysis, Buffer Date Reading 100... ... 100... ... and so on is more like what a data frame should be. I get quite annoyed when I finally manage to extract data from a government agency only to find that my tax money has been spent on

Re: [R] Date read correctly from CSV, then reformatted incorrectly by R

2021-11-20 Thread Avi Gross via R-help
that may also mean sanity checks along the way to see if the data is what you expect or alter it to be what you need. -Original Message- From: R-help On Behalf Of Philip Monk Sent: Saturday, November 20, 2021 3:28 PM To: Jeff Newmiller Cc: R-help Mailing List Subject: Re: [R]

Re: [R] Date read correctly from CSV, then reformatted incorrectly by R

2021-11-20 Thread Philip Monk
I am. Long day, poorly small children! P On Sat, 20 Nov 2021, 21:08 Bert Gunter, wrote: > "I also know that '/' is a special character in R (if that's the right > term) " > > That is false. I think you are confusing "/" with "\", which is R's > *escape* character. > > > cat("a/nb") > a/nb > >

Re: [R] Date read correctly from CSV, then reformatted incorrectly by R

2021-11-20 Thread Bert Gunter
"I also know that '/' is a special character in R (if that's the right term) " That is false. I think you are confusing "/" with "\", which is R's *escape* character. > cat("a/nb") a/nb > cat("a\nb") a b It gets confusing especially in regex's, because "\" is used in regex syntax also. Bert

Re: [R] Date read correctly from CSV, then reformatted incorrectly by R

2021-11-20 Thread Philip Monk
Thanks, Jeff. I follow what you're doing below, but know I need to read up on Date / POSIXct. Helpful direction! :) On Sat, 20 Nov 2021 at 18:41, Jeff Newmiller wrote: > > Beat me to it! But it is also worth noting that once converted to Date or > POSIXct, timestamps should be treated as

Re: [R] Date read correctly from CSV, then reformatted incorrectly by R

2021-11-20 Thread Philip Monk
Thanks, Andrew. I didn't realise as.Date *only* read two formats, I think I was tripped up by using %y instead of %Y, though I also know that '/' is a special character in R (if that's the right term) and as such know there is special syntax to use (which I don't know). On Sat, 20 Nov 2021 at

Re: [R] Date read correctly from CSV, then reformatted incorrectly by R

2021-11-20 Thread Jeff Newmiller
Beat me to it! But it is also worth noting that once converted to Date or POSIXct, timestamps should be treated as data without regard to how that data is displayed. When you choose to output that data you will have options as to the display format associated with the function you are using for

Re: [R] Date read correctly from CSV, then reformatted incorrectly by R

2021-11-20 Thread Andrew Simmons
The as.Date function for a character class argument will try reading in two formats (%Y-%m-%d and %Y/%m/%d). This does not look like the format you have provided, which is why it doesn't work. Try something like: x <- c("28/10/2016", "19/11/2016", "31/12/2016", "16/01/2016", "05/03/2017")

Re: [R] Date read correctly from CSV, then reformatted incorrectly by R

2021-11-20 Thread Philip Monk
Thanks Eric & Jeff. I'll certainly read up on lubridate, and the posting guide (again) (this should be in plain text). CSV extract below... Philip Buffer28/10/201619/11/201631/12/201616/01/201705/03/2017 1002.437110889-8.696748953.2392998162.443183304

Re: [R] Date read correctly from CSV, then reformatted incorrectly by R

2021-11-20 Thread Jeff Newmiller
a) R data frames are column oriented. Do not fight this. b) Data frame header names are character type. Period. Do not fight this. It sounds like you need to reshape your data after you read it in. Provide the first five lines of your CSV file (or a reasonable facsimile if your data are

Re: [R] Date read correctly from CSV, then reformatted incorrectly by R

2021-11-20 Thread Eric Berger
Hi Philip, This is a recurring question and there are many ways to do this. My preference is to use the lubridate package. library(lubridate) a <- "15/01/2010" b <- dmy(a) b # "2010-01-15" class(b) # [1] "Date" HTH, Eric On Sat, Nov 20, 2021 at 7:09 PM Philip Monk wrote: > Hello, > > Simple

[R] Date read correctly from CSV, then reformatted incorrectly by R

2021-11-20 Thread Philip Monk
Hello, Simple but infuriating problem. Reading in CSV of data using : ``` # CSV file has column headers with date of scene capture in format dd/mm/ # check.names = FALSE averts R incorrectly processing dates due to '/' data <- read.csv("C:/R_data/Bungala (b2000) julian.csv", check.names =