Laboratory of Microbial Genomics and Big Data (강원대학교 미생물유전체빅데이터 연구실)

R: Basics - Data - Import and Export - by Eun Bae Kim (08/22/2018)
 Visits : 497,903 ( Your IP 18.116.80.206 )
 

 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: 
 35: 
 36: 
 37: 
 38: 
 39: 
 40: 
 41: 
 42: 
 43: 
 44: 
 45: 
 46: 
 47: 
 48: 
 49: 
 50: 
 51: 
 52: 
 53: 
 54: 
 55: 
 56: 
 57: 
 58: 
 59: 
 60: 
 61: 
 62: 
 63: 
 64: 
 65: 
 66: 
 67: 
 68: 
 69: 
setwd("C:/Users/ebkim/Desktop");
# Importing Text Data ############################################################
# setwd("working directory");
dfData1 = read.table("http://lab.gutdesigner.com/research_r_data/data0001.txt", header=TRUE);
dfData1
dfData2 = read.table("http://lab.gutdesigner.com/research_r_data/data0002.txt", header=TRUE);
dfData2
class(dfData1); class(dfData2)

dfData1[1,]
dfData2["EBKim", ]
dfData2[1,]

dfData2["EBKim", ]; mean(dfData2["EBKim", ]); sd(dfData2["EBKim", ])
numEBKim = as.numeric(dfData2["EBKim", ]);
numEBKim; mean(numEBKim); sd(numEBKim)

numEng = dfData2[ , "English"]
numEng; mean(numEng); sd(numEng)

# Transformation
as.character(numEng)
as.complex(numEng)
as.numeric(numEng)
as.double(numEng)
as.integer(numEng)
as.logical(numEng)      # 0 = FALSE




# Importing data from the Clipboard ################################################
# Copy your own table in a spreadsheet
dfData3 = read.delim("clipboard", sep=" "); dfData3



# Importing data from the text object
dfData4 = read.table(header = TRUE, text =
"Korean English Mathematics
EBKim 89 85 100
GDJin 87 70 80
JBPark 96 80 90
IHYou 88 100 85
JHWon 72 97 78
SJChoi 76 92 83")
dfData4




# Exporting Data ####################################################################
dfData4 = read.table(header = TRUE, text =
"Korean English Mathematics
EBKim 89 85 100
GDJin 87 70 80
JBPark 96 80 90
IHYou 88 100 85
JHWon 72 97 78
SJChoi 76 92 83")
dfData4

# Exporting as text files
write.table(dfData4, "saved_data.txt", sep="\t")

# Exporting as xls files
install.packages("xlsx")
library(xlsx)
write.xlsx(dfData4, "saved_data.xlsx")



Kangwon National University