I've got a data set in csv. Unfortunately each line has different amount of "," commas. I am interested in importing only first 3 and last 3 variables from the file in R.
in example:
> line: "A","B","C","D",...,"X",Y","Z"
I want to achieve the following `
> line: "A","B","C","X","Y","Z"
I tried to use grep, to find - by using of regural expressions - first 3 variables:
new_data <- grep("([^,]+)(,[^,]+){2}", dataset, values=TRUE)
After that operation it shows me all lines in which that expression exists.
How can I remove the following variables in the line using grep, if it is possible, how can I remove the whole interval (each variable from <3;n-3>).
Do you now other method to solve that problem?