Using utils and the foreign packages
Data is generally available in an external file. The types of external files are certainly varied and it is important to learn which of them may be imported into R. The probable spreadsheet files may exist in a comma separated variable (CSV)
format, XLS or XLSX (Microsoft Excel) form, or ODS (OpenOffice/LibreOffice Calc) ones. There are more possible formats but we restrict our attention to these described previously. A snapshot of two files, Employ.dat
and SCV.csv
, in gedit and MS Excel are given in the following screenshot. The brief characteristics of the two files are summarized in the following list:
- The first row lists the names of the variables of the dataset
- Each observation begins on a new line
- In the DAT file, the delimiter is a tab (
\t
), whereas for the CSV file, it is a comma (,
) - All three columns of the DAT file are numeric in nature
- The first five columns of the CSV file are numeric while the last column is character
- Overall, both the files...