Operations with data modes and object types in R

From AWF-Wiki
(Difference between revisions)
Jump to: navigation, search
(Created page with "==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'...")
 
(Blanked the page)
 
Line 1: Line 1:
==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] TRUE
 
 
is.factor(a)
 
 
## [1] FALSE
 
 
f <- as.factor(a)
 
mode(f)
 
 
## [1] "numeric"
 
 
mode(e)
 
 
## [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] "data.frame"
 
 
str(d)
 
 
## 'data.frame': 3 obs. of 4 variables:
 
##  $ A: num  1 2 3
 
##  $ B: num  4 5 6
 
##  $ C: chr  "low" "medium" "high"
 
##  $ E: num  7 8 9
 

Latest revision as of 17:13, 31 January 2015

Personal tools
Namespaces

Variants
Actions
Navigation
Development
Toolbox
Print/export