Hi all, I have an Nx2 array, where the first column contains the timestamps and the second column contains the corresponding data. second | ts --------| -- 14:25:00| 18 14:25:02| 14 14:25:04| 11 14:25:06| 4 14:25:08| 24 14:25:10| 13 14:25:12| 12 14:25:14| 6 14:25:16| 21 14:25:18| 37 14:25:20| 21 14:25:22| 9 Since I don't know how to do this in R yet, please allow me to show data in Matlab: In Matlab, the first column becomes: 0.600694444496185 0.600752314785495 0.600810185191222 0.600868055596948 0.600925925886258 0.600983796291985 0.601041666697711 0.601099536987022 0.601157407392748 How do I plot such data with X-axis showing the timestamps (seconds) and the Y-axis showing the data? Thanks a lot! -- View this message in context: http://r.789695.n4.nabble.com/How-do-I-plat-timestamed-in-seconds-data-in-R-tp2279519p2279519.html Sent from the R help mailing list archive at Nabble.com.
David Winsemius
2010-Jul-06 13:28 UTC
[R] How do I plat timestamed (in seconds) data in R?
On Jul 6, 2010, at 8:58 AM, LosemindL wrote:> > Hi all, > > I have an Nx2 array, where the first column contains the timestamps > and the > second column contains the corresponding data. > > second | ts > --------| -- > 14:25:00| 18 > 14:25:02| 14 > 14:25:04| 11 > 14:25:06| 4 > 14:25:08| 24 > 14:25:10| 13 > 14:25:12| 12 > 14:25:14| 6 > 14:25:16| 21 > 14:25:18| 37 > 14:25:20| 21 > 14:25:22| 9 > > Since I don't know how to do this in R yet, please allow me to show > data in > Matlab:> tz <- read.table(textConnection("second | ts + 14:25:00| 18 + 14:25:02| 14 + 14:25:04| 11 + 14:25:06| 4 + 14:25:08| 24 + 14:25:10| 13 + 14:25:12| 12 + 14:25:14| 6 + 14:25:16| 21 + 14:25:18| 37 + 14:25:20| 21 + 14:25:22| 9"), header=TRUE, sep="|")> > In Matlab, the first column becomes: > > > 0.600694444496185 > 0.600752314785495 > 0.600810185191222 > 0.600868055596948 > 0.600925925886258 > 0.600983796291985 > 0.601041666697711 > 0.601099536987022 > 0.601157407392748 > > How do I plot such data with X-axis showing the timestamps (seconds) > and the > Y-axis showing the data? >> plot (zoo(tz[,2], order.by=tz[,1]) ) -- David Winsemius, MD West Hartford, CT
Gabor Grothendieck
2010-Jul-06 13:38 UTC
[R] How do I plat timestamed (in seconds) data in R?
On Tue, Jul 6, 2010 at 8:58 AM, LosemindL <comtech.usa at gmail.com> wrote:> > Hi all, > > I have an Nx2 array, where the first column contains the timestamps and the > second column contains the corresponding data. > > second ?| ts > --------| -- > 14:25:00| 18 > 14:25:02| 14 > 14:25:04| 11 > 14:25:06| 4 > 14:25:08| 24 > 14:25:10| 13 > 14:25:12| 12 > 14:25:14| 6 > 14:25:16| 21 > 14:25:18| 37 > 14:25:20| 21 > 14:25:22| 9 > > How do I plot such data with X-axis showing the timestamps (seconds) and the > Y-axis showing the data? >Try this (and see the three vignettes, i.e. pdf documents, that come with zoo, the zoo help files and the article on dates and times in R News 4/1): Lines <- "second | ts 14:25:00| 18 14:25:02| 14 14:25:04| 11 14:25:06| 4 14:25:08| 24 14:25:10| 13 14:25:12| 12 14:25:14| 6 14:25:16| 21 14:25:18| 37 14:25:20| 21 14:25:22| 9" library(zoo) library(chron) z <- read.zoo(textConnection(Lines), header = TRUE, sep = "|", FUN = times) plot(z, type = "o") # overplot points and lines