[R] About uniroot error
Tania Morgado Garcia
tmg1970 @ending from gm@il@com
Mon Sep 24 19:37:12 CEST 2018
Thanks for your answers. I continue to learn R and now I am detained in an
error with uniroot that I see happens to others but I can not find the
solution. Next the code
x1 <- BAaxOrd$V1
y1 <- BAaxOrd$V2
x1R <- BAaxOrdRCOS$V1
y1R <- BAaxOrdRCOS$V2
FCOS1 <- splinefun(smooth.spline(x1,y1))
FRCOS1 <- splinefun(smooth.spline(x1R,y1R))
FCOS1 <- Vectorize(FCOS1)
FRCOS1 <- Vectorize(FRCOS1)
req(input$file1)
tryCatch(
{
df <- read.csv(input$file1$datapath,
header = input$header,
sep = "\t",
quote = '"')
},
error = function(e) {
# return a safeError if a parsing error occurs
stop(safeError(e))
}
)
#if(input$disp == "head") {
# return(head(df))
#}
#else {
# Determine Carbon Reserve
for (row in 1:nrow(df)) {
if(df$ts==1) {
prof <-
uniroot(f=function(x){FCOS1(x1)-df$carbono},interval=c(0,20))$root
limsup <- prof + df$pu
reserva <- integrate(FRCOS1,prof,limsup)$value
}
The if is because there are several types of soil, but I only put one. The
error is
Warning in if (is.na(f.lower)) stop("f.lower = f(lower) is NA") :
the condition has length > 1 and only the first element will be used
Warning in if (is.na(f.upper)) stop("f.upper = f(upper) is NA") :
the condition has length > 1 and only the first element will be used
Warning: Error in uniroot: f() values at end points not of opposite sign
The file that I load with data has a single row with the values ts = 1,
carbon = 2.04 and pu = 15 (I left only that row to be able to determine the
origin of the error). The functions FCOS1 and FRCOS1 are monotone
decreasing.Graphic attachment of FCOS1
I would appreciate some help in this regard
thanks a lot
More information about the R-help
mailing list