0

I'm new to R so I apologize if my terminology is incorrect here. I have a .csv file that has two rows with irrelevant information (the date, and another global header) and then has the relevant data starting at row 3 with all the column headers. I have figured out that the code

my.files <- list.files()
file <- readLines(my.files[1])
temp2 <- data.frame((file[-c(1,2)]))

removes the first two rows of data and stores the remaining rows in a data frame, however, the data frame that is saved only has one column with each of the intended columns separated by a comma: "Frame ID,Delta Time, Head Pos X, Head Pos Y, Head Pos Z..." The rows beneath have the correct responses, but are similarly squished into a single column separated by commas.

How do I either 1) rewrite the above code to end with a matrix that is missing the first two rows, or 2) separate a single column that is comma delimited into multiple columns within a data frame?

I have seen the strsplit() function but have not been able to apply it appropriately.

akrun
  • 874,273
  • 37
  • 540
  • 662
domwill
  • 11
  • 3
  • 2
    It's easier to help you if you include a simple [reproducible example](https://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example) with sample input and desired output that can be used to test and verify possible solutions. Maybe just use `read.csv(...., skip=2)` to skip the first two rows? It will probably parse the rest of the file just fine. – MrFlick Feb 21 '23 at 20:20

1 Answers1

1

Try this:

data <- read.table("path to file", skip = 2, header = TRUE, sep = ',')

It will read the file, after skipping 2 lines and the 3rd will be the header

Lucas
  • 302
  • 8