0

I'm trying to create a graph with curve() with do.call to apply a function to each element in a list but the x argument is not being recognized.

tt <- function(x) {
  list1 <- list(
    option1 <- c(init=600000 + 600000, depr=000000, il=180, per=180, 
                 quant=list(c(45)), pre=list(c(330000)), cust=0,
                 cust_un=list(c(0)), sala=1200, num=0, wacc=0.0082, 
                 redr=1, tem=69, capa=2000, cap2=60000, cap3=100000, 
                 cap4=1000000, custo2=1200, custo3=1600, custo4=5000, 
                 chan=0.30, tempo_nal=0, redu_lucr=00, redu_qt=0,
                 aumen_cf=0.3, redu_lucrofinal=0.2, redu_qtdfinal=0.1, 
                 aumen_cffi=0.80, final=0000, iniceco=210000, 
                 finreco=250000, iniv=40000, fiv=65000, ininda=000, 
                 percionario=1, n=80, PV=1300000, i=0.008, temrmal=1, 
                 temeio=0, car=x)
  )
  sapply(list1, function(x){do.call(mean, as.list(x))})
}

curve(tt, from=3, to=120)

the x in car argument is not being recognized:

# Error ... unused arguments (car1 = 3, car2 = 4.17, car3 = 5.34, car4 = 6.51, 
#  car5 = 7.68, car6 = 8.85, car7 = 10.02, car8 = 11.19, car9 = 12.36, 
#  car10 = 13.53, car11 = 14.7, car12 = 15.87,car13 = 17.04, car14 = 18.21, 
#  car15 = 19.38, car16 = 20.55, car17 = 21.72, car18 = 22.89, car19 = 24.06, 
#  car20 = 25.23, car21 = 26.4, car22 = 27.57, car23 = 28.74, car24 = 29.91, 
#  car25 = 31.08, car26 = 32.25, car27 = 33.42, car28 = 34.59, car29 = 35.76, 
#  car30 = 36.93, car31 = 38.1, car32 = 39.27, car33 = 40.44, car34 = 41.61, 
#  car35 = 42.78, car36 = 43.95, car37 = 45.12, car38 = 46.29, car39 = 47.46, 
#  car40 = 48.63, car41 = 49.8, car42 = 50.97, car43 = 52.14, car44 = 53.31, 
#  car45 = 54.48, car46 = 55.65, car47 = 56.82, car48 = 57.99, car49 = 59.16, 
#  car50 = 6  
jay.sf
  • 60,139
  • 8
  • 53
  • 110
RoBrT
  • 59
  • 4
  • Where does the `rr2` function come from? It's easier to help you if you include a simple [reproducible example](https://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example) with sample input and desired output that can be used to test and verify possible solutions. – MrFlick Nov 14 '21 at 02:08
  • Try `sapply(list1, function(x, ...) {do.call(rr2, as.list(x))})`. – jay.sf Nov 14 '21 at 05:49

0 Answers0