1

I have a two lists of named data in R. They are different min and max generations from energy sources.

mins <- bind_rows(april.mins, may.maxs)
maxs <- bind_rows(april.maxs, may.maxs)

mins <- lapply(mins, mean)
maxs <- lapply(maxs, mean)

I am attempting to write a function that will let me generate 600 random values from the different mins and maxs by the different named sources and then storing them.

vals <- function(source){
  runif(600, min = mins$source, max = max$source) 
   }

When I individually run this, I am able to generate the random values. For ex:

runif(600, min = mins$biogas, max = maxs$biogas)

However, as the function, it returns an "invalid arguments" error.

vals(geothermal)

Any insight would be much appreciated. Thank you!

Michaela
  • 39
  • 3

1 Answers1

0

Try this:

minss = data.frame(biogas=5)

maxss = data.frame(biogas=10)

vals <- function(source){
  runif(600, min = minss[[source]], max = maxss[[source]]) 
}

vals('biogas')
Robert Tan
  • 594
  • 1
  • 8
  • 20