Save and Load Data in R

Created by Rischan Mafrur

Chonnam National University of South Korea

http://rischanlab.github.io

This is simple tutorial for saving and loading data to R. For example I assign the data to variable x

x <- 1:50

Show x

x
##  [1]  1  2  3  4  5  6  7  8  9 10 11 12 13 14 15 16 17 18 19 20 21 22 23
## [24] 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46
## [47] 47 48 49 50

And then save to /Users/macintosh/Rdata/

save(x, file="/Users/macintosh/Rdata/x.Rdata")

After we save the data, now I delete variable x

rm(x)

show x

x
## Error: object 'x' not found

Now we don't have variable x , so we load x from the x.Rdata

load("/Users/macintosh/Rdata/x.Rdata")

And the last one, show variable x, with command x or print(x)

x
##  [1]  1  2  3  4  5  6  7  8  9 10 11 12 13 14 15 16 17 18 19 20 21 22 23
## [24] 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46
## [47] 47 48 49 50
print(x)
##  [1]  1  2  3  4  5  6  7  8  9 10 11 12 13 14 15 16 17 18 19 20 21 22 23
## [24] 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46
## [47] 47 48 49 50

Oke finished, now we can save and load the data in R