-
Notifications
You must be signed in to change notification settings - Fork 0
/
data_types0.r
executable file
·34 lines (32 loc) · 1003 Bytes
/
data_types0.r
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
#!/usr/bin/env Rscript
## frequent data types:
## * Vectors c() or vector(mode = "logical", length = 0)
cat("vectors always give the type of data stored in them as class\n")
cat("vector(mode=\"integer\",length=10):",vector(mode="integer",length=10),"\n")
a <- vector(mode="integer",length=10)
cat("a == ",a,"\n")
a <- 1:10
cat("a <- 1:10, a == ",a,"\n")
## * Lists list()
cat(class(list()),"\n")
## * Matrices matrix()
cat(class(matrix()),"(matrices have a type)\n")
## * Arrays array()
cat(class(array(c(1,2,3))),"\n")
## * Factors factor()
cat(class(factor()),"\n")
cat("Number of factors in mtcars$cyl:",nlevels(factor(mtcars$cyl)),"\n")
## * Data Frames data.frame()
cat(class(data.frame()),"\n")
cat(str(data.frame(nums = c(1,2,3),
chars = c('a','b','c'),
logicals = c(T,F,T)
)
),"\n")
cat("Atomic data types:\n")
cat(class(T),"\n")
cat(class(1),"\n")
cat(class(1L),"\n")
cat(class(2+3i),"\n")
cat(class('a'),"\n")
cat(class(charToRaw('a')),"\n")