CSV 파일 불러오기
csv 파일 불러오기
1
2
3
4
# 영어컬럼 불러올때 latin1으로 설정하기
# 한글컬럼 불러올때 encoding = 'euc-kr'
a<-read.csv('ex_comma.csv', header=T, sep=',', encoding='latin1', na.strings="-")
a
name | gender | math | english | korean | attend |
---|---|---|---|---|---|
PARK | F | 65 | 80 | 100 | FALSE |
HAN | M | 75 | 60 | 80 | TRUE |
LEE | F | 80 | 100 | 70 | FALSE |
SHIN | M | 95 | 70 | 100 | TRUE |
KIM | M | 100 | 80 | 50 | TRUE |
1
2
3
# csv파일 데이터가 한열에 모두 있을때 sep='\t'
b<-read.csv('ex_tab.csv', header=T, sep='\t', encoding='latin1')
b
name | gender | math | english | korean | attend |
---|---|---|---|---|---|
PARK | F | 65 | 80 | 100 | FALSE |
HAN | M | 75 | 60 | 80 | TRUE |
LEE | F | 80 | 100 | 70 | FALSE |
SHIN | M | 95 | 70 | 100 | TRUE |
KIM | M | 100 | 80 | 50 | TRUE |
1
2
c<-read.csv(file.choose(), header=T, sep=',', encoding='latin1')
c
1
2
3
4
5
6
7
8
9
10
Error in file.choose(): 파일선택이 취소되었습니다
Traceback:
1. read.csv(file.choose(), header = T, sep = ",", encoding = "latin1")
2. read.table(file = file, header = header, sep = sep, quote = quote,
. dec = dec, fill = fill, comment.char = comment.char, ...)
3. file.choose()
1
2
install.packages("xlsx")
library(xlsx)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
also installing the dependencies 'rJava', 'xlsxjars'
There is a binary version available but the source version is later:
binary source needs_compilation
rJava 1.0-4 1.0-6 TRUE
Binaries will be installed
package 'rJava' successfully unpacked and MD5 sums checked
package 'xlsxjars' successfully unpacked and MD5 sums checked
package 'xlsx' successfully unpacked and MD5 sums checked
The downloaded binary packages are in
C:\Users\MyCom\AppData\Local\Temp\Rtmp0EJhGB\downloaded_packages
Warning message:
"package 'xlsx' was built under R version 3.6.3"
1
2
d<-read.xlsx('ex_xlsx.xlsx', sheetIndex=1, encoding='UTF-8')
d
name | gender | math | english | korean | attend |
---|---|---|---|---|---|
PARK | F | 65 | 80 | 100 | FALSE |
HAN | M | 75 | 60 | 80 | TRUE |
LEE | F | 80 | 100 | 70 | FALSE |
SHIN | M | 95 | 70 | 100 | TRUE |
KIM | M | 100 | 80 | 50 | TRUE |
1
2
d$total <- d$math + d$english + d$korean
d
name | gender | math | english | korean | attend | total |
---|---|---|---|---|---|---|
PARK | F | 65 | 80 | 100 | FALSE | 245 |
HAN | M | 75 | 60 | 80 | TRUE | 215 |
LEE | F | 80 | 100 | 70 | FALSE | 250 |
SHIN | M | 95 | 70 | 100 | TRUE | 265 |
KIM | M | 100 | 80 | 50 | TRUE | 230 |
1
2
3
#csv 파일 저장 하고 쓰기
write.table(d, 'save_sample.csv', row.names=FALSE, quote=FALSE, sep=',')
Leave a comment