read.file.fnc

Copy, Paste, Adapt

dat= read.file.fnc('dat.xls')

dat= read.file.fnc('dat.txt', have.names=T,

separator='tab', decimal=',', miss=-999,

skip=2, nrows=50)

dat= read.file.fnc('dat.Rdata')

dat= read.file.fnc('dat.sav')

Target

With this function you can read external files and incorporate them in a session in R. You can read txt files, *.excel (until 2007) files, *.spss binary files (. sav), R binaries (Rdata) and databases copied to the clipboard from another application like LibreOffice Calc.

EXCEL FILES (until 2007 version)

  1. The first row of the excel files must contain the columns name (or column number).

  2. Must be saved in Excel 97-2003 format (2010 DOES NOT WORK).

  3. If the file is in LibreOffice Calc you need to save it in Excel 97-2003 format.

attitude = read.file.fnc('example_excel.xls')

attitude = read.file.fnc('example_excel.xls', which.sheet=2)

Read the sheet 2 in the Excel file example excel.xls and it is assigned to the objetc attitude (by default which.sheet=1)

SPSS FILES

attitude = read.file.fnc('example_spss.sav')

attitude = read.file.fnc('example_spss.sav', label=F)

Read spss example example_spss.sav and omit value labels in the variables.

PLAIN TEXT FILES

dat = read.file.fnc('example_text.txt',

have.names=T,

separator='tab',

miss='')

This command read the file example_text.txt, assuming that the first row is made up of the names of the columns (have.names=T). These columns are separated by a tab (separator='tab'). Missing values are defined in the file by the empty cell ('').

Rdata FILES(R)

dat = read.file.fnc('example.Rdata')

Read binary file example.Rdata and assigns it to the object (data.frame) dat.

Import data from Clipboard

R can incorporate data copied from a spreadsheet just using as an argument the keyword file clipboard. This simply mark and copy the desired area in LibreOffice or Excel and then execute the following line in R.

dat=read.file.fnc('clipboard')

Mark and copy in Excel or LibreOffice the area to be exported

Reading the clipboard with default arguments

Note that we have marked the names of the variables in LibreOffice and decimals are defined with the comma character. As we used to read the clipboard without arguments the function has been assumed that no variable names in the first row, the decimal point is the character (.) and the column separator is space. To fix repeat the function call with the appropriate arguments. For this to succeed we must repeat back to LibreOffice or Excel again and copy back the data we want.

dat =read.file.fnc('clipboard', have.names=T,

decimal=',', separator='tab')