User Tools

Site Tools


Sidebar

Translations of this page:

Back to BIS-Schools

Biodiversity data analysis with R

Lectures

Worksheets

Code

Excursus

en:learning:schools:s01:excursus:ba-ex-02-01

E02-1: Data types and structures

You already have noticed that when reading tabulated data into R, the variable in which the data is stored is is of type data frame. In turn, each column of the data frame is of a certain data type. To give you a hand with this, a short overview on data types and structures is provided in the following.

Basic R data types

The basis R data types are:

  • Integer (integer value like 2)
  • Numeric (floating point value like 2.0)
  • Character (character like c)
  • Complex (complex number like -1 + 3i
  • Logical (Boolean, only TRUE or FALSE)

For more information on data types in general, have a look on the links in Wikipedia.

A quick look on R data structures

Data structures are used to store one to many individual values. In the following days, the two most important data structures we work with are the following:

  • Vectors
  • Data frame

Vectors: Think of vectors like a table which only consists of one column. Each row is one field of the vector and you can access the individual fields using an index number. In R, a vector is used for basically everything what holds a single data type (i.e. only numeric values or only characters etc.). If you want to learn more about vectors, see E00-1 Vectors.

Data frames: Think of data frames like a table in Excel. As in Excel, you can access each individual cell or mark entire columns or rows. Each column can have a different data type so you could store characters in e.g. the first column and numerical values in the second one etc. If you mix characters and numbers in one column, the column will always be of the character data type. If you want to learn more about data frames, see E00-2 Data frames.

For more information on data structures have a look at e.g. the respective data type site at Quick R. There you will also find an overview on how to get information about an object.

For converting data types, the respective Quick R's page is a good starting point.

You can identify a variable's data type or structure using the class function, e.g. class(<myVariable>)
en/learning/schools/s01/excursus/ba-ex-02-01.txt · Last modified: 2015/09/22 16:30 by tnauss