Using Excel we prepare a data table as a spreadsheet
and save it as a CSV (Comma Separated Values) file ex1.csv
. In it values are separated with semicolon ; .
lab;U;V a;1;1 b;2;3 c;3;2 d;5;3 e;5;5
At the beginning of the file we can add some additional information - metadata. For example ex2.csv
Example from 7ISS - June 2017 Vladimir Batagelj lab;U;V a;1;1 b;2;3 c;3;2 d;5;3 e;5;5
Such a file can be prepared also manually using some text editor, or as an output from some program.
Using help(read.table) we learn that the right function for reading our file is read.csv2() and that we have to include some additional parameters:
> H <- read.csv2("ex2.csv",skip=2,row.names=1) > H U V a 1 1 b 2 3 c 3 2 d 5 3 e 5 5
See also:
Searching on Google we also learn that we could read into R also directly from the Excel file.
library(gdata) D <- read.xls("ex1.xls")
In older data sets the fixed width format was often used. To read such data see