cristabel.duran at waldbau.uni-freiburg.de
2011-Jul-29 13:40 UTC
[R] coordinates from locator function in POSIXct format
Dear R-list, I have a plot with y-axis corresponding to wind measurments and x-axis with date-time information. When I want to identify some extrem wind events in the wind-curve, I use locator() to get the exact date-information, by clicking in the points in graph I?m interested in. I get in the R console the x and y coordinates. The x coordinates are not in a POSIXct format, I guess R is returning the x coordinates in a time unit as miliseconds or something else. Do anyone how to get the x coordinates directly in a POSIXct format? Thanks in advance! Cristabel. Cristabel Dur?n Rangel. PhD Student. Institute of Silviculture. Faculty of Forest and Environmental Sciences. University of Freiburg. Germany Telf: +49 (761) 203 8604 (ofc) ?Man lernt die Physiognomie einer Landschaft desto besser kennen, je genauer man die einzelnen Z?ge auffa?t, sie untereinander vergleicht und so auf dem Wege der Analysis den Quellen der Gen?sse nachgeht, die uns das gro?e Naturgem?lde bietet.? Alexander von Humboldt, 1799
Well,if you would have had a look at ?POSIXct the documentation would have given you quite a comprehensive explanation of the meaning of the values of your time vector as they are the values these POSIXct values are actually stored in (they are seconds since 1970-01-01). Additionally you would have been redirected to as.POSIXct() which converts all sorts of objects to POSIXct. I would expect this function to return your desired format if you feed it with the numeric values that locator() returned. HTH Jannis On 07/29/2011 03:40 PM, cristabel.duran at waldbau.uni-freiburg.de wrote:> Dear R-list, > > I have a plot with y-axis corresponding to wind measurments > and x-axis with date-time information. > When I want to identify some extrem wind events in the > wind-curve, I use locator() to get the exact > date-information, by clicking in the points in graph I?m > interested in. > I get in the R console the x and y coordinates. > The x coordinates are not in a POSIXct format, I guess R is > returning the x coordinates in a time unit as miliseconds > or something else. > > Do anyone how to get the x coordinates directly in a > POSIXct format? > > Thanks in advance! > Cristabel. > > > Cristabel Dur?n Rangel. PhD Student. > Institute of Silviculture. Faculty of Forest and > Environmental Sciences. University of Freiburg. > Germany > Telf: +49 (761) 203 8604 (ofc) > > ?Man lernt die Physiognomie einer Landschaft desto besser > kennen, je genauer man die einzelnen Z?ge auffa?t, sie > untereinander vergleicht und so auf dem Wege der Analysis > den Quellen der Gen?sse nachgeht, die uns das gro?e > Naturgem?lde bietet.? > Alexander von Humboldt, 1799 > > ______________________________________________ > 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.
cristabel.duran
2011-Jul-29 16:21 UTC
[R] coordinates from locator function in POSIXct format
Hi Janis, thank you for you answer. Actually already I did exactly what you said. However, when I convert the number of "seconds" from the first measurement (some day in July 2010) then a I get a date in the year 2050 which is impossible. The latest date possible is 29March2011. my value in ?seconds?: 1285038419 z <- 1285038419 as.POSIXct(z, origin="2010-07-15") "2051-04-04 03:06:59 CEST" any clue why I get this date? I thank your help, Cristabel. On 07/29/2011 04:45 PM, Jannis wrote:> Well,if you would have had a look at ?POSIXct the documentation would > have given > you quite a comprehensive explanation of the meaning of the values of > your time vector as they are the values these POSIXct values are > actually stored in (they are seconds since 1970-01-01). Additionally > you would have been redirected to as.POSIXct() which converts all > sorts of objects to POSIXct. I would expect this function to return > your desired format if you feed it with the numeric values that > locator() returned. > > > HTH > Jannis > > > > On 07/29/2011 03:40 PM, cristabel.duran at waldbau.uni-freiburg.de wrote: >> Dear R-list, >> >> I have a plot with y-axis corresponding to wind measurments >> and x-axis with date-time information. >> When I want to identify some extrem wind events in the >> wind-curve, I use locator() to get the exact >> date-information, by clicking in the points in graph I?m >> interested in. >> I get in the R console the x and y coordinates. >> The x coordinates are not in a POSIXct format, I guess R is >> returning the x coordinates in a time unit as miliseconds >> or something else. >> >> Do anyone how to get the x coordinates directly in a >> POSIXct format? >> >> Thanks in advance! >> Cristabel. >> >> >> Cristabel Dur?n Rangel. PhD Student. >> Institute of Silviculture. Faculty of Forest and >> Environmental Sciences. University of Freiburg. >> Germany >> Telf: +49 (761) 203 8604 (ofc) >> >> ?Man lernt die Physiognomie einer Landschaft desto besser >> kennen, je genauer man die einzelnen Z?ge auffa?t, sie >> untereinander vergleicht und so auf dem Wege der Analysis >> den Quellen der Gen?sse nachgeht, die uns das gro?e >> Naturgem?lde bietet.? >> Alexander von Humboldt, 1799 >> >> ______________________________________________ >> 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. >
David Winsemius
2011-Jul-29 16:32 UTC
[R] coordinates from locator function in POSIXct format
On Jul 29, 2011, at 12:21 PM, cristabel.duran wrote:> Hi Janis, > thank you for you answer. > > Actually already I did exactly what you said. However, when I > convert the number of "seconds" from the first measurement (some day > in July 2010) then a I get a date in the year 2050 which is > impossible. The latest date possible is 29March2011. > > my value in ?seconds?: 1285038419 > z <- 1285038419 > as.POSIXct(z, origin="2010-07-15") > "2051-04-04 03:06:59 CEST" > > any clue why I get this date?Because the default origin is 1970-01-01 > z <- 1285038419 > as.POSIXct(z, origin="1970-01-01") [1] "2010-09-21 04:06:59 EDT" -- David.> > I thank your help, > > Cristabel. > > > > On 07/29/2011 04:45 PM, Jannis wrote: >> Well,if you would have had a look at ?POSIXct the documentation >> would have given >> you quite a comprehensive explanation of the meaning of the values >> of your time vector as they are the values these POSIXct values are >> actually stored in (they are seconds since 1970-01-01). >> Additionally you would have been redirected to as.POSIXct() which >> converts all sorts of objects to POSIXct. I would expect this >> function to return your desired format if you feed it with the >> numeric values that locator() returned. >> >> >> HTH >> Jannis >> >> >> >> On 07/29/2011 03:40 PM, cristabel.duran at waldbau.uni-freiburg.de >> wrote: >>> Dear R-list, >>> >>> I have a plot with y-axis corresponding to wind measurments >>> and x-axis with date-time information. >>> When I want to identify some extrem wind events in the >>> wind-curve, I use locator() to get the exact >>> date-information, by clicking in the points in graph I?m >>> interested in. >>> I get in the R console the x and y coordinates. >>> The x coordinates are not in a POSIXct format, I guess R is >>> returning the x coordinates in a time unit as miliseconds >>> or something else. >>> >>> Do anyone how to get the x coordinates directly in a >>> POSIXct format? >>> >>> Thanks in advance! >>> Cristabel. >>> >>> >>> Cristabel Dur?n Rangel. PhD Student. >>> Institute of Silviculture. Faculty of Forest and >>> Environmental Sciences. University of Freiburg. >>> Germany >>> Telf: +49 (761) 203 8604 (ofc) >>> >>> ?Man lernt die Physiognomie einer Landschaft desto besser >>> kennen, je genauer man die einzelnen Z?ge auffa?t, sie >>> untereinander vergleicht und so auf dem Wege der Analysis >>> den Quellen der Gen?sse nachgeht, die uns das gro?e >>> Naturgem?lde bietet.? >>> Alexander von Humboldt, 1799 >>> >>> ______________________________________________ >>> 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. >> > > ______________________________________________ > 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.David Winsemius, MD West Hartford, CT
cristabel.duran
2011-Jul-29 16:37 UTC
[R] coordinates from locator function in POSIXct format
Thanks David and Janis, now the result is logic! have a nice WE, Cristabel. On 07/29/2011 06:32 PM, David Winsemius wrote:> > On Jul 29, 2011, at 12:21 PM, cristabel.duran wrote: > >> Hi Janis, >> thank you for you answer. >> >> Actually already I did exactly what you said. However, when I convert >> the number of "seconds" from the first measurement (some day in July >> 2010) then a I get a date in the year 2050 which is impossible. The >> latest date possible is 29March2011. >> >> my value in ?seconds?: 1285038419 >> z <- 1285038419 >> as.POSIXct(z, origin="2010-07-15") >> "2051-04-04 03:06:59 CEST" >> >> any clue why I get this date? > > Because the default origin is 1970-01-01 > > > z <- 1285038419 > > as.POSIXct(z, origin="1970-01-01") > [1] "2010-09-21 04:06:59 EDT" >
I keep the following function handy so that I can change the numeric value from POSIXct back to POSIXct; I tend to keep the numeric in matrices since it allows faster operations in some cases. This just puts the appropriate classes on the object; quicker than using as.POSIXct(z, origin="1970-01-01") unix2POSIXct <- function (time) structure(time, class = c("POSIXt", "POSIXct"))> z <- 1285038419 > as.POSIXct(z, origin="1970-01-01")[1] "2010-09-21 04:06:59 EDT"> unix2POSIXct(z)[1] "2010-09-20 23:06:59 EDT">On Fri, Jul 29, 2011 at 9:40 AM, <cristabel.duran at waldbau.uni-freiburg.de> wrote:> Dear R-list, > > I have a plot with y-axis corresponding to wind measurments > and x-axis with date-time information. > When I want to identify some extrem wind events in the > wind-curve, I use locator() to get the exact > date-information, by clicking in the points in graph I?m > interested in. > I get in the R console the x and y coordinates. > The x coordinates are not in a POSIXct format, I guess R is > returning the x coordinates in a time unit as miliseconds > or something else. > > Do anyone how to get the x coordinates directly in a > POSIXct format? > > Thanks in advance! > Cristabel. > > > Cristabel Dur?n Rangel. PhD Student. > Institute of Silviculture. Faculty of Forest and > Environmental Sciences. University of Freiburg. > Germany > Telf: +49 (761) 203 8604 (ofc) > > ?Man lernt die Physiognomie einer Landschaft desto besser > kennen, je genauer man die einzelnen Z?ge auffa?t, sie > untereinander vergleicht und so auf dem Wege der Analysis > den Quellen der Gen?sse nachgeht, die uns das gro?e > Naturgem?lde bietet.? > ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?Alexander von Humboldt, 1799 > > ______________________________________________ > 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. >-- Jim Holtman Data Munger Guru What is the problem that you are trying to solve?