A basic understanding of data types and data structures and how to operate on those allows you to write better and more efficient code. Note that everything in R is an object. A good conceptual understanding of objects is important because manipulation of objects is a very common task.
R has six atomic vector types (atomic means that the vector only holds data of a single type and vectors can be thought of as contiguous cells containing data).
character
, e.g. “Berlin”, “R is awesome”numeric
(real or decimal), e.g. 14, 22.598integer
, e.g. 5L (the L tells R to store this as an
integer)logical
, e.g. TRUE, FALSEcomplex
, e.g. 1+6i (complex numbers with real and
imaginary parts)Objects can have attributes, which include:
names
dimnames
dim
class
attributes
(contain metadata)Note that more specialized R-objects such as objects referring to spatial data or time series data, among others, may have very different attributes.
R provides many functions to examine features of vectors and other objects, for example
class()
str()
typeof()
length()
dim()
attributes()
Citation
The E-Learning project SOGA-R was developed at the Department of Earth Sciences by Kai Hartmann, Joachim Krois and Annette Rudolph. You can reach us via mail by soga[at]zedat.fu-berlin.de.
Please cite as follow: Hartmann, K., Krois, J., Rudolph, A. (2023): Statistics and Geodata Analysis using R (SOGA-R). Department of Earth Sciences, Freie Universitaet Berlin.