scan vs. readLines

Published by onesixx on

http://www.ats.ucla.edu/stat/r/modules/raw_data.htm
http://www.clemson.edu/economics/faculty/wilson/R-tutorial/data.html

scan()   같은 type 일때나 같은 type으로 읽기=>what으로 type설정
라인별 separator 설정가능(sep=”\n”), 파일을 읽는 가장 빠른 방법
readLines()   헤더에 숫자와 문자 섞여 있는 경우 유용

scan(file="", what=double(), sep="", n=-1, nmax=-1,
     encoding="unknown", skipNul=FALSE,
     quote=if(identical(sep, "\n")) "" else "'\"", dec = ".",
     skip=0, nlines=0, na.strings="NA",
     flush=F, fill=F, strip.white=F, quiet=F, blank.lines.skip=T, multi.line=T,
     comment.char="", allowEscapes=F, fileEncoding="", text)

readLines(con=stdin(), n=-1L, 
          encoding="unknown", skipNul=F,ok=T, warn=T)
  • 데이터 문자일 경우, 꼭 what=”character”지정
  • n=읽어들일 데이터 최대갯수, nlines=읽어들일 라인의 갯수, skip=지정한 갯수만큼 라인 건너뜀
R
R

scan()을 사용해 행단위로 읽기
matrix( , byrow=) 행렬의 원소를 행단위로, 파일내 행렬

R

ex)

https://stackoverflow.com/questions/29803117/in-r-how-to-read-file-with-custom-end-of-line-eol
Plain Text
R
R
R

Categories: Reshaping

onesixx

Blog Owner