I try to create descriptive statistics for different groups of refugees. I want to use a for loop which creates the same tables always for a certain sub sample of my refugees data base. I create multiple sub groups for different countries using a list.
I tried:
all <- refugees
syr <- subset(refugees[refugees$nation_vorher == "MSYR"])
all$arrival_y <- format(as.Date(all$arrival), format("%Y"))
all$gebj <- as.integer(all$gebj)
syr$arrival_y <- format(as.Date(syr$arrival), format("%Y"))
syr$gebj <- as.integer(syr$gebj)
countries = list(all, syr)
results <- vector(mode = "integer", length = length(countries))
for (i in 1:length(countries)){
  refugees <- countries[i]
  
 
  
  arr2007 <- subset(refugees[refugees$arrival_y == "2007" & refugees$gebj <= 1992])
  arr2011 <- subset(refugees[refugees$arrival_y == "2011" & refugees$gebj <= 1996])
  arr2016 <- subset(refugees[refugees$arrival_y == "2016" & refugees$gebj <= 2001])
  arr2020 <- subset(refugees[refugees$arrival_y == "2020" & refugees$gebj <= 2005]) 
}
... more code below
The code works perfectly if I run it without the loop. However, when I run the loop I get the following Error: Error in subset.default(refugees[refugees$arrival_y == "2007" & refugees$gebj <= : argument "subset" is missing, with no default
I hope you can help me, thanks!
EDIT some lines of data:
     ID arrival      nation_vorher    bez_stsl gebj gesl arrival_y
     1    2005-01-01          MSYR     Serbien 1955    F      2007
     2    2009-02-23          MAFG        <NA> 1953    M      2009
     3    2002-08-27          MSYR     Serbien 1976    M      2016
     4    2004-07-01          <NA>        <NA> 1943    F      2016
     5    2005-05-30           MKS      Kosovo 1977    F      2020
