함수 | 기본값 | 설명 |
---|---|---|
read.table() | sep=””, header=FALSE | read txt file |
read.csv() | sep=”,”, header=TRUE | red csv file |
read.delim() | sep=”\t”, header=TRUE, dec=”,” | 탭 구분 기호를 사용한 파일 |
read.table(file=, header=F)
header: 특정 이름 부여
col.names의 길이가 col 수보다 하나 작은 경우 첫 col은 row.names로 간주
write.table(df, “filename”, row.names=T, col.names=T)
: 데이터프레임을 텍스트 파일로
read.csv(file=, header=T)
header=T 가 기본값
write.csv(df, file=, row.names=T, col.names=T)
scan(file=, what=, sep=” “)
비정형의 문자열 데이터 읽는 데 유용
what: read type
sep: 분리 기준, 디폴트는 빈칸
scan(file, what=””, sep=”\n”) - 행으로 분리, 빈 줄 무시, 문자열 벡터 리턴
readLines(file, n=) - 빈 줄 무시 X (n: 읽어올 줄 수)
with() 이 안에서 attach 한 것처럼 가능
with(abalone, boxplot(Length ~ Sex, main=”abalone”))
library(foreign)
read.spss()
library(xlsx)
read.xlsx()
library(readr)
read_csv(file=)
library(readxl)
read_excel()
library(openxlsx)
read.xlsx(”filename”, detectDates=TRUE) - 날짜를 숫자로 인식 방지
write.xlsx()
sink(”filename”) & sink() : 텍스트 출력 파일에 넣기
pdf(”filename”) & dev.off() : 그래픽 출력 파일에 넣기, windows() 못 씀
savePlot(”filename”, type=”png”)
그래픽 윈도우에 출력된 그래프를 파일로 저장, windows() 사용 가능
wordcloud(words, freq, scale=c(4,5), min.freq=3, max.words=Inf, random.order=TRUE, random.color=FALSE, rot.per=.1, colors=”black”,…)
word: 단어
freq: 빈도
scale: 최저빈도와 최고빈도 단어 사이 폰트 크기 차이
min.freq: 빈도 lower bound
max.words: 빈도 upper bound
random.order: TRUE - 랜덤 / FALSE - 빈도수 클수록 중앙에
random.color: TRUE - 랜덤 / FALSE - 빈도순
rot.per: 90도 회전된 각도로 출력되는 단어 비율
colors: 작은 빈도부터 큰 빈도까지의 단어 색
lyrics.1 <- gsub(",", "", lyrics)
lyrics.1 <- gsub("\\\\.", "", lyrics.1)
lyrics.1 <- gsub("\\\\!", "", lyrics.1)
lyrics.1 <- gsub("\\\\?", "", lyrics.1)
tab.1 <- tolwoer(lyrics.1)
wordcloud(words=names(tab.1), freq=tab.1, scale=c(5,0.5), min.freq=1, colors=rainbow(10), random.color=FALSE, random.order=FALSE, rot.per=0.25)
grep(pattern, doc, value=F, ignore.case=F)
doc에서 pattern이 있는 곳(인덱스)을 알려줌
value=T → 인덱스가 아니라 해당 문자열을 출력 (””로 감싸서 나옴)
ignore.case=T → 대소문자 구별 X
lyrics <- scan("yesterday.txt", what="")
grep("\\\\?", lyrics) # ?는 meta char라서 \\\\ 필요
# [1] 47 89