[R] simple time series plot

William Dunlap wdunlap at tibco.com
Wed Apr 18 18:28:12 CEST 2012


Try recording the data as a rectangle with 3 entries in each row
   timestamp, sensor_id, sensor_reading
You can read this into an R data.frame, sensorData, with a call to read.csv
then use
  z <- split(sensorData, sensorData$sensor_id)
to make a list of data.frames, one  for each sensor, that you can plot
from with something like
  lapply(z, function(zi)plot(zi$timestamp, zi$sensor_reading))


Bill Dunlap
Spotfire, TIBCO Software
wdunlap tibco.com

> -----Original Message-----
> From: r-help-bounces at r-project.org [mailto:r-help-bounces at r-project.org] On Behalf
> Of phibo
> Sent: Wednesday, April 18, 2012 6:26 AM
> To: r-help at r-project.org
> Subject: Re: [R] simple time series plot
> 
> Thanks for your reply!
> 
> As I write the script to export the data from the database myself, I'm free
> to sort the data (almost) at will.
> 
> I can either export to CSV in the form of
> 
> sensor1
> timestamp1, reading1, timestamp2, reading2, timestamp2, reading2...
> sensor2
> timestamp1, reading1, timestamp2, reading2, timestamp2, reading2...
> 
> OR
> 
> sensor1
> timestamp1, timestamp2, timestamp3, ...
> reading1, reading2, reading3, ...
> sensor2
> timestamp1, timestamp2, timestamp3, ...
> reading1, reading2, reading3, ...
> 
> What is easier to read into a matrix? Sorry for asking such a stupid
> question. But I just couldn't figure out how to read in the CSV into a data
> structure that I could plot afterwards.
> 
> THANKS for your help!
> 
> --
> View this message in context: http://r.789695.n4.nabble.com/simple-time-series-plot-
> tp4565579p4567706.html
> Sent from the R help mailing list archive at Nabble.com.
> 
> ______________________________________________
> R-help at r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.



More information about the R-help mailing list