[GRASSLIST:10780] Re: [R] Length of a vector of POSIX objects reported incorrectly?
Markus Neteler
neteler at itc.it
Mon Mar 6 17:06:05 EST 2006
Jason,
try this nonsense example:
year <- 2006
year2 <- 2006
month <- 1
month2 <- 3
daysequence <- seq(ISOdate(year, month, 1),ISOdate(year2, month2, 1), "days")
str(daysequence)
curve <- sin(seq(1,length(daysequence)))
plot(daysequence,curve)
See also the as.POSIXct() function.
Markus
On Mon, Mar 06, 2006 at 04:44:45PM -0500, Jason Horn wrote:
> Gabor,
>
> Thanks for that!
>
> Now, does anyone know how to plot times on an axis of an xy plot?
>
>
>
>
> On Mar 6, 2006, at 4:20 PM, Gabor Grothendieck wrote:
>
> >POSIXlt stores its data in a 9 component structure so its
> >length is always 9. See R News 4/1 help desk article for more info.
> >To get what you are looking for try using POSIXct, not POSIXlt:
> >
> >length(as.POSIXct(times))
> >
> >
> >On 3/6/06, Jason Horn <jhorn at bu.edu> wrote:
> >>I have a vector of POSIX times/dates (called "times") that I want to
> >>plot. But I'm having trouble because R reports the length of the
> >>vector incorrectly. Can someone help me figure out what's going on
> >>here?
> >>
> >>This code....
> >>
> >>print(times)
> >>print(class(times))
> >>print(length(times))
> >>
> >>
> >>Produces this...
> >>.
> >>.
> >>.
> >>[355] "2006-03-06 18:34:00" "2006-03-06 18:32:00" "2006-03-06
> >>18:31:00"
> >>[358] "2006-03-06 18:30:00" "2006-03-06 18:29:00" "2006-03-06
> >>18:27:00"
> >>[361] "2006-03-06 18:26:00" "2006-03-06 18:25:00" "2006-03-06
> >>18:24:00"
> >>[364] "2006-03-06 18:23:00" "2006-03-06 18:21:00" "2006-03-06
> >>18:20:00"
> >>[1] "POSIXt" "POSIXlt"
> >>[1] 9
> >>
> >>Huh? As you can see there are 365 entries in the "times" vector.
> >>Why does R think there are only 9?
> >>
> >>
> >>
> >> [[alternative HTML version deleted]]
> >>
> >>______________________________________________
> >>R-help at stat.math.ethz.ch mailing list
> >>https://stat.ethz.ch/mailman/listinfo/r-help
> >>PLEASE do read the posting guide! http://www.R-project.org/posting-
> >>guide.html
> >>
> >
>
--
Markus Neteler <neteler itc it> http://mpa.itc.it
ITC-irst - Centro per la Ricerca Scientifica e Tecnologica
MPBA - Predictive Models for Biol. & Environ. Data Analysis
Via Sommarive, 18 - 38050 Povo (Trento), Italy
More information about the grass-user
mailing list