-6

I have a csv file containing various tweets. What I have to do is extract the date and time from each row, then make a histogram from it. It has to be done in r, im not sure of how to extract specifically the time and date. Ive attached a picture of how the data looks.

Adam Quek
  • 6,973
  • 1
  • 17
  • 23
Xace
  • 31
  • 1
  • 1
  • 3
  • 1
    Parse it and convert the dates to numerical format. – ABCD Oct 21 '17 at 03:43
  • How would i do that in R? What function? – Xace Oct 21 '17 at 03:54
  • 1
    Please do not use an image of data, instead provide copyable text. What have you tried? Frankly, this is a relatively basic thing within R that it has been asked and answered many many times on StackOverflow and elsewhere. It appears you have done no research and put in no effort. (If you are looking for guidance on how to better ask questions, please read [SO's minimum, verifiable examples](https://stackoverflow.com/help/mcve) as well as [reproducible questions](https://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example).) – r2evans Oct 21 '17 at 04:06
  • I wasnt able to find another question like this. What i have to do is seperate the date/time from the other text. If you know of a post like this please direct me to it. Thankyou! – Xace Oct 21 '17 at 04:34

1 Answers1

0

All of your date-times are fixed length, so you can use the substr function to extract each part of the date and time separately, then use paste to put them back together in the proper order, and then use one of the date-time parsing functions from the lubridate package to turn it into a POSIXct (date-time) object.

For example:

library(lubridate)

date <- 'Tue Feb 11 12:19:39 +0000 2014'

parsed_date <- mdy_hms(paste(substr(date, 5, 10), substr(date, 27, 30), substr(date, 12, 19)))

> parsed_date
[1] "2014-02-11 12:19:39 UTC"
danh
  • 618
  • 3
  • 7
  • Thanks for that! Just one question how would I separate the date from the other text which is in the same row? I cant really copy and paste as the file has over 10000 rows. – Xace Oct 21 '17 at 10:38