-1

I'm a beginner in working with R. In general I do have csv files which I'm gonna read with "read.csv". The files have 2 colums:

1st is date: "2013-01-01 22:20:00"

2nd is value: 0

So far I just took the var$2nd for analysis on data - but I need the date. Is it possible to read this date? And ask for the values between two dates? Or exclude values always between two times? What is the right data format, how to convert and which is standard if I just read.csv

Thank you!

Herr Student
  • 853
  • 14
  • 26
  • 1
    please read [**this**](http://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example) and edit your post. As such it is "not a real question". – Arun Mar 07 '13 at 15:41
  • Read the five vignettes (pdf documents) here: http://cran.r-project.org/web/packages/zoo/index.html – G. Grothendieck Mar 07 '13 at 15:46
  • Hi! Welcome to Stackoverflow. Please do as @Arun suggested and read the posting guide. You'll have a better chance of getting a helpful answer if you ask a specific question and show us what you've already tried. – Chris Mar 07 '13 at 16:49
  • if you use the `read_csv` function from the `readr` package columns in a format that it thinks is date - like your first column above - will be imported thusly. By default strings are imported as character not factors. – nycrefugee Feb 08 '19 at 14:20

1 Answers1

1

Say your csv file is called "foo.csv" and contains:

date, value
"2013-01-01 22:20:00", 3
"2013-01-02 12:20:00", 5

You need to tell R what kinds of things the columns are. By default, if it sees a string it will turn it into a factor, which is not what you want, so:

f <- read.csv ("foo.csv", colClasses=c("POSIXct", "integer"))

should do the trick.

Learn how read.csv works by doing:

?read.csv

and read carefully. If you do:

str (f)

you'll see that your date is POSIXct, as you asked. Do

?POSIXct

to learn how to do comparisons.

Wayne
  • 933
  • 7
  • 11