Skip to content
Prev 155225 / 398506 Next

how to address last and all but last column in dataframe

Not sure where your "input" came from. It's not in a format I would  
have expected of an R object and the first line is not in a form that  
would be particularly easy to read into a valid R object. Numbers are  
no legitimate object names. It's also not clear what you want to do  
with the duplicated line numbers at the beginning. Your question  
implies that you do not consider them part of the data.

In the future a worked example along the lines of that constructed by  
Jorge Ivan Velez in a recent answer to another question might increase  
chances of a prompt reply with tested code:

# Data set
DF=read.table(textConnection("V1 V2 V3
a    b    0:1:12
d    f    1:2:1
c    d    1:0:9
b    e    2:2:6
f    c    5:5:0"),header=TRUE)
closeAllConnections()

The "length" of a dataframe is the number of columns.

?length

Dataframes can be referenced using the extract operation e.g.   
df[<row>, <col>]

?Extract       # for additional information on indexing using  column  
vectors.

So:

video[ ,length(video)]  #should return the last column vector although  
it will be no longer be named.

The rest of the dataframe with intact column names could be obtained  
with:

video[  ,-length(video)]