1

I have two lists:

list.1
list.2

I have a command for a list of tables. It works well:

foreach(x=iter(list.1)) %do%
{ 
    assign(x, mutate(get(x),  date = make_datetime(
    shana, hodesh, taarich, shaa)) %>%
    select( -shana, -hodesh, -taarich, -shaa)) # selecting the relevant columns.
}

But I want to apply this command for multiple lists. I tried to write this, but didn't go well:

foreach(x=iter(list.1 , list.2 )) %do%
{ 
   assign(x, mutate(get(x),  date = make_datetime(
   shana, hodesh, taarich, shaa)) %>%
   select( -shana, -hodesh, -taarich, -shaa)) # selecting the relevant columns.
}
Dan Fairaizl
  • 2,172
  • 2
  • 28
  • 31
Arie D
  • 11
  • 1
  • Thank you. Can you please help me with the syntax? I'm having trouble with that. – Arie D Jul 25 '17 at 17:55
  • sure. What exactly you want to do? Something like this: https://stackoverflow.com/questions/19002378/applying-a-function-on-two-lists or you want to apply this function (on each list separately)? – M-- Jul 25 '17 at 18:01
  • I want to apply this function in each list separately but in the same command, because I have a lot of lists – Arie D Jul 25 '17 at 18:09

1 Answers1

0

You can do

lapply(list(list.1, list.2), function(list.i) {
  foreach(x=iter(list.i)) %do%
  { 
    assign(x, mutate(get(x),  date = make_datetime(
      shana, hodesh, taarich, shaa)) %>%
        select( -shana, -hodesh, -taarich, -shaa)) # selecting the relevant columns.
  }
}
F. Privé
  • 11,423
  • 2
  • 27
  • 78