[R] datetime and date
Hi, I have the following issue. The dataframe df has a column (Date1) supposed to be a date but read as a factor. There are two types of values in the same column Date1 Type 1 are datetime like 5/23/2008 0:00:00 Type 2 have no time like 1/10/13. When I apply the following to the date column df$Date1-as.POSIXct(as.character(df$Date1, format = %d/%m/%Y)) For type 1 I got the expected result: 2008-05-23 For type 2 I got NA. I have searched but could not solve it. Please help. Thanks, Yolande [[alternative HTML version deleted]] __ R-help@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.
Re: [R] datetime and date
Hi Jim, I got an error df$Date2- + as.POSIXct(as.character(df$Date1, format = %m/%d/%Y %H:%M:%S)) Error in as.POSIXlt.character(x, tz, ...) : character string is not in a standard unambiguous format On Sun, Feb 2, 2014 at 9:08 PM, Jim Lemon j...@bitwrit.com.au wrote: On 02/03/2014 12:53 PM, Yolande Tra wrote: Hi, I have the following issue. The dataframe df has a column (Date1) supposed to be a date but read as a factor. There are two types of values in the same column Date1 Type 1 are datetime like 5/23/2008 0:00:00 Type 2 have no time like 1/10/13. When I apply the following to the date column df$Date1-as.POSIXct(as.character(df$Date1, format = %d/%m/%Y)) For type 1 I got the expected result: 2008-05-23 For type 2 I got NA. I have searched but could not solve it. Please help. Hi Yolande, Try this: # first get the dates with times df$Date1- as.POSIXct(as.character(df$Date1, format = %m/%d/%Y %H:%M:%S)) # then fill in the ones without times df$Date1[nchar(df$Date1) 10]- as.POSIXct(as.character(df$Date1, format = %m/%d/%y)) Notice that I think you got the month/day order wrong, if your first type is correct. Jim [[alternative HTML version deleted]] __ R-help@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.
Re: [R] datetime and date
Thank you Jeff. I had to go back to excel and format the column from there. Thank you everyone, Yolande On Sun, Feb 2, 2014 at 9:51 PM, Yolande Tra yolande@gmail.com wrote: Hi Jim, I got an error df$Date2- + as.POSIXct(as.character(df$Date1, format = %m/%d/%Y %H:%M:%S)) Error in as.POSIXlt.character(x, tz, ...) : character string is not in a standard unambiguous format On Sun, Feb 2, 2014 at 9:08 PM, Jim Lemon j...@bitwrit.com.au wrote: On 02/03/2014 12:53 PM, Yolande Tra wrote: Hi, I have the following issue. The dataframe df has a column (Date1) supposed to be a date but read as a factor. There are two types of values in the same column Date1 Type 1 are datetime like 5/23/2008 0:00:00 Type 2 have no time like 1/10/13. When I apply the following to the date column df$Date1-as.POSIXct(as.character(df$Date1, format = %d/%m/%Y)) For type 1 I got the expected result: 2008-05-23 For type 2 I got NA. I have searched but could not solve it. Please help. Hi Yolande, Try this: # first get the dates with times df$Date1- as.POSIXct(as.character(df$Date1, format = %m/%d/%Y %H:%M:%S)) # then fill in the ones without times df$Date1[nchar(df$Date1) 10]- as.POSIXct(as.character(df$Date1, format = %m/%d/%y)) Notice that I think you got the month/day order wrong, if your first type is correct. Jim [[alternative HTML version deleted]] __ R-help@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] replacement has length zero. In addition: Warning message: In max(i) : no non-missing arguments to max; returning -Inf
Hi, Here is my data, the first 10 rows u=regCond_all[1:10,] dput(u) structure(c(999, 999, 999, 999, 999, 999, 999, 999, 999, 999, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 1.9, 2, 1.97, 1.99, 1.83, 1.78, 1.6, 1.52, 1.52, 1.36, 10.53, 9.88, 9.88, 10.53, 10.53, 10.53, 5.26, 9.88, 10.53, 10.53, 5.4, 5.57, 5.46, 5.34, 5.5, 5.59, 5.62, 5.76, 6.23, 6.19, 295, 294, 292, 294, 283, 288, 305, 287, 294, 295, , , , , , , , , , , 999, 999, 999, 999, 999, 999, 999, 999, 999, 999, 12.7, 12.5, 12.3, 12.6, 12.6, 12.5, 12.5, 12.5, 12.7, 12.7, 999, 999, 999, 999, 999, 999, 999, 999, 999, 999, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99), class = c(xts, zoo), .indexCLASS = c(POSIXct, POSIXt), .indexTZ = , tclass = c(POSIXct, POSIXt), tzone = , index = structure(c(1217564520, 1217566320, 1217568120, 1217569980, 1217571720, 1217573520, 1217575320, 1217577120, 1217578920, 1217580720), tzone = , tclass = c(POSIXct, POSIXt)), .Dim = c(10L, 13L), .Dimnames = list(NULL, c(WDIR, WSPD, GST, WVHT, DPD, APD, MWD, PRES, ATMP, WTMP, DEWP, VIS, TIDE))) I tried to copy some fields from this data to another data. I got error. Could you please help? Thanks. diveCond - data.frame(matrix(0, nrow=97, ncol=17)) names(diveCond) - c(dive_id, timestamp, visability, r_wvht, r_dpd, r_apt, r_mwd, r_wtmp, l_salinity, l_o2, l_hs, l_tp, l_wdir, l_along, l_cross, l_mab, l_depth) dive_id - 0 for(i in 1:dim(diveCond)[1]){ thisStamp - as.POSIXct(strptime(diveCond$timestamp[i], %Y-%m-%d %H:%M:%S)) ind - which.min( abs(index(regCond_all) - thisStamp )) diveCond$r_wvht[i] - regCond_all$WVHT[ind] diveCond$r_dpd[i] - regCond_all$DPD[ind] diveCond$r_apt[i] - regCond_all$APD[ind] diveCond$r_mwd[i] - regCond_all$MWD[ind] diveCond$r_wtmp[i] - regCond_all$WTMP[ind] } Error in diveCond$r_wvht[i] - regCond_all$WVHT[ind] : replacement has length zero In addition: Warning message: In max(i) : no non-missing arguments to max; returning -Inf If you could explain the error that would help prevent future errors. Thanks, Y [[alternative HTML version deleted]] __ R-help@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.
Re: [R] replacement has length zero. In addition: Warning message: In max(i) : no non-missing arguments to max; returning -Inf
After replacing it to u for(i in 1:dim(diveCond)[1]){ + thisStamp - as.POSIXct(strptime(diveCond$timestamp[i], %Y-%m-%d %H:%M:%S)) + ind - which.min( abs(index(u) - thisStamp )) + diveCond$r_wvht[i]- u$WVHT[ind] + diveCond$r_dpd[i]- u$DPD[ind] + diveCond$r_apt[i] - u$APD[ind] + diveCond$r_mwd[i] - u$MWD[ind] + diveCond$r_wtmp[i] - u$WTMP[ind] + } Error in diveCond$r_wvht[i] - u$WVHT[ind] : replacement has length zero In addition: Warning message: In max(i) : no non-missing arguments to max; returning -Inf Y On Fri, Aug 3, 2012 at 4:12 PM, arun smartpink...@yahoo.com wrote: Hi, Here, I am getting the error: for(i in 1:dim(diveCond)[1]){ thisStamp - as.POSIXct(strptime(diveCond$timestamp[i], %Y-%m-%d %H:%M:%S)) ind - which.min( abs(index(regCond_all) - thisStamp )) diveCond$r_wvht[i] - regCond_all$WVHT[ind] diveCond$r_dpd[i] - regCond_all$DPD[ind] diveCond$r_apt[i] - regCond_all$APD[ind] diveCond$r_mwd[i] - regCond_all$MWD[ind] diveCond$r_wtmp[i] - regCond_all$WTMP[ind] } Error in index(regCond_all) : object 'regCond_all' not found u=regCond_all[1:10,] Error: object 'regCond_all' not found From a glance, I guess you should have posted with u in place of regCond_all for the loop. A.K. - Original Message - From: Yolande Tra yolande@gmail.com To: R help r-help@r-project.org Cc: Sent: Friday, August 3, 2012 3:49 PM Subject: [R] replacement has length zero. In addition: Warning message: In max(i) : no non-missing arguments to max; returning -Inf Hi, Here is my data, the first 10 rows u=regCond_all[1:10,] dput(u) structure(c(999, 999, 999, 999, 999, 999, 999, 999, 999, 999, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 1.9, 2, 1.97, 1.99, 1.83, 1.78, 1.6, 1.52, 1.52, 1.36, 10.53, 9.88, 9.88, 10.53, 10.53, 10.53, 5.26, 9.88, 10.53, 10.53, 5.4, 5.57, 5.46, 5.34, 5.5, 5.59, 5.62, 5.76, 6.23, 6.19, 295, 294, 292, 294, 283, 288, 305, 287, 294, 295, , , , , , , , , , , 999, 999, 999, 999, 999, 999, 999, 999, 999, 999, 12.7, 12.5, 12.3, 12.6, 12.6, 12.5, 12.5, 12.5, 12.7, 12.7, 999, 999, 999, 999, 999, 999, 999, 999, 999, 999, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99), class = c(xts, zoo), .indexCLASS = c(POSIXct, POSIXt), .indexTZ = , tclass = c(POSIXct, POSIXt), tzone = , index = structure(c(1217564520, 1217566320, 1217568120, 1217569980, 1217571720, 1217573520, 1217575320, 1217577120, 1217578920, 1217580720), tzone = , tclass = c(POSIXct, POSIXt)), .Dim = c(10L, 13L), .Dimnames = list(NULL, c(WDIR, WSPD, GST, WVHT, DPD, APD, MWD, PRES, ATMP, WTMP, DEWP, VIS, TIDE))) I tried to copy some fields from this data to another data. I got error. Could you please help? Thanks. diveCond - data.frame(matrix(0, nrow=97, ncol=17)) names(diveCond) - c(dive_id, timestamp, visability, r_wvht, r_dpd, r_apt, r_mwd, r_wtmp, l_salinity, l_o2, l_hs, l_tp, l_wdir, l_along, l_cross, l_mab, l_depth) dive_id - 0 for(i in 1:dim(diveCond)[1]){ thisStamp - as.POSIXct(strptime(diveCond$timestamp[i], %Y-%m-%d %H:%M:%S)) ind - which.min( abs(index(regCond_all) - thisStamp )) diveCond$r_wvht[i] - regCond_all$WVHT[ind] diveCond$r_dpd[i] - regCond_all$DPD[ind] diveCond$r_apt[i] - regCond_all$APD[ind] diveCond$r_mwd[i] - regCond_all$MWD[ind] diveCond$r_wtmp[i] - regCond_all$WTMP[ind] } Error in diveCond$r_wvht[i] - regCond_all$WVHT[ind] : replacement has length zero In addition: Warning message: In max(i) : no non-missing arguments to max; returning -Inf If you could explain the error that would help prevent future errors. Thanks, Y [[alternative HTML version deleted]] __ R-help@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.htmlhttp://www.r-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. [[alternative HTML version deleted]] __ R-help@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.
Re: [R] replacement has length zero. In addition: Warning message: In max(i) : no non-missing arguments to max; returning -Inf
i=10 thisStamp - as.POSIXct(strptime(diveCond$timestamp[i], %Y-%m-%d %H:%M:%S)) thisStamp [1] 2008-08-11 14:12:00 EDT ind - which.min( abs(index(regCond_all) - thisStamp )) ind [1] 506 diveCond$r_wvht[i] [1] 0 regCond_all$WVHT[ind] WVHT 2008-08-11 14:22:00 1.35 It did not to diveCond. Y On Fri, Aug 3, 2012 at 5:10 PM, Sarah Goslee sarah.gos...@gmail.com wrote: This runs, so there must be something else going on that you haven't told us about. diveCond - structure(list(dive_id = c(1, 2, 3, 4, 5, 6, 7, 8, 9, 10), timestamp = c(2008-08-06 08:49:00, 2008-08-06 10:03:00, 2008-08-06 10:25:00, 2008-08-08 09:42:00, 2008-08-08 10:53:00, 2008-08-08 12:42:00, 2008-08-11 10:10:00, 2008-08-11 11:01:00, 2008-08-11 11:16:00, 2008-08-11 14:12:00 ), visability = c(3.5, 3.5, NA, 4, NA, NA, NA, 7, 6.5, NA), r_wvht = c(0, 0, 0, 0, 0, 0, 0, 0, 0, 0), r_dpd = c(0, 0, 0, 0, 0, 0, 0, 0, 0, 0), r_apt = c(0, 0, 0, 0, 0, 0, 0, 0, 0, 0), r_mwd = c(0, 0, 0, 0, 0, 0, 0, 0, 0, 0), r_wtmp = c(0, 0, 0, 0, 0, 0, 0, 0, 0, 0), l_salinity = c(0, 0, 0, 0, 0, 0, 0, 0, 0, 0), l_o2 = c(0, 0, 0, 0, 0, 0, 0, 0, 0, 0), l_hs = c(0, 0, 0, 0, 0, 0, 0, 0, 0, 0), l_tp = c(0, 0, 0, 0, 0, 0, 0, 0, 0, 0), l_wdir = c(0, 0, 0, 0, 0, 0, 0, 0, 0, 0), l_along = c(0, 0, 0, 0, 0, 0, 0, 0, 0, 0), l_cross = c(0, 0, 0, 0, 0, 0, 0, 0, 0, 0), l_mab = c(0, 0, 0, 0, 0, 0, 0, 0, 0, 0), l_depth = c(0, 0, 0, 0, 0, 0, 0, 0, 0, 0)), .Names = c(dive_id, timestamp, visability, r_wvht, r_dpd, r_apt, r_mwd, r_wtmp, l_salinity, l_o2, l_hs, l_tp, l_wdir, l_along, l_cross, l_mab, l_depth), row.names = c(NA, 10L), class = data.frame) regCond_all - structure(c(999, 999, 999, 999, 999, 999, 999, 999, 999, 999, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 1.9, 2, 1.97, 1.99, 1.83, 1.78, 1.6, 1.52, 1.52, 1.36, 10.53, 9.88, 9.88, 10.53, 10.53, 10.53, 5.26, 9.88, 10.53, 10.53, 5.4, 5.57, 5.46, 5.34, 5.5, 5.59, 5.62, 5.76, 6.23, 6.19, 295, 294, 292, 294, 283, 288, 305, 287, 294, 295, , , , , , , , , , , 999, 999, 999, 999, 999, 999, 999, 999, 999, 999, 12.7, 12.5, 12.3, 12.6, 12.6, 12.5, 12.5, 12.5, 12.7, 12.7, 999, 999, 999, 999, 999, 999, 999, 999, 999, 999, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99), class = c(xts, zoo), .indexCLASS = c(POSIXct, POSIXt), .indexTZ = , tclass = c(POSIXct, POSIXt), tzone = , index = structure(c(1217564520, 1217566320, 1217568120, 1217569980, 1217571720, 1217573520, 1217575320, 1217577120, 1217578920, 1217580720), tzone = , tclass = c(POSIXct, POSIXt)), .Dim = c(10L, 13L), .Dimnames = list(NULL, c(WDIR, WSPD, GST, WVHT, DPD, APD, MWD, PRES, ATMP, WTMP, DEWP, VIS, TIDE))) for(i in 1:dim(diveCond)[1]){ thisStamp - as.POSIXct(strptime(diveCond$timestamp[i], %Y-%m-%d %H:%M:%S)) ind - which.min( abs(index(regCond_all) - thisStamp )) diveCond$r_wvht[i]- regCond_all$WVHT[ind] diveCond$r_dpd[i]- regCond_all$DPD[ind] diveCond$r_apt[i] - regCond_all$APD[ind] diveCond$r_mwd[i] - regCond_all$MWD[ind] diveCond$r_wtmp[i] - regCond_all$WTMP[ind] } # this also runs i - 10 thisStamp - as.POSIXct(strptime(diveCond$timestamp[i], %Y-%m-%d %H:%M:%S)) ind - which.min( abs(index(regCond_all) - thisStamp )) diveCond$r_wvht[i]- regCond_all$WVHT[ind] diveCond$r_dpd[i]- regCond_all$DPD[ind] diveCond$r_apt[i] - regCond_all$APD[ind] diveCond$r_mwd[i] - regCond_all$MWD[ind] diveCond$r_wtmp[i] - regCond_all$WTMP[ind] What happens when you do: i - 10 thisStamp - as.POSIXct(strptime(diveCond$timestamp[i], %Y-%m-%d %H:%M:%S)) thisStamp ind - which.min( abs(index(regCond_all) - thisStamp )) ind diveCond$r_wvht[i] regCond_all$WVHT[ind] On Fri, Aug 3, 2012 at 5:02 PM, Yolande Tra yolande@gmail.com wrote: dput(head(diveCond, 10)) structure(list(dive_id = c(1, 2, 3, 4, 5, 6, 7, 8, 9, 10), timestamp = c(2008-08-06 08:49:00, 2008-08-06 10:03:00, 2008-08-06 10:25:00, 2008-08-08 09:42:00, 2008-08-08 10:53:00, 2008-08-08 12:42:00, 2008-08-11 10:10:00, 2008-08-11 11:01:00, 2008-08-11 11:16:00, 2008-08-11 14:12:00 ), visability = c(3.5, 3.5, NA, 4, NA, NA, NA, 7, 6.5, NA), r_wvht = c(0, 0, 0, 0, 0, 0, 0, 0, 0, 0), r_dpd = c(0, 0, 0, 0, 0, 0, 0, 0, 0, 0), r_apt = c(0, 0, 0, 0, 0, 0, 0, 0, 0, 0), r_mwd = c(0, 0, 0, 0, 0, 0, 0, 0, 0, 0), r_wtmp = c(0, 0, 0, 0, 0, 0, 0, 0, 0, 0), l_salinity = c(0, 0, 0, 0, 0, 0, 0, 0, 0, 0), l_o2 = c(0, 0, 0, 0, 0, 0, 0, 0, 0, 0), l_hs = c(0, 0, 0, 0, 0, 0, 0, 0, 0, 0), l_tp = c(0, 0, 0, 0, 0, 0, 0, 0, 0, 0), l_wdir = c(0, 0, 0, 0, 0, 0, 0, 0, 0, 0), l_along = c(0, 0, 0, 0, 0, 0, 0, 0, 0, 0), l_cross = c(0, 0, 0, 0, 0, 0, 0, 0, 0, 0), l_mab = c(0, 0, 0, 0, 0, 0, 0, 0, 0, 0), l_depth = c(0, 0, 0, 0, 0, 0, 0, 0, 0, 0)), .Names = c(dive_id, timestamp, visability, r_wvht, r_dpd, r_apt, r_mwd, r_wtmp, l_salinity, l_o2, l_hs, l_tp, l_wdir, l_along, l_cross, l_mab, l_depth), row.names = c(NA, 10L
[R] add text to a plot, create character labels
Hi, I was trying to run the following, where the labels on the x axis are dates and need to be converted to characters. It did not work. Any help would be appreciated. Thanks. text(axTicks(1),par(usr)[3]-2,srt=45,adj=1,labels=as.character(c(2008-01-08,2008-08-10,2008-08-22,2008-09-03, 2008-09-15)), xpd=T, cex=0.8) Error: unexpected numeric constant in text(axTicks(1),par(usr)[3]-2,srt=45,adj=1,labels=as.character(c(2008 Yolande [[alternative HTML version deleted]] __ R-help@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.
Re: [R] add text to a plot, create character labels
Thanks for the tip for future typos. Yolande On Wed, Aug 1, 2012 at 1:38 PM, David Winsemius dwinsem...@comcast.netwrote: On Aug 1, 2012, at 9:04 AM, Yolande Tra wrote: Hi, I was trying to run the following, where the labels on the x axis are dates and need to be converted to characters. It did not work. Any help would be appreciated. Thanks. text(axTicks(1),par(usr)[3] There is an unmatched quote in the par() call. Adding spaces after commas in argument lists may help you see these sorts of errors in the future. -2,srt=45,adj=1,labels=as.**character(c(2008-01-08,** 2008-08-10,2008-08-22,**2008-09-03, 2008-09-15)), xpd=T, cex=0.8) Error: unexpected numeric constant in text(axTicks(1),par(usr)[3]-**2,srt=45,adj=1,labels=as.** character(c(2008 Yolande -- David Winsemius, MD Alameda, CA, USA [[alternative HTML version deleted]] __ R-help@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] time series line plot: Error in plot.window(...) : invalid 'xlim' value
Hello, This should be pretty simple but I cannot get it right. Please point to the right code. Thanks. last - read.csv(file.path(dataDir,plot1.csv), as.is=T,stringsAsFactors = FALSE) last dater_wvht 18/6/2008 0.977 28/8/2008 0.773 3 8/11/2008 1.483 4 8/13/2008 1.577 5 8/14/2008 1.390 6 8/18/2008 0.780 7 8/20/2008 0.838 8 8/27/2008 1.770 9 8/28/2008 1.295 10 8/31/2008 2.410 11 9/2/2008 1.317 12 9/3/2008 1.3075000 13 9/4/2008 1.390 14 9/5/2008 1.633 15 9/8/2008 1.2416667 16 9/11/2008 1.395 17 10/12/2009 0.863 18 10/14/2009 2.790 19 10/19/2009 1.0325000 20 10/21/2009 1.965 21 10/26/2009 1.780 22 10/29/2009 1.567 23 10/30/2009 1.050 24 11/2/2009 1.463 25 11/3/2009 1.240 26 11/4/2009 1.0075000 27 11/11/2009 1.605 28 11/13/2009 1.8475000 x-as.vector(last$date) x [1] 8/6/2008 8/8/2008 8/11/2008 8/13/2008 8/14/2008 8/18/2008 8/20/2008 8/27/2008 [9] 8/28/2008 8/31/2008 9/2/2008 9/3/2008 9/4/2008 9/5/2008 9/8/2008 9/11/2008 [17] 10/12/2009 10/14/2009 10/19/2009 10/21/2009 10/26/2009 10/29/2009 10/30/2009 11/2/2009 [25] 11/3/2009 11/4/2009 11/11/2009 11/13/2009 y-as.vector(last$r_wvht) y [1] 0.977 0.773 1.483 1.577 1.390 0.780 0.838 1.770 1.295 2.410 [11] 1.317 1.3075000 1.390 1.633 1.2416667 1.395 0.863 2.790 1.0325000 1.965 [21] 1.780 1.567 1.050 1.463 1.240 1.0075000 1.605 1.8475000 plot(x,y) Error in plot.window(...) : need finite 'xlim' values In addition: Warning messages: 1: In xy.coords(x, y, xlabel, ylabel, log) : NAs introduced by coercion 2: In min(x) : no non-missing arguments to min; returning Inf 3: In max(x) : no non-missing arguments to max; returning -Inf plot(x,y,xlim=c(6/8/2008,11/13/2009)) Error in plot.window(...) : invalid 'xlim' value Y [[alternative HTML version deleted]] __ R-help@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.
Re: [R] time series line plot: Error in plot.window(...) : invalid 'xlim' value
Thank you everyone for the attempt to solve the problem It is an irregular series and insert NAs when a date is missing library(zoo) z - zoo(last$r_wvht, order.by=last$date) plot(z) Error in plot.window(...) : need finite 'xlim' values In addition: Warning messages: 1: In xy.coords(x, y, xlabel, ylabel, log) : NAs introduced by coercion 2: In min(x) : no non-missing arguments to min; returning Inf 3: In max(x) : no non-missing arguments to max; returning -Inf I have also tried z - read.zoo(plot1.csv, header = TRUE, sep = ,, format = %m/%d/%Y) plot(z) The plot does not look good. It does not display the individual dates. Y Y On Tue, Jul 31, 2012 at 1:33 PM, Rui Barradas ruipbarra...@sapo.pt wrote: Hello, Sorry, I forgot the time series part of your question. You could use instead one of # 1. type = l gives a line plot plot(r_wvht ~ date, data = last, type=l) # 2. use time series object plot library(zoo) z - zoo(last$r_wvht, order.by=last$date) plot(z) Rui Barradas Em 31-07-2012 18:27, Rui Barradas escreveu: Hello, You could use dput(), it's not your first post... last - structure(list(date = c(8/6/2008, 8/8/2008, 8/11/2008, 8/13/2008, 8/14/2008, 8/18/2008, 8/20/2008, 8/27/2008, 8/28/2008, 8/31/2008, 9/2/2008, 9/3/2008, 9/4/2008, 9/5/2008, 9/8/2008, 9/11/2008, 10/12/2009, 10/14/2009, 10/19/2009, 10/21/2009, 10/26/2009, 10/29/2009, 10/30/2009, 11/2/2009, 11/3/2009, 11/4/2009, 11/11/2009, 11/13/2009 ), r_wvht = c(0.977, 0.773, 1.483, 1.577, 1.39, 0.78, 0.838, 1.77, 1.295, 2.41, 1.317, 1.3075, 1.39, 1.633, 1.2416667, 1.395, 0.863, 2.79, 1.0325, 1.965, 1.78, 1.567, 1.05, 1.463, 1.24, 1.0075, 1.605, 1.8475 )), .Names = c(date, r_wvht), class = data.frame, row.names = c(1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28)) last$date - as.Date(last$date, format=%m/%d/%Y) plot(r_wvht ~ date, data = last) (You were forgetting that last$date was a character vector, not class Date.) Hope this helps, Rui Barradas Em 31-07-2012 18:02, Yolande Tra escreveu: Hello, This should be pretty simple but I cannot get it right. Please point to the right code. Thanks. last - read.csv(file.path(dataDir,**plot1.csv), as.is =T,stringsAsFactors = FALSE) last dater_wvht 18/6/2008 0.977 28/8/2008 0.773 3 8/11/2008 1.483 4 8/13/2008 1.577 5 8/14/2008 1.390 6 8/18/2008 0.780 7 8/20/2008 0.838 8 8/27/2008 1.770 9 8/28/2008 1.295 10 8/31/2008 2.410 11 9/2/2008 1.317 12 9/3/2008 1.3075000 13 9/4/2008 1.390 14 9/5/2008 1.633 15 9/8/2008 1.2416667 16 9/11/2008 1.395 17 10/12/2009 0.863 18 10/14/2009 2.790 19 10/19/2009 1.0325000 20 10/21/2009 1.965 21 10/26/2009 1.780 22 10/29/2009 1.567 23 10/30/2009 1.050 24 11/2/2009 1.463 25 11/3/2009 1.240 26 11/4/2009 1.0075000 27 11/11/2009 1.605 28 11/13/2009 1.8475000 x-as.vector(last$date) x [1] 8/6/2008 8/8/2008 8/11/2008 8/13/2008 8/14/2008 8/18/2008 8/20/2008 8/27/2008 [9] 8/28/2008 8/31/2008 9/2/2008 9/3/2008 9/4/2008 9/5/2008 9/8/2008 9/11/2008 [17] 10/12/2009 10/14/2009 10/19/2009 10/21/2009 10/26/2009 10/29/2009 10/30/2009 11/2/2009 [25] 11/3/2009 11/4/2009 11/11/2009 11/13/2009 y-as.vector(last$r_wvht) y [1] 0.977 0.773 1.483 1.577 1.390 0.780 0.838 1.770 1.295 2.410 [11] 1.317 1.3075000 1.390 1.633 1.2416667 1.395 0.863 2.790 1.0325000 1.965 [21] 1.780 1.567 1.050 1.463 1.240 1.0075000 1.605 1.8475000 plot(x,y) Error in plot.window(...) : need finite 'xlim' values In addition: Warning messages: 1: In xy.coords(x, y, xlabel, ylabel, log) : NAs introduced by coercion 2: In min(x) : no non-missing arguments to min; returning Inf 3: In max(x) : no non-missing arguments to max; returning -Inf plot(x,y,xlim=c(6/8/2008,**11/13/2009)) Error in plot.window(...) : invalid 'xlim' value Y [[alternative HTML version deleted]] __** R-help@r-project.org mailing list https://stat.ethz.ch/mailman/**listinfo/r-helphttps://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/** posting-guide.html http://www.r-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. __** R-help@r-project.org mailing list https://stat.ethz.ch/mailman/**listinfo/r-helphttps://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/** posting-guide.html http://www.r-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. [[alternative HTML version deleted
Re: [R] time series line plot: Error in plot.window(...) : invalid 'xlim' value
Thanks. This is an irregular time series. The line plot does not look good because of the gap between 9/11/2008 and 10/12/2009. I think two plots would be better. How would you include the date on the x-axis. Right now it only gives one tick mark, 2009. Yolande On Tue, Jul 31, 2012 at 2:01 PM, Rui Barradas ruipbarra...@sapo.pt wrote: Hello, It only gives that error if you don't last$date - as.Date(last$date, format=%m/%d/%Y) You must have dates, not character values. Try it, then make a zoo object, then plot it. Rui Barradas Em 31-07-2012 18:54, Yolande Tra escreveu: Thank you everyone for the attempt to solve the problem It is an irregular series and insert NAs when a date is missing library(zoo) z - zoo(last$r_wvht, order.by=last$date) plot(z) Error in plot.window(...) : need finite 'xlim' values In addition: Warning messages: 1: In xy.coords(x, y, xlabel, ylabel, log) : NAs introduced by coercion 2: In min(x) : no non-missing arguments to min; returning Inf 3: In max(x) : no non-missing arguments to max; returning -Inf I have also tried z - read.zoo(plot1.csv, header = TRUE, sep = ,, format = %m/%d/%Y) plot(z) The plot does not look good. It does not display the individual dates. Y Y On Tue, Jul 31, 2012 at 1:33 PM, Rui Barradas ruipbarra...@sapo.pt wrote: Hello, Sorry, I forgot the time series part of your question. You could use instead one of # 1. type = l gives a line plot plot(r_wvht ~ date, data = last, type=l) # 2. use time series object plot library(zoo) z - zoo(last$r_wvht, order.by=last$date) plot(z) Rui Barradas Em 31-07-2012 18:27, Rui Barradas escreveu: Hello, You could use dput(), it's not your first post... last - structure(list(date = c(8/6/2008, 8/8/2008, 8/11/2008, 8/13/2008, 8/14/2008, 8/18/2008, 8/20/2008, 8/27/2008, 8/28/2008, 8/31/2008, 9/2/2008, 9/3/2008, 9/4/2008, 9/5/2008, 9/8/2008, 9/11/2008, 10/12/2009, 10/14/2009, 10/19/2009, 10/21/2009, 10/26/2009, 10/29/2009, 10/30/2009, 11/2/2009, 11/3/2009, 11/4/2009, 11/11/2009, 11/13/2009 ), r_wvht = c(0.977, 0.773, 1.483, 1.577, 1.39, 0.78, 0.838, 1.77, 1.295, 2.41, 1.317, 1.3075, 1.39, 1.633, 1.2416667, 1.395, 0.863, 2.79, 1.0325, 1.965, 1.78, 1.567, 1.05, 1.463, 1.24, 1.0075, 1.605, 1.8475 )), .Names = c(date, r_wvht), class = data.frame, row.names = c(1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28)) last$date - as.Date(last$date, format=%m/%d/%Y) plot(r_wvht ~ date, data = last) (You were forgetting that last$date was a character vector, not class Date.) Hope this helps, Rui Barradas Em 31-07-2012 18:02, Yolande Tra escreveu: Hello, This should be pretty simple but I cannot get it right. Please point to the right code. Thanks. last - read.csv(file.path(dataDir,plot1.csv), as.is =T,stringsAsFactors = FALSE) last dater_wvht 18/6/2008 0.977 28/8/2008 0.773 3 8/11/2008 1.483 4 8/13/2008 1.577 5 8/14/2008 1.390 6 8/18/2008 0.780 7 8/20/2008 0.838 8 8/27/2008 1.770 9 8/28/2008 1.295 10 8/31/2008 2.410 11 9/2/2008 1.317 12 9/3/2008 1.3075000 13 9/4/2008 1.390 14 9/5/2008 1.633 15 9/8/2008 1.2416667 16 9/11/2008 1.395 17 10/12/2009 0.863 18 10/14/2009 2.790 19 10/19/2009 1.0325000 20 10/21/2009 1.965 21 10/26/2009 1.780 22 10/29/2009 1.567 23 10/30/2009 1.050 24 11/2/2009 1.463 25 11/3/2009 1.240 26 11/4/2009 1.0075000 27 11/11/2009 1.605 28 11/13/2009 1.8475000 x-as.vector(last$date) x [1] 8/6/2008 8/8/2008 8/11/2008 8/13/2008 8/14/2008 8/18/2008 8/20/2008 8/27/2008 [9] 8/28/2008 8/31/2008 9/2/2008 9/3/2008 9/4/2008 9/5/2008 9/8/2008 9/11/2008 [17] 10/12/2009 10/14/2009 10/19/2009 10/21/2009 10/26/2009 10/29/2009 10/30/2009 11/2/2009 [25] 11/3/2009 11/4/2009 11/11/2009 11/13/2009 y-as.vector(last$r_wvht) y [1] 0.977 0.773 1.483 1.577 1.390 0.780 0.838 1.770 1.295 2.410 [11] 1.317 1.3075000 1.390 1.633 1.2416667 1.395 0.863 2.790 1.0325000 1.965 [21] 1.780 1.567 1.050 1.463 1.240 1.0075000 1.605 1.8475000 plot(x,y) Error in plot.window(...) : need finite 'xlim' values In addition: Warning messages: 1: In xy.coords(x, y, xlabel, ylabel, log) : NAs introduced by coercion 2: In min(x) : no non-missing arguments to min; returning Inf 3: In max(x) : no non-missing arguments to max; returning -Inf plot(x,y,xlim=c(6/8/2008,11/13/2009)) Error in plot.window(...) : invalid 'xlim' value Y [[alternative HTML version deleted]] __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-helphttps://stat.ethz.ch/mailman/**listinfo/r-help
Re: [R] time series line plot: Error in plot.window(...) : invalid 'xlim' value
It does look better indeed. Thanks, Yolande On Tue, Jul 31, 2012 at 3:15 PM, Rui Barradas ruipbarra...@sapo.pt wrote: Hello, Adapted from the help page for plot.zoo #library(zoo) #z - zoo(last$r_wvht, order.by=last$date) plot(z, xaxt = n) tt - time(z) ix - seq(1, length(tt), length.out=8) axis(side = 1, at = tt[ix], labels = FALSE) labs - format(tt, %Y-%b-%d) axis(side = 1, at = tt[ix], labels = labs[ix], tcl = -0.7, cex.axis = 0.7, las=2) It looks better, but I wouldn't risk good. Rui Barradas Em 31-07-2012 19:10, Yolande Tra escreveu: Thanks. This is an irregular time series. The line plot does not look good because of the gap between 9/11/2008 and 10/12/2009. I think two plots would be better. How would you include the date on the x-axis. Right now it only gives one tick mark, 2009. Yolande On Tue, Jul 31, 2012 at 2:01 PM, Rui Barradas ruipbarra...@sapo.pt wrote: Hello, It only gives that error if you don't last$date - as.Date(last$date, format=%m/%d/%Y) You must have dates, not character values. Try it, then make a zoo object, then plot it. Rui Barradas Em 31-07-2012 18:54, Yolande Tra escreveu: Thank you everyone for the attempt to solve the problem It is an irregular series and insert NAs when a date is missing library(zoo) z - zoo(last$r_wvht, order.by=last$date) plot(z) Error in plot.window(...) : need finite 'xlim' values In addition: Warning messages: 1: In xy.coords(x, y, xlabel, ylabel, log) : NAs introduced by coercion 2: In min(x) : no non-missing arguments to min; returning Inf 3: In max(x) : no non-missing arguments to max; returning -Inf I have also tried z - read.zoo(plot1.csv, header = TRUE, sep = ,, format = %m/%d/%Y) plot(z) The plot does not look good. It does not display the individual dates. Y Y On Tue, Jul 31, 2012 at 1:33 PM, Rui Barradas ruipbarra...@sapo.pt wrote: Hello, Sorry, I forgot the time series part of your question. You could use instead one of # 1. type = l gives a line plot plot(r_wvht ~ date, data = last, type=l) # 2. use time series object plot library(zoo) z - zoo(last$r_wvht, order.by=last$date) plot(z) Rui Barradas Em 31-07-2012 18:27, Rui Barradas escreveu: Hello, You could use dput(), it's not your first post... last - structure(list(date = c(8/6/2008, 8/8/2008, 8/11/2008, 8/13/2008, 8/14/2008, 8/18/2008, 8/20/2008, 8/27/2008, 8/28/2008, 8/31/2008, 9/2/2008, 9/3/2008, 9/4/2008, 9/5/2008, 9/8/2008, 9/11/2008, 10/12/2009, 10/14/2009, 10/19/2009, 10/21/2009, 10/26/2009, 10/29/2009, 10/30/2009, 11/2/2009, 11/3/2009, 11/4/2009, 11/11/2009, 11/13/2009 ), r_wvht = c(0.977, 0.773, 1.483, 1.577, 1.39, 0.78, 0.838, 1.77, 1.295, 2.41, 1.317, 1.3075, 1.39, 1.633, 1.2416667, 1.395, 0.863, 2.79, 1.0325, 1.965, 1.78, 1.567, 1.05, 1.463, 1.24, 1.0075, 1.605, 1.8475 )), .Names = c(date, r_wvht), class = data.frame, row.names = c(1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28)) last$date - as.Date(last$date, format=%m/%d/%Y) plot(r_wvht ~ date, data = last) (You were forgetting that last$date was a character vector, not class Date.) Hope this helps, Rui Barradas Em 31-07-2012 18:02, Yolande Tra escreveu: Hello, This should be pretty simple but I cannot get it right. Please point to the right code. Thanks. last - read.csv(file.path(dataDir,**plot1.csv), as.is =T,stringsAsFactors = FALSE) last dater_wvht 18/6/2008 0.977 28/8/2008 0.773 3 8/11/2008 1.483 4 8/13/2008 1.577 5 8/14/2008 1.390 6 8/18/2008 0.780 7 8/20/2008 0.838 8 8/27/2008 1.770 9 8/28/2008 1.295 10 8/31/2008 2.410 11 9/2/2008 1.317 12 9/3/2008 1.3075000 13 9/4/2008 1.390 14 9/5/2008 1.633 15 9/8/2008 1.2416667 16 9/11/2008 1.395 17 10/12/2009 0.863 18 10/14/2009 2.790 19 10/19/2009 1.0325000 20 10/21/2009 1.965 21 10/26/2009 1.780 22 10/29/2009 1.567 23 10/30/2009 1.050 24 11/2/2009 1.463 25 11/3/2009 1.240 26 11/4/2009 1.0075000 27 11/11/2009 1.605 28 11/13/2009 1.8475000 x-as.vector(last$date) x [1] 8/6/2008 8/8/2008 8/11/2008 8/13/2008 8/14/2008 8/18/2008 8/20/2008 8/27/2008 [9] 8/28/2008 8/31/2008 9/2/2008 9/3/2008 9/4/2008 9/5/2008 9/8/2008 9/11/2008 [17] 10/12/2009 10/14/2009 10/19/2009 10/21/2009 10/26/2009 10/29/2009 10/30/2009 11/2/2009 [25] 11/3/2009 11/4/2009 11/11/2009 11/13/2009 y-as.vector(last$r_wvht) y [1] 0.977 0.773 1.483 1.577 1.390 0.780 0.838 1.770 1.295 2.410 [11] 1.317 1.3075000 1.390 1.633 1.2416667 1.395 0.863 2.790 1.0325000 1.965 [21] 1.780 1.567 1.050 1.463 1.240 1.0075000 1.605 1.8475000 plot(x,y) Error
Re: [R] time series line plot: Error in plot.window(...) : invalid 'xlim' value
It is not working yet last1$date - as.Date(last1$date, format=%m/%d/%Y) u- zoo(last1$r_wvht, order.by=last1$date) plot(u, xaxt=n) Error in plot.window(...) : need finite 'ylim' values In addition: Warning messages: 1: In min(x) : no non-missing arguments to min; returning Inf 2: In max(x) : no non-missing arguments to max; returning -Inf 3: In min(x) : no non-missing arguments to min; returning Inf 4: In max(x) : no non-missing arguments to max; returning -Inf Instead I read the help page on zoo (as you pointed out) and create a zoo object as follows z - zoo(c(0.98,0.77,1.48,1.58,1.39,0.78,0.84,1.77,1.30,2.41,1.32,1.31,1.39,1.63,1.24,1.40), as.Date(c(2008-08-06,2008-08-08,2008-08-11,2008-08-13,2008-08-14,2008-08-18,2008-08-20, 2008-08-27, 2008-08-28, 2008-08-31,2008-09-02, 2008-09-03,2008-09-04,2008-09-05,2008-09-08,2008-09-11))) plot(z, xaxt=n) plot(z, xaxt=n,xlab=,ylab=) And now there was no warning. Thanks, Yolande On Tue, Jul 31, 2012 at 5:06 PM, Rui Barradas ruipbarra...@sapo.pt wrote: Hello, Inline. Em 31-07-2012 21:45, Yolande Tra escreveu: I am sorry but I still got some errors. May be it is because of the package zoo. Please be patient with me. Thanks. Yolande last1 - read.csv(file.path(dataDir,**plot1_2008.csv), as.is =T,stringsAsFactors = FALSE) library(zoo) Attaching package: zoo The following object(s) are masked from package:base: as.Date, as.Date.numeric Before creating the zoo object, you MUST change the class of last1$date to Date: last1$date - as.Date(last1$Date, format=%m/%d/%Y) If not, it's a character vector, NOT a date. And plot.zoo doesn't recognize valid x axis values. Rui Barradas u- zoo(last1$r_wvht, order.by=last1$date) plot(u, xaxt=n) Error in plot.window(...) : need finite 'xlim' values In addition: Warning messages: 1: In min(x) : no non-missing arguments to min; returning Inf 2: In max(x) : no non-missing arguments to max; returning -Inf 3: In min(x) : no non-missing arguments to min; returning Inf 4: In max(x) : no non-missing arguments to max; returning -Inf 5: In xy.coords(x, y, xlabel, ylabel, log) : NAs introduced by coercion 6: In min(x) : no non-missing arguments to min; returning Inf 7: In max(x) : no non-missing arguments to max; returning -Inf On Tue, Jul 31, 2012 at 3:15 PM, Rui Barradas ruipbarra...@sapo.pt wrote: Hello, Adapted from the help page for plot.zoo #library(zoo) #z - zoo(last$r_wvht, order.by=last$date) plot(z, xaxt = n) tt - time(z) ix - seq(1, length(tt), length.out=8) axis(side = 1, at = tt[ix], labels = FALSE) labs - format(tt, %Y-%b-%d) axis(side = 1, at = tt[ix], labels = labs[ix], tcl = -0.7, cex.axis = 0.7, las=2) It looks better, but I wouldn't risk good. Rui Barradas Em 31-07-2012 19:10, Yolande Tra escreveu: Thanks. This is an irregular time series. The line plot does not look good because of the gap between 9/11/2008 and 10/12/2009. I think two plots would be better. How would you include the date on the x-axis. Right now it only gives one tick mark, 2009. Yolande On Tue, Jul 31, 2012 at 2:01 PM, Rui Barradas ruipbarra...@sapo.pt wrote: Hello, It only gives that error if you don't last$date - as.Date(last$date, format=%m/%d/%Y) You must have dates, not character values. Try it, then make a zoo object, then plot it. Rui Barradas Em 31-07-2012 18:54, Yolande Tra escreveu: Thank you everyone for the attempt to solve the problem It is an irregular series and insert NAs when a date is missing library(zoo) z - zoo(last$r_wvht, order.by=last$date) plot(z) Error in plot.window(...) : need finite 'xlim' values In addition: Warning messages: 1: In xy.coords(x, y, xlabel, ylabel, log) : NAs introduced by coercion 2: In min(x) : no non-missing arguments to min; returning Inf 3: In max(x) : no non-missing arguments to max; returning -Inf I have also tried z - read.zoo(plot1.csv, header = TRUE, sep = ,, format = %m/%d/%Y) plot(z) The plot does not look good. It does not display the individual dates. Y Y On Tue, Jul 31, 2012 at 1:33 PM, Rui Barradas ruipbarra...@sapo.pt wrote: Hello, Sorry, I forgot the time series part of your question. You could use instead one of # 1. type = l gives a line plot plot(r_wvht ~ date, data = last, type=l) # 2. use time series object plot library(zoo) z - zoo(last$r_wvht, order.by=last$date) plot(z) Rui Barradas Em 31-07-2012 18:27, Rui Barradas escreveu: Hello, You could use dput(), it's not your first post... last - structure(list(date = c(8/6/2008, 8/8/2008, 8/11/2008, 8/13/2008, 8/14/2008, 8/18/2008, 8/20/2008, 8/27/2008, 8/28/2008, 8/31/2008, 9/2/2008, 9/3/2008, 9/4/2008, 9/5/2008, 9/8/2008, 9/11/2008, 10/12/2009, 10/14/2009, 10/19/2009, 10/21/2009, 10/26/2009, 10/29/2009, 10/30/2009, 11/2/2009, 11/3/2009, 11/4/2009, 11/11/2009, 11/13/2009 ), r_wvht = c(0.977, 0.773, 1.483, 1.577, 1.39, 0.78
Re: [R] readRDS, In as.double.xts(fishReport$count) : NAs introduced by coercion
Thanks. It was very helpful. Y On Sun, Jul 29, 2012 at 2:45 AM, arun smartpink...@yahoo.com wrote: Hello, I tried to do the same thing that you have done. Without the timestamps as rownames (xts object), there were no errors. dat1-read.table(text= dive_id datetime speciescount size 1 08/06/2008 8:49:00 S.OYT15 6 1 08/06/2008 8:49:00 S.atrovirens 1 23 ,header=TRUE, sep=) dat2-dat1 saveRDS(dat2,dat2.rds) dat3-readRDS(dat2.rds) str(dat3) #'data.frame':2 obs. of 6 variables: # $ dive_id: int 1 1 # $ date : Factor w/ 1 level 08/06/2008: 1 1 # $ time : Factor w/ 1 level 8:49:00: 1 1 # $ species: Factor w/ 2 levels S.atrovirens,..: 2 1 # $ count : int 15 1 # $ size : int 6 23 dat3$count-as.numeric(dat3$count) is.numeric(dat3$count) #[1] TRUE Now with timestamps as row.names library(xts) DateTime-as.POSIXct(c(2008-08-06 08:49:00,2008-08-06 08:49:00),format=%Y-%m-%d %H:%M) dat4-xts(dat1,order.by=DateTime) saveRDS(dat4,dat4.rds) dat5-readRDS(dat4.rds) identical(dat4,dat5) #[1] TRUE dat5$count-as.numeric(dat5$count) #Here, I didn't get the warning message that you got is.numeric(dat5$count) #[1] FALSE #So, I assume that it is not because of reading the file as an RDS extension, but reading it as an xts object. #You can convert the xts to dataframe and do the conversion of count column to numeric. dat6-data.frame(date=index(dat5),coredata(dat5)) str(dat6) #'data.frame':2 obs. of 7 variables: #$ date : POSIXct, format: 2008-08-06 08:49:00 2008-08-06 08:49:00 #$ dive_id: Factor w/ 1 level 1: 1 1 #$ date.1 : Factor w/ 1 level 08/06/2008: 1 1 #$ time : Factor w/ 1 level 8:49:00: 1 1 #$ species: Factor w/ 2 levels S.atrovirens,..: 2 1 #$ count : Factor w/ 2 levels 1,15: 2 1 #$ size : Factor w/ 2 levels 23, 6: 2 1 dat6$count-as.numeric(dat6$count) is.numeric(dat6$count) #[1] TRUE I hope this helps. A.K. - Original Message - From: Yolande Tra yolande@gmail.com To: R help r-help@r-project.org Cc: Sent: Saturday, July 28, 2012 10:23 PM Subject: [R] readRDS, In as.double.xts(fishReport$count) : NAs introduced by coercion Hello, I looked in the R-help but could not find an archive addressing the following. I would like to convert a character to numeric after reading a file with RDS extension. After using as.numeric, I checked if it is numeric. It was not converted. Please help. Here is my code Report - readRDS(file=RDS/Report.RDS) Report[1:2,] dive_id date time species count size 2008-08-06 08:49:00 108/06/2008 8:49:00 S. OYT15 6 2008-08-06 08:49:00 108/06/2008 8:49:00 S. atrovirens 1 23 site depth level TRANSECT VIS_M TEMP_C swell_URSKI 2008-08-06 08:49:00 Hopkins 15 B 1 3.5 13.9 1.0686708 2008-08-06 08:49:00 Hopkins 15 B 1 3.5 13.9 1.0686708 Report$count-as.numeric(Report$count) Warning message: In as.double.xts(fishReport$count) : NAs introduced by coercion is.numeric(Report$count) [1] FALSE Thank you, Y [[alternative HTML version deleted]] __ R-help@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. [[alternative HTML version deleted]] __ R-help@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] readRDS, In as.double.xts(fishReport$count) : NAs introduced by coercion
Hello, I looked in the R-help but could not find an archive addressing the following. I would like to convert a character to numeric after reading a file with RDS extension. After using as.numeric, I checked if it is numeric. It was not converted. Please help. Here is my code Report - readRDS(file=RDS/Report.RDS) Report[1:2,] dive_id date time species count size 2008-08-06 08:49:00 108/06/2008 8:49:00 S. OYT15 6 2008-08-06 08:49:00 108/06/2008 8:49:00 S. atrovirens 1 23 site depth level TRANSECT VIS_M TEMP_C swell_URSKI 2008-08-06 08:49:00 Hopkins 15 B 1 3.5 13.9 1.0686708 2008-08-06 08:49:00 Hopkins 15 B 1 3.5 13.9 1.0686708 Report$count-as.numeric(Report$count) Warning message: In as.double.xts(fishReport$count) : NAs introduced by coercion is.numeric(Report$count) [1] FALSE Thank you, Y [[alternative HTML version deleted]] __ R-help@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] convert date to a factor
Hello, I would like to convert date as a factor to represent time in a repeated measure situation in the following code. How would I do that? d - read.csv(file.path(dataDir,data.csv), as.is=T,stringsAsFactors = FALSE) d[1:2,] id date ab c y 1 1 8/6/2008 Red15 B 22 2 1 8/6/2008 Green 15 B 22 Thank you, Y [[alternative HTML version deleted]] __ R-help@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.
Re: [R] convert date to a factor
Thanks, Y On Fri, Jul 20, 2012 at 11:47 AM, R. Michael Weylandt michael.weyla...@gmail.com wrote: d$date - factor(d$date) Best, Michael On Fri, Jul 20, 2012 at 9:44 AM, Yolande Tra yolande@gmail.com wrote: Hello, I would like to convert date as a factor to represent time in a repeated measure situation in the following code. How would I do that? d - read.csv(file.path(dataDir,data.csv), as.is=T,stringsAsFactors = FALSE) d[1:2,] id date ab c y 1 1 8/6/2008 Red15 B 22 2 1 8/6/2008 Green 15 B 22 Thank you, Y [[alternative HTML version deleted]] __ R-help@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.htmlhttp://www.r-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. [[alternative HTML version deleted]] __ R-help@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.
Re: [R] convert date to a factor
Thanks, Y On Fri, Jul 20, 2012 at 1:02 PM, arun smartpink...@yahoo.com wrote: Hi, Try this: dat1-read.table(text= iddateab cy 1 1 8/6/2008Red15B 22 2 1 8/6/2008 Green 15B 22 ,sep=,header=TRUE) dat1$date-with(dat1,as.factor(date)) dat1 id date a b c y 1 1 8/6/2008 Red 15 B 22 2 1 8/6/2008 Green 15 B 22 is.factor(dat1$date) [1] TRUE A.K. - Original Message - From: Yolande Tra yolande@gmail.com To: r-help@r-project.org Cc: Sent: Friday, July 20, 2012 10:44 AM Subject: [R] convert date to a factor Hello, I would like to convert date as a factor to represent time in a repeated measure situation in the following code. How would I do that? d - read.csv(file.path(dataDir,data.csv), as.is=T,stringsAsFactors = FALSE) d[1:2,] id date ab c y 1 1 8/6/2008 Red15 B 22 2 1 8/6/2008 Green 15 B 22 Thank you, Y [[alternative HTML version deleted]] __ R-help@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.htmlhttp://www.r-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. [[alternative HTML version deleted]] __ R-help@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] expert opinion on lmer
Hello, I have the following design, counts were collected at different transects, different depths and different sites at different times. Time is continuous and assumed to be random, all the others are categorical fixed where transect is nested within depth which is nested within site. I would like an expert opinion about the following code where intercept is modeled as random (I am not sure if this is the right way). a-factor(transect) b-factor(depth) c-factor(site) g-lmer(count~(1|time)+(time|a:b:c), family=poisson) Thanks, Y [[alternative HTML version deleted]] __ R-help@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] loop searching the id corresponding to the given index (timestamp)
Hello, I have the following loop for two data sets: diveData_2008 and diveData_2009. It uses two other data: diveCond_all and fishTable. The problem is at the point to identify the dive_id for the given index (index is timestamp). It keeps on saying for the1st loop Error in fishReport$dive_id[i] - dive_id : replacement has length zero for the 2nd loop Error in fishReport$dive_id[i + j] - dive_id : replacement has length zero That is where the only problem resides. Here is the code and below are the first 15 lines of data N - dim(diveData_2009)[1] + dim(diveData_2008)[1] fishReport - data.frame(matrix(0, nrow=N, ncol=11)) names(fishReport) - c(dive_id, site, section, level, transect, depth, species, count, size) for(i in 1:dim(diveData_2008)[1]){ # Which dive is this observation from thisIndex - as.character(index(diveData_2008[i,])) dive_id - diveCond_all$dive_id[diveCond_all$timestamp==thisIndex] cat(dive_id, thisIndex, \n) # Store the pertinent data in the fish report data.frame fishReport$dive_id[i] - dive_id fishReport$site[i] - diveData_2008[i,site] fishReport$level[i] - diveData_2008[i,level] fishReport$section[i] - 0 fishReport$transect[i] - as.numeric(diveData_2008[i,TRANSECT]) fishReport$depth[i]- as.numeric(diveData_2008[i,depth]) fishReport$species[i] - fishTable$name_2009[fishTable$name_2008==as.character(diveData_2008[i,species]) ][1] fishReport$count[i]- as.numeric(diveData_2008[i,count]) fishReport$size[i]- as.numeric(diveData_2008[i,size]) fishReport$visibility[i] - as.numeric(diveData_2008[i,VIS_M]) fishReport$swell[i] -as.numeric(diveData_2008[i,swell_URSKI]) } j-i ## The 2009 dives for(i in i+1:dim(diveData_2009)[1]){ thisIndex - as.character(index(diveData_2009[i,])) dive_id - diveCond_all$dive_id[diveCond_all$timestamp==thisIndex] cat(dive_id, thisIndex, \n) fishReport$dive_id[i+j] - dive_id fishReport$site[i+j] - Hopkins fishReport$level[i+j] - diveData_2009[i,level] fishReport$transect[i+j] - as.numeric(diveData_2009[i,TRANSECT]) fishReport$depth[i+j]- as.numeric(diveData_2009[i,depth]) fishReport$species[i+j] - diveData_2009[i,species] fishReport$count[i+j]- as.numeric(diveData_2008[i,count]) fishReport$size[i+j]- as.numeric(diveData_2009[i,size]) fishReport$visibility[i+j] - as.numeric(diveData_2008[i,VIS_M]) } diveData_2008 (first 15 lines) structure(c( 1, 1, 1, 1, 1, 1, 1, 1, 1, 2, 2, 2, 2, 2, 2, 8/6/2008, 8/6/2008, 8/6/2008, 8/6/2008, 8/6/2008, 8/6/2008, 8/6/2008, 8/6/2008, 8/6/2008, 8/6/2008, 8/6/2008, 8/6/2008, 8/6/2008, 8/6/2008, 8/6/2008, 8:49, 8:49, 8:49, 8:49, 8:49, 8:49, 8:49, 8:49, 8:49, 10:03, 10:03, 10:03, 10:03, 10:03, 10:03, S. OYT, S. atrovirens, S. atrovirens, S. atrovirens, O. pictus, C. nicholsii, C. nicholsii, D. vacca, No organisms, S. OYT, S. atrovirens, S. atrovirens, S. atrovirens, S. chrysomelas, O. pictus, 15,1,1,1, 1,1,1,1,1,1,1,1, 1,1,1, 6, 23, 27, 29, 8, 8, 9, 18, NA, 6, 23, 28, 35, 32, 8, Hopkins, Hopkins, Hopkins, Hopkins, Hopkins, Hopkins, Hopkins, Hopkins, Hopkins, Hopkins, Hopkins, Hopkins, Hopkins, Hopkins, Hopkins, 15, 15, 15, 15, 15, 15, 15, 15, 15, 10, 10, 10, 10, 10, 10, B, B, B, B, B, B, B, B, M, B, B, B, B, B, B, 1, 1, 1, 1, 1, 1, 1, 1, 1, 2, 2, 2, 2, 2, 2, 3.5, 3.5, 3.5, 3.5, 3.5, 3.5, 3.5, 3.5, 3.5, 3.5, 3.5, 3.5, 3.5, 3.5, 3.5, 13.9, 13.9, 13.9, 13.9, 13.9, 13.9, 13.9, 13.9, 13.9, 13.9, 13.9, 13.9, 13.9, 13.9, 13.9, 1.0686708, 1.0686708, 1.0686708, 1.0686708, 1.0686708, 1.0686708, 1.0686708, 1.0686708, 1.0686708, 1.950, 1.950, 1.950, 1.950, 1.950, 1.950), .indexCLASS = c(POSIXct, POSIXt), tclass = c(POSIXct, POSIXt), .indexTZ = , tzone = , class = c(xts, zoo), index = structure(c(1218026940, 1218026940, 1218026940, 1218026940, 1218026940, 1218026940, 1218026940, 1218026940, 1218026940, 1218031380, 1218031380, 1218031380, 1218031380, 1218031380, 1218031380 ), tzone = , tclass = c(POSIXct, POSIXt)), .Dim = c(15L, 13L), .Dimnames = list(NULL, c(dive_id, date, time, species, count, size, site, depth, level, TRANSECT, VIS_M, TEMP_C, swell_URSKI))) diveData_2009 (first 15 lines) structure(c(62, 62, 62, 62, 62, 62, 62, 62, 62, 62, 62, 62,
Re: [R] loop searching the id corresponding to the given index (timestamp)
it is a function from library(xts) On Wed, Jul 18, 2012 at 1:15 PM, Jean V Adams jvad...@usgs.gov wrote: What is the function index() that you use in this line of code? thisIndex - as.character(index(diveData_2008[i,])) Is it from some package? Or a function you wrote yourself? I'm trying to run the code you submitted, but I don't have a function called index(). Jean Yolande Tra yolande@gmail.com wrote on 07/18/2012 08:47:04 AM: Hello, I have the following loop for two data sets: diveData_2008 and diveData_2009. It uses two other data: diveCond_all and fishTable. The problem is at the point to identify the dive_id for the given index (index is timestamp). It keeps on saying for the1st loop Error in fishReport$dive_id[i] - dive_id : replacement has length zero for the 2nd loop Error in fishReport$dive_id[i + j] - dive_id : replacement has length zero That is where the only problem resides. Here is the code and below are the first 15 lines of data N - dim(diveData_2009)[1] + dim(diveData_2008)[1] fishReport - data.frame(matrix(0, nrow=N, ncol=11)) names(fishReport) - c(dive_id, site, section, level, transect, depth, species, count, size) for(i in 1:dim(diveData_2008)[1]){ # Which dive is this observation from thisIndex - as.character(index(diveData_2008[i,])) dive_id - diveCond_all$dive_id[diveCond_all$timestamp==thisIndex] cat(dive_id, thisIndex, \n) # Store the pertinent data in the fish report data.frame fishReport$dive_id[i] - dive_id fishReport$site[i] - diveData_2008[i,site] fishReport$level[i] - diveData_2008[i,level] fishReport$section[i] - 0 fishReport$transect[i] - as.numeric(diveData_2008[i,TRANSECT]) fishReport$depth[i]- as.numeric(diveData_2008[i,depth]) fishReport$species[i] - fishTable$name_2009[fishTable$name_2008==as.character(diveData_2008 [i,species]) ][1] fishReport$count[i]- as.numeric(diveData_2008[i,count]) fishReport$size[i]- as.numeric(diveData_2008[i,size]) fishReport$visibility[i] - as.numeric(diveData_2008[i,VIS_M]) fishReport$swell[i] -as.numeric(diveData_2008[i,swell_URSKI]) } j-i ## The 2009 dives for(i in i+1:dim(diveData_2009)[1]){ thisIndex - as.character(index(diveData_2009[i,])) dive_id - diveCond_all$dive_id[diveCond_all$timestamp==thisIndex] cat(dive_id, thisIndex, \n) fishReport$dive_id[i+j] - dive_id fishReport$site[i+j] - Hopkins fishReport$level[i+j] - diveData_2009[i,level] fishReport$transect[i+j] - as.numeric(diveData_2009[i,TRANSECT]) fishReport$depth[i+j] - as.numeric(diveData_2009[i,depth]) fishReport$species[i+j] - diveData_2009[i,species] fishReport$count[i+j]- as.numeric(diveData_2008[i,count]) fishReport$size[i+j]- as.numeric(diveData_2009[i,size]) fishReport$visibility[i+j] - as.numeric(diveData_2008[i,VIS_M]) } diveData_2008 (first 15 lines) structure(c( 1, 1, 1, 1, 1, 1, 1, 1, 1, 2, 2, 2, 2, 2, 2, 8/6/2008, 8/6/2008, 8/6/2008, 8/6/2008, 8/6/2008, 8/6/2008, 8/6/2008, 8/6/2008, 8/6/2008, 8/6/2008, 8/6/2008, 8/6/2008, 8/6/2008, 8/6/2008, 8/6/2008, 8:49, 8:49, 8:49, 8:49, 8:49, 8:49, 8:49, 8:49, 8:49, 10:03, 10:03, 10:03, 10:03, 10:03, 10:03, S. OYT, S. atrovirens, S. atrovirens, S. atrovirens, O. pictus, C. nicholsii, C. nicholsii, D. vacca, No organisms, S. OYT, S. atrovirens, S. atrovirens, S. atrovirens, S. chrysomelas, O. pictus, 15,1,1,1, 1,1,1,1,1,1,1,1, 1,1,1, 6, 23, 27, 29, 8, 8, 9, 18, NA, 6, 23, 28, 35, 32, 8, Hopkins, Hopkins, Hopkins, Hopkins, Hopkins, Hopkins, Hopkins, Hopkins, Hopkins, Hopkins, Hopkins, Hopkins, Hopkins, Hopkins, Hopkins, 15, 15, 15, 15, 15, 15, 15, 15, 15, 10, 10, 10, 10, 10, 10, B, B, B, B, B, B, B, B, M, B, B, B, B, B, B, 1, 1, 1, 1, 1, 1, 1, 1, 1, 2, 2, 2, 2, 2, 2, 3.5, 3.5, 3.5, 3.5, 3.5, 3.5, 3.5, 3.5, 3.5, 3.5, 3.5, 3.5, 3.5, 3.5, 3.5, 13.9, 13.9, 13.9, 13.9, 13.9, 13.9, 13.9, 13.9, 13.9, 13.9, 13.9, 13.9, 13.9, 13.9, 13.9, 1.0686708, 1.0686708, 1.0686708, 1.0686708, 1.0686708, 1.0686708, 1.0686708, 1.0686708, 1.0686708, 1.950, 1.950, 1.950
Re: [R] loop searching the id corresponding to the given index (timestamp)
Thank you Rui. Very helpful. Yolande. On Wed, Jul 18, 2012 at 1:37 PM, Rui Barradas ruipbarra...@sapo.pt wrote: Hello, Try the following. for(i in 1:dim(diveData_2008)[1]){ # Which dive is this observation from thisIndex - as.character(index(diveData_**2008[i,])) thisIndex - as.POSIXct(thisIndex) dive_id - diveCond_all$dive_id[diveCond_**all$timestamp == thisIndex] # [... etc ...] And the same in the 2009 loop. I think this is it. Good luck, Rui Barradas Em 18-07-2012 14:47, Yolande Tra escreveu: Hello, I have the following loop for two data sets: diveData_2008 and diveData_2009. It uses two other data: diveCond_all and fishTable. The problem is at the point to identify the dive_id for the given index (index is timestamp). It keeps on saying for the1st loop Error in fishReport$dive_id[i] - dive_id : replacement has length zero for the 2nd loop Error in fishReport$dive_id[i + j] - dive_id : replacement has length zero That is where the only problem resides. Here is the code and below are the first 15 lines of data N - dim(diveData_2009)[1] + dim(diveData_2008)[1] fishReport - data.frame(matrix(0, nrow=N, ncol=11)) names(fishReport) - c(dive_id, site, section, level, transect, depth, species, count, size) for(i in 1:dim(diveData_2008)[1]){ # Which dive is this observation from thisIndex - as.character(index(diveData_**2008[i,])) dive_id - diveCond_all$dive_id[diveCond_**all$timestamp==thisIndex] cat(dive_id, thisIndex, \n) # Store the pertinent data in the fish report data.frame fishReport$dive_id[i] - dive_id fishReport$site[i] - diveData_2008[i,site] fishReport$level[i] - diveData_2008[i,level] fishReport$section[i] - 0 fishReport$transect[i] - as.numeric(diveData_2008[i,**TRANSECT]) fishReport$depth[i]- as.numeric(diveData_2008[i,**depth]) fishReport$species[i] - fishTable$name_2009[fishTable$**name_2008==as.character(** diveData_2008[i,species]) ][1] fishReport$count[i]- as.numeric(diveData_2008[i,**count]) fishReport$size[i]- as.numeric(diveData_2008[i,**size]) fishReport$visibility[i] - as.numeric(diveData_2008[i,**VIS_M]) fishReport$swell[i] -as.numeric(diveData_2008[i,** swell_URSKI]) } j-i ## The 2009 dives for(i in i+1:dim(diveData_2009)[1]){ thisIndex - as.character(index(diveData_**2009[i,])) dive_id - diveCond_all$dive_id[diveCond_**all$timestamp==thisIndex] cat(dive_id, thisIndex, \n) fishReport$dive_id[i+j] - dive_id fishReport$site[i+j] - Hopkins fishReport$level[i+j] - diveData_2009[i,level] fishReport$transect[i+j] - as.numeric(diveData_2009[i,**TRANSECT]) fishReport$depth[i+j] - as.numeric(diveData_2009[i,**depth]) fishReport$species[i+j] - diveData_2009[i,species] fishReport$count[i+j]- as.numeric(diveData_2008[i,**count]) fishReport$size[i+j]- as.numeric(diveData_2009[i,**size]) fishReport$visibility[i+j] - as.numeric(diveData_2008[i,**VIS_M]) } diveData_2008 (first 15 lines) structure(c( 1, 1, 1, 1, 1, 1, 1, 1, 1, 2, 2, 2, 2, 2, 2, 8/6/2008, 8/6/2008, 8/6/2008, 8/6/2008, 8/6/2008, 8/6/2008, 8/6/2008, 8/6/2008, 8/6/2008, 8/6/2008, 8/6/2008, 8/6/2008, 8/6/2008, 8/6/2008, 8/6/2008, 8:49, 8:49, 8:49, 8:49, 8:49, 8:49, 8:49, 8:49, 8:49, 10:03, 10:03, 10:03, 10:03, 10:03, 10:03, S. OYT, S. atrovirens, S. atrovirens, S. atrovirens, O. pictus, C. nicholsii, C. nicholsii, D. vacca, No organisms, S. OYT, S. atrovirens, S. atrovirens, S. atrovirens, S. chrysomelas, O. pictus, 15,1,1,1, 1,1,1,1,1,1,1,1, 1,1,1, 6, 23, 27, 29, 8, 8, 9, 18, NA, 6, 23, 28, 35, 32, 8, Hopkins, Hopkins, Hopkins, Hopkins, Hopkins, Hopkins, Hopkins, Hopkins, Hopkins, Hopkins, Hopkins, Hopkins, Hopkins, Hopkins, Hopkins, 15, 15, 15, 15, 15, 15, 15, 15, 15, 10, 10, 10, 10, 10, 10, B, B, B, B, B, B, B, B, M, B, B, B, B, B, B, 1, 1, 1, 1, 1, 1, 1, 1, 1, 2, 2, 2, 2, 2, 2, 3.5, 3.5, 3.5, 3.5, 3.5, 3.5, 3.5, 3.5, 3.5, 3.5, 3.5, 3.5, 3.5, 3.5, 3.5, 13.9, 13.9, 13.9, 13.9, 13.9, 13.9, 13.9, 13.9, 13.9, 13.9, 13.9, 13.9, 13.9, 13.9, 13.9, 1.0686708, 1.0686708, 1.0686708, 1.0686708, 1.0686708
[R] NA instead of time stamp
I was wondering why I get NA instead of the timestamp in the following. Thanks. dataDir - file.path(wd) localRaw - read.csv(file.path(dataDir,LOCAL.csv), as.is=T,stringsAsFactors = FALSE) localRaw[1:2,] Year Month Day hour minute second Temp1mab Temp7mab Temp14mab Salinity1mab 1 200910 50 0 0 11.288 13.67513.743 33.513 2 200910 50 15 0 11.258 13.68413.716 33.514 O21mab waveht wavedir waveperiod depth mab along across 1 0 54.926 1.600340 9.09 .NA NA 2 0 55.574 1.525340 9.09 .NA NA DateTime-with(localRaw,paste(Year,Month,Day,hour,minute)) DateTime-as.POSIXct(DateTime, format=%m/%d/%Y %H:%M) localCond_2009-xts(localRaw ,order.by=DateTime) localCond_2009[1:2,] Year Month Day hour minute second Temp1mab Temp7mab Temp14mab NA 2009 10 5 0 0 011.288 13.675 13.743 NA 2009 10 5 0 15 011.258 13.684 13.716 Salinity1mab O21mab waveht wavedir waveperiod depthmab along across NA 33.513 054.926 1.600 340.0 9.090 . NA NA NA 33.514 055.574 1.525 340.0 9.090 . NA NA [[alternative HTML version deleted]] __ R-help@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] as.xts
Hello, Attached is the file created from as.xts. After submitting the following code, I got an error. Please help. Thanks. diveCond - data.frame(matrix(0, nrow=61, ncol=17)) names(diveCond) - c(dive_id, timestamp, visability, r_wvht, r_dpd, r_apt, r_mwd, r_wtmp, l_salinity, l_o2, l_hs, l_tp, l_wdir, l_along, l_cross, l_mab, l_depth) dive_id - 0 for(i in unique(as.character(index(diveData_2008{ dive_id - dive_id+1 diveCond$dive_id[dive_id] - dive_id diveCond$timestamp[dive_id] - as.character(i) diveCond$visability[dive_id] - as.numeric(diveData_2008[i][1,11]) } Error in if (length(c(year, month, day, hour, min, sec)) == 6 c(year, : missing value where TRUE/FALSE needed In addition: Warning messages: 1: In as_numeric() : NAs introduced by coercion 2: In as_numeric() : NAs introduced by coercion Thanks, Yolande __ R-help@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] Error in as.xts
Hi I got the following error using as.xts Error in xts(x, order.by = order.by, frequency = frequency, ...) : NROW(x) must match length(order.by) Here is how the data looks like d1 - read.csv(file.path(dataDir,AppendixA-FishCountsTable-2009.csv), as.is=T) d1[1:3,] dive_id date time species count sizesite depth level TRANSECT VIS_M 1 62 10/12/2009 12:44 E. lateralis 2 15 Hopkins15 B 1 4 2 62 10/12/2009 12:44 E. lateralis 1 22 Hopkins15 B 1 4 3 62 10/12/2009 12:44 E. lateralis 1 25 Hopkins15 B 1 4 diveData_2009 - as.xts( d1,order.by=as.POSIXct(strptime(paste(d$date, d$TIME ), %d/%m/%Y %H:%M) )) Error in xts(x, order.by = order.by, frequency = frequency, ...) : NROW(x) must match length(order.by) I could not figure out how to correct it Thank you for your help Yolande [[alternative HTML version deleted]] __ R-help@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.