R
[R] 세로 열 문자열을 한 줄로 된 문자열로 변경
'김용환'
2015. 8. 18. 15:27
R에서 세로 열 문자열을 한 줄로 된 문자열로 변경하는 예이다.
scan, paste0을 이용하면 쉽게 바꿀 수 있다.
category.txt 에 다음 내용의 파일이 존재한다.
airport
amusement_park
aquarium
art_gallery
bakery
bar
,,,
소스
scanned <- scan("category.txt", what="")
pasted <- paste0("\"", paste0(scanned, collapse="\",\""), "\"")
writeLines(text=pasted, "cc.txt")
결과 (cc.txt)
"airport","amusement_park","aquarium","art_gallery","bakery","bar",...