Skip to content

Instantly share code, notes, and snippets.

@AkiyukiOkayasu
Last active January 26, 2022 09:03
Show Gist options
  • Save AkiyukiOkayasu/8bb35a8517b8830e5ec932c3473cfd34 to your computer and use it in GitHub Desktop.
Save AkiyukiOkayasu/8bb35a8517b8830e5ec932c3473cfd34 to your computer and use it in GitHub Desktop.
大量のCSVファイルをSAVファイルに変換する
#install.packages("tidyverse")#ライブラリのインストール(初回のみ)
library(haven)
print(getwd())# 作業ディレクトリ
l <- list.files(pattern=".csv")# CSVファイルを検索、リスト化
for (e in l) {
print(paste0(e, ".sav"))
df <- read.csv(e)#CSV読み込み
write_sav(df, paste0(e, ".sav"))#SAV書き出し
}
find . -name "*.csv" | xargs sed -i "" "s/,\$//"
find . -name "*.csv" | xargs nkf -w --overwrite -d; find . -name "*.csv" | xargs sed -i "" "s/,\$//"
find . -name "*.csv" | xargs nkf -w --overwrite -d
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment