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
  • note on first line: should be mins <- bind_rows(april.mins, may.>mins<) – Robert Tan Dec 02 '17 at 02:06
  • Refer to https://stackoverflow.com/questions/18222286/dynamically-select-data-frame-columns-using-and-a-vector-of-column-names may want to try it using bracket subsetting vals <- function(source){ runif(600, min = mins[source], max = max[source]) } – Robert Tan Dec 02 '17 at 02:11
  • accessing via brackets produces same error – Michaela Dec 02 '17 at 02:13

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
  • 634
  • 1
  • 8
  • 21