0

I have a list that stores 142 data frames I have extracted the names of them into a vector

d.names[1] [1] "ACQ_C.XPT"

I used a function to create a true/false vector which contains a list of variables in each data frame that I wish to either keep or discard

d1[1] $ACQ_C.XPT SEQN ACD010A ACD010B ACD010C ACQ020 ACQ030 ACD040 ACQ050 ACQ060 ACD070 ACD080 TRUE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE

I wish to iteratively go down the list of the data frames and create data frames that include only those variables marked as true in vector d1

lapply(seq_along(d.names),function(i,x){as.data.frame(x[,rapply(d1[i], 
function(x) list(x))])x=d.names[i]})

Error: unexpected symbol in "lapply(seq_along(d.names),function(i,x){as.data.frame(x[,rapply(d1[i], function(x) list(x))])x"

M--
  • 25,431
  • 8
  • 61
  • 93
Abbas Ali
  • 1
  • 1
  • str(d[[1]]) 'data.frame': 7344 obs. of 11 variables: str(d[[142]]) 'data.frame': 6213 obs. of 42 variables: lapply(seq_along(d.names),function(i,x){as.data.frame(x[,rapply(d1[i], function(x) list(x))])},x=d) Error in x[, rapply(d1[i], function(x) list(x))] : incorrect number of dimensions Called from: as.data.frame(x[, rapply(d1[i], function(x) list(x))]) – Abbas Ali Aug 23 '17 at 21:11
  • I managed to get an output by using lapply(seq_along(d.names),function(i,x){as.data.frame((d[[i]])[,rapply(d1[i], function(x) list(x))])},x=d) now I need to iterate and add a dataframe name to each output ie d1[i] should be the name of each iteration – Abbas Ali Aug 23 '17 at 21:26

0 Answers0