I am trying to add a row NewRow to each matrix in a list mylist. NewRow should be a vector of integers from 1 until the end of the row. Each matrix in mylist has a different number of columns, so the last number in the NewRow vector isn't constant, it has to be dynamic. These are my attempts:
mylist.with.new.row <- lapply(mylist, rbind, NewRow = 1:ncol())
mylist.with.new.row <- lapply(mylist, rbind, NewRow = 1:ncol(mylist))
Neither work because ncol() can't be empty, but also can't just be ncol(mylist) because it has to be dynamic.
I assume this can be done with a loop but I'm hoping someone knows a quicker way.
Thanks!