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, 9999, 9999,
> 9999, 9999, 9999, 9999, 9999, 9999, 9999, 9999, 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<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.

Reply via email to