How to create a table in R from a csv file?

时间:2015-06-25 09:58:48

标签: r csv

I have a csv file and am unsure how to get R to interpret it as a table because all the title info is in one cell and all the data relating to the titles is in a separate cell. So all the info I need is in 2 cells but it actually needs to be split up. enter image description here

The cell A3 has a value called 'Team' , this corresponds to the part in the cell A4 that says 'Visitor'. Then each part after than corresponds to the bit below it. ..sorry I don't know how to describe it, but ultimately it would look like this …

enter image description here

1 个答案:

答案 0 :(得分:0)

Looks like the field separator in your data is a ;

read.csv has a parameter sep to change the field separator and another parameter header to tell it there is an initial line containing the column names. Use read.csv like this:

data = read.csv(file="/mydir/myfile.csv", sep=";", header=T)

To test you can print out the first 5 lines of the data table with:

head(data,5)
相关问题