Using nested apply functions instead of nested for loops
Clash Royale CLAN TAG #URR8PPP Using nested apply functions instead of nested for loops My objective here was to iterate across each column in a df and then for each column iterate down each row and perform a function. The specific function in this case replaces the NA values with the corresponding value in the final column, but the details of the function required are not relevant to the question here. I got the results I needed using two nested for loops like this: df NA for (j in 1:ncol(df.i)) { for (i in 1:nrow(df.i)) { df.i[i,j] <- ifelse(is.na(df.i[i,j]), df.i[i,39], df.i[i,j]) } } However, I believe this should be possible using an apply(df.i, 1, function) nested within an apply(df.i, 2, function) But I'm not totally sure that is possible or how to do it. Does anyone know how to achieve the same thing with a nested use of the apply function? apply(df.i, 1, function) apply(df.i, 2, function) apply ifelse is a vectorized function, s...