Operations with data modes and object types in R

From AWF-Wiki
Revision as of 15:45, 25 January 2015 by Aknop (Talk | contribs)

(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to: navigation, search

Operations with data modes and object types in R

Consulting and changing data modes is very easy. Below some examples for checking the data mode of the object a and change it to as a factor.

is.numeric(a)

    1. [1] TRUE

is.factor(a)

    1. [1] FALSE

f <- as.factor(a) mode(f)

    1. [1] "numeric"

mode(e)

    1. [1] "logical"

An example of transformation from matrix to dataframe was already shown in Types of Objects in R. Another option to do the same is shown below. The type and the structure (of the d object) is also shown below.

d.1 <- as.data.frame(m) class(d.1)

    1. [1] "data.frame"

str(d)

    1. 'data.frame': 3 obs. of 4 variables:
    2. $ A: num 1 2 3 ## $ B: num 4 5 6
    3. $ C: chr "low" "medium" "high" ## $ E: num 7 8 9
Personal tools
Namespaces

Variants
Actions
Navigation
Development
Toolbox
Print/export