-1

I am new to R, and am trying to use aRpsDCA to create a function to estimate decline parameters for an oil or gas well by history-matching. I get it to work fine on a single well, but am having difficulties applying the formula to a large .csv file containing several wells (The dataset has a well identifier, cumulative months, and then rate at that month for all the wells, and they all have differing cumulative months). I am trying to use lapply but so far am having errors.

I won't go through all of the function, but it takes two variables (q, t), or function(q,t). The function is called h2e.fnc. Here is what I am trying to use to get it to run over the entire list, but it's not working.

declAll <- lapply(hynsvl$API, h2e.fnc(hynsvl$q, hynsvl$t))
Error in match.fun(FUN) : 
  'h2e.fnc(hynsvl$q, hynsvl$t)' is not a function, character or symbol

$API is the well identifier, and then q and t are rate and time inputs into the function.

Any suggestions on how I would properly run this to get the function to calculate for all of the wells individually?

bdavis562002
  • 101
  • 3
  • 2
    Welcome to StackOverflow. Please provide a reproducible example including test data to troubleshoot the code. For reference see: https://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example – Djork Apr 20 '18 at 03:38

1 Answers1

0

You can use apply to call for all rows in your dataframe

twoarg <- function(a,b)
{
   a + b
}
l1 <- c(1:100)
l2 <- c(100:1)

df <- data.frame(l1,l2)

apply(df,1,function(x) twoarg(x["l1"],x["l2"])) # 1 all rows , 2 all columns
Carlos Santillan
  • 1,077
  • 7
  • 8