Tuesday, October 12, 2004
In R, how to enumerate a data.frame column by column? The pseudo code is like
foreach col ( data.frame ) {
process col;
store processed col elsewhere
}
There is probably some cooler way to do this but here is what I do:
foreach col ( data.frame ) {
process col;
store processed col elsewhere
}
There is probably some cooler way to do this but here is what I do:
numColumns <- dim(myDataFrame)[2]
for (i in 1:numColumns) {
myColumn <- myDataFrame[,i]
do stuff to myColumn
}
Also related, how to find out the index of the last row/element of a data.frame/vector?
See the "dim" command above. D.