12.07.2015 Views

R dummies

R dummies

R dummies

SHOW MORE
SHOW LESS
  • No tags were found...

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

‘data.frame’: 10 obs. of 9 variables:$ Atomic.number: int 1 2 3 4 5 6 7 8 9 10$ Name : chr “Hydrogen” “Helium” “Lithium” “Beryllium” ...$ Symbol : chr “H” “He” “Li” “Be” ...$ Group : int 1 18 1 2 13 14 15 16 17 18$ Period : int 1 1 2 2 2 2 2 2 2 2$ Block : chr “s” “s” “s” “s” ...$ State.at.STP : chr “Gas” “Gas” “Solid” “Solid” ...$ Occurrence : chr “Primordial” “Primordial” “Primordial” “Primordial”...$ Description : chr “Non-metal” “Noble gas” “Alkali metal” “Alkalineearth metal” ...If you have a file in the EU format mentioned earlier (where commas areused as decimal separators and semicolons are used as field separators), youneed to import it to R using the read.csv2() function.Using read.table() to import tabular data in text filesThe CSV format, described in the previous section, is a special case of tabulardata in text files. In general, text files can use a multitude of options to distinguishbetween data elements. For example, instead of using commas, another format isto use tab characters as the separator between columns of data. If you have a tabdelimitedfile, you can use read.delim() to read your data.The functions read.csv(), read.csv2(), and read.delim() are special cases ofthe multipurpose read.table() function that can deal with a wide variety of datafile formats. The read.table() function has a number of arguments that give youfine control over the specification of the text file you want to import. Here aresome of these arguments:header: If the file contains column names in the first row, specify TRUE.sep: The data separator (for example, sep=”,” for CSV files or sep=”\t” for tabseparatedfiles).quote: By default, strings are enclosed in double quotation marks (“). If the textfile uses single quotation marks, you can specify this as the argument to quote(for example, quote=”’”, a single quote embedded between double quotes).

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!