r 将每个因子的表导出到zip文件中

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了r 将每个因子的表导出到zip文件中相关的知识,希望对你有一定的参考价值。

#-- function to export tables per factor in a zip
writeTablesPerCat <- function(df, cat, fn, zip_flags = "-j", na_string = "", replace = TRUE){
	stopifnot(cat %in% colnames(df))
	df_ls <- split(df, df[[cat]])
	names(df_ls) <- tolower(gsub(" ", "-", names(df_ls)))
	files <- sapply(names(df_ls), function(x) paste0(tempdir(), "/", basename(fn), "-", x, ".txt"))
	for(i in names(df_ls)){
		write_tsv(df_ls[[i]][,!colnames(df_ls[[i]]) %in% cat], files[i], na = na_string)
	}
	if(replace == TRUE){
		suppressWarnings(file.remove(paste0(fn, ".zip")))
	}
	zip(paste0(fn, ".zip"), files, flags = zip_flags)
	file.remove(files)
}

以上是关于r 将每个因子的表导出到zip文件中的主要内容,如果未能解决你的问题,请参考以下文章