[R] replacement has length zero. In addition: Warning message: In max(i) : no non-missing arguments to max; returning -Inf

Sarah Goslee sarah.goslee at gmail.com
Fri Aug 3 22:02:16 CEST 2012


Hi Yolande,

What's index() ?

I get
>  ind <- which.min( abs(index(regCond_all) - thisStamp ))
Error in which.min(abs(index(regCond_all) - thisStamp)) :
  could not find function "index"

There's probably an easier way to do whatever you're trying to
accomplish, but I'm afraid I can't tell what that is from just your
code, especially without being able to figure out how ind is
calculated. Can you describe what you want to do and what the result
should look like when run with the first 10 rows of your data, as you
provided with dput()?

Sarah

On Fri, Aug 3, 2012 at 3:49 PM, Yolande Tra <yolande.tra at gmail.com> wrote:
> 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
-- 
Sarah Goslee
http://www.functionaldiversity.org



More information about the R-help mailing list