不积跬步无以至千里,不积小流无以成江海

 Administrator     2022-10-26      小工具      4550

R批量将XPT文件,批量转成csv格式

先读取文件名,再用一个循环批量转换。

library(haven)

temp_path = list.files('./data3')
print(temp_path)
for (i in temp_path) {
  # format(i)
  i_temp = paste("C:/Users/BIN/Desktop/R delt/data3/",i,sep = "", collapse = NULL)
  j_temp = paste("C:/Users/BIN/Desktop/R delt/data3/",i,'.csv',sep = "", collapse = NULL)
  print(i_temp)
  mydata <- read_xpt(i_temp)
  write.csv(mydata, j_temp)
}