Arthur Camberlein >> SEO & Data articles >> Skipping last column in R while `read.csv`

Skipping last column in R while `read.csv`

Written by Arthur Camberlein | Published on & updated on

Skipping last column in R while `read.csv` should be done in two steps

data <- read.csv("test12.csv")
data
data[,-ncol(data)]

That is when you don't know the number of columns. If you explicitly know, use the code below instead:

df <- read.csv("test12.csv")[,-3]

This solution come from a stackoverflow post I did https://stackoverflow.com/questions/48597844/skipping-last-column-in-r-with-read-csv & could be related to another ask such as https://stackoverflow.com/questions/5788117/only-read-selected-columns to only read selected columns in R.  (not from me this time)

Back to blog

Learn more with the article FAQ

Skipping last column in R while `read.csv` - FAQs

Blog post taggued in: Data, R

Written by