-1

Hi smart people of the interwebz!

I've got a probably stupid problem. I'm working with a list - called "groups" - of data frames, which I want to work through a function with multiple entry possibilities.

Now the thing is, that although all values should be changeable, but I currently intent to just change one (the data frame) via a list with lapply.

The function looks as follows:

regressions <- function(endo, dataframe, scaling, factorizing){...}

Where I only intent to change the value "Arab_World" (the data frame).

regressions("Ins_Share", Arab_World, T, F)

I tried it with "bullshit bingo" via lapply, but don't know how to input my function into it... I wnat to have the possibility to change values in the function (i.e. endo, scaling and factorizing) in the future, but currently only need to work through the list of data frames.

My last sad try looked something like this, where "x" should be an entry from the list.

lapply(groups, function(x) {regressions("Ins_Share", x, T, F)})

This then produces this error message

Error in colMeans(x, na.rm = TRUE) : 'x' must be numeric Called from: colMeans(x, na.rm = TRUE)

I'm quite frustrated due to the apparent simplicity of the problem, but my inability to solve it, and hope that I could learn from someone in here!

Thank you in advance!

Daniel
  • 1
  • 2
  • 2
    The "try" code looks like it should work...? If you want to use lapply without `function(x)`, you can perhaps name the other args `lapply(groups, regressions, endo = foo, scaling = bah, factorizing = egad)`. If no one figures it out, you might consider making a reproducible example, btw: https://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example/28481250#28481250 – Frank Jul 17 '18 at 18:12
  • If that `lapply` code doesn't work it's probably an issue with the `regressions` function, not the `lapply` code. – IceCreamToucan Jul 17 '18 at 18:13
  • Are the variables T and F defined outside of regressions() before your call to lapply? – fjimenez Jul 17 '18 at 18:43
  • Frank: I'm unfortunately not at liberty of posting the data, otherwise I would have provided some. Sorry! Ryan: The function works, if I input the data frame manually. fjimenez: T and F are defined inside the regression – Daniel Jul 17 '18 at 19:38
  • The fool that I am, I forgot to provide the error message: Error in colMeans(x, na.rm = TRUE) : 'x' must be numeric Called from: colMeans(x, na.rm = TRUE) – Daniel Jul 17 '18 at 19:42
  • Even if you can't post your exact data, you can come up with some dummy data or find a public domain dataset that replicates the problem. Otherwise, we have no way of reproducing the issue – camille Jul 17 '18 at 22:39
  • Each data frame has about 84 columns (where one of them is a date and the rest just numeric). That's the reason why I have no idea how to provide a reproducible example - and still can't upload data I work with. I think that the problem lies in the date-column, but I have no idea how to circumvent said problem – Daniel Jul 18 '18 at 18:50

1 Answers1

0

If someone should stumble upon the same problem as I did. lapply just needed "get()"...

i.e.

lapply(groups, function(x) {regressions("Ins_Share", get(x), T, F)})

Problem solved.

Daniel
  • 1
  • 2