Skip to content

Commit f290fed

Browse files
authored
Update R_Intro.R
1 parent 4c6ffc2 commit f290fed

File tree

1 file changed

+27
-4
lines changed

1 file changed

+27
-4
lines changed

R_Intro.R

Lines changed: 27 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@ list.files()
1212
############
1313

1414

15+
#--------------------------------------------------
16+
1517
############
1618
?read.table
1719
?read.csv
@@ -41,12 +43,18 @@ set3 <- read.table("../../data/readin/ReadMeIn3.txt",
4143
sep=',',
4244
na.strings = '')
4345

46+
#--------------------------------------------------
47+
4448
##################
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+
4553
?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)
4955

56+
#--------------------------------------------------
57+
# saveRDS/readRDS are used to save (compressed version of) individual R objects
5058
## # save our data set
5159
saveRDS(set1,file="TstObj.rds")
5260
## # get it back
@@ -55,13 +63,23 @@ newtst <- readRDS("TstObj.rds")
5563
my.vector <- c(1,8,-100)
5664
saveRDS(my.vector, file="JustAVector.rds")
5765

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+
5872
## # Save all our work
5973
save.image("AllMyWork.RData")
6074
## # Reload it
6175
load("AllMyWork.RData")
6276
## # name given to default save
6377
# load(".RData")
6478

79+
80+
#--------------------------------------------------
81+
# Let us learb some basic operations of R
82+
6583
# numeric types: interger, double
6684
348
6785
# character
@@ -79,7 +97,7 @@ TRUE | FALSE
7997
# &, |, !
8098
# <,>,<=,>=, ==, !=
8199

82-
## ----datatypes2----------------------------------------------------------
100+
## ---- datatypes2 ----------------------------------------------------------
83101
# variables assignment is done with the <- operator
84102
my.number <- 483
85103
# the '.' above does nothing. we could have done:
@@ -175,11 +193,16 @@ named.list <- list(Item1="my string",
175193
# [[]] also works
176194
c(named.list$Item1,named.list[[1]])
177195

196+
197+
# ---------------------------------------------------
198+
# ---------------------------------------------------
178199
## ----get iris dataset
179200
data("iris")
180201
head(iris)
181202
str(iris)
182203

204+
# Note iris is a data.frame data type; this is simply a list.
205+
183206
## ----pca1
184207
data("iris")
185208
# get numeric portions of list and make a matrix

0 commit comments

Comments
 (0)