@@ -12,6 +12,8 @@ list.files()
12
12
# ###########
13
13
14
14
15
+ # --------------------------------------------------
16
+
15
17
# ###########
16
18
?read.table
17
19
?read.csv
@@ -41,12 +43,18 @@ set3 <- read.table("../../data/readin/ReadMeIn3.txt",
41
43
sep = ' ,' ,
42
44
na.strings = ' ' )
43
45
46
+ # --------------------------------------------------
47
+
44
48
# #################
49
+ # write data to file
50
+ # Options largely the same as their read counterparts
51
+ # row.names = FALSE is helpful to avoid have 1,2,3,... as a variable/column
52
+
45
53
?write.csv
46
- # # write.csv(myRObject,
47
- # # file="/path/to/save/spot/file.csv",
48
- # # row.names=FALSE)
54
+ write.csv(myRObject , file = " /path/to/save/spot/file.csv" , row.names = FALSE )
49
55
56
+ # --------------------------------------------------
57
+ # saveRDS/readRDS are used to save (compressed version of) individual R objects
50
58
# # # save our data set
51
59
saveRDS(set1 ,file = " TstObj.rds" )
52
60
# # # get it back
@@ -55,13 +63,23 @@ newtst <- readRDS("TstObj.rds")
55
63
my.vector <- c(1 ,8 ,- 100 )
56
64
saveRDS(my.vector , file = " JustAVector.rds" )
57
65
66
+
67
+ # --------------------------------------------------
68
+
69
+ # We can save all variables in the current R workspace with save.image We can load in a saved workspace with load
70
+ # R will ask you save your work when you exit
71
+
58
72
# # # Save all our work
59
73
save.image(" AllMyWork.RData" )
60
74
# # # Reload it
61
75
load(" AllMyWork.RData" )
62
76
# # # name given to default save
63
77
# load(".RData")
64
78
79
+
80
+ # --------------------------------------------------
81
+ # Let us learb some basic operations of R
82
+
65
83
# numeric types: interger, double
66
84
348
67
85
# character
@@ -79,7 +97,7 @@ TRUE | FALSE
79
97
# &, |, !
80
98
# <,>,<=,>=, ==, !=
81
99
82
- # # ----datatypes2----------------------------------------------------------
100
+ # # ---- datatypes2 ----------------------------------------------------------
83
101
# variables assignment is done with the <- operator
84
102
my.number <- 483
85
103
# the '.' above does nothing. we could have done:
@@ -175,11 +193,16 @@ named.list <- list(Item1="my string",
175
193
# [[]] also works
176
194
c(named.list $ Item1 ,named.list [[1 ]])
177
195
196
+
197
+ # ---------------------------------------------------
198
+ # ---------------------------------------------------
178
199
# # ----get iris dataset
179
200
data(" iris" )
180
201
head(iris )
181
202
str(iris )
182
203
204
+ # Note iris is a data.frame data type; this is simply a list.
205
+
183
206
# # ----pca1
184
207
data(" iris" )
185
208
# get numeric portions of list and make a matrix
0 commit comments