Skip to content
Prev 155224 / 398506 Next

how to address last and all but last column in dataframe

Hi Felix,
Doubtless there are other routes. Generally I use ?length to get the number
of columns. Then do your arithmetic within the indexing operator ?"[" to
select what you want.

## Dummy ex. to select first and last column of any data frame ( = DF )
DF[ , c(1, length( names( DF ) ) ) ]

## Dummy ex. to select first and penultimate column of any data frame
DF[ , c(1, length( names( DF ) ) -1 ) ]

HTH, Mark.
drflxms wrote: