我在编写输出数据时遇到问题。我做了这样的指示:
myfiles <- list.files("D:/dolnyslask/2011/after", pattern=".csv")
for (j in 1:length(myfiles)) {
thisfile <- read.csv(myfiles[j], header = T, sep=";", na.string="NA", comment.char="")
for (i in thisfile) {
x = sd(i, na.rm=T)
y = length (na.omit(i))
if (y == 0) {
cat(paste(rep(c("-"),11)), file=myfiles[j], append=T, sep="\t")
cat(paste(length(na.omit(i))), file=myfiles[j], append=T, sep="\n")
} else if (is.na(x) || x == 0) {
cat(paste(format(min(i, na.rm=T)), format(mean(i, na.rm=T)), format(max(i, na.rm=T)), format(median(i, na.rm=T)), format(sd(i, na.rm=T)), format(mean(i, na.rm=T)), format(mean(i, na.rm=T)), format(mean(i, na.rm=T) - mean(i, na.rm=T)), format(mean(i, na.rm=T) - mean(i, na.rm=T)), format((mean(i, na.rm=T) - mean(i, na.rm=T))/median(i, na.rm=T)), format((mean(i, na.rm=T) - mean(i, na.rm=T))/median(i, na.rm=T)), digits=5), file=myfiles[j], append=T, sep="\t")
cat(paste(length(na.omit(i))), file=myfiles[j], append=T, sep="\n")
} else {
cat(paste(format(min(i, na.rm=T)), format(mean(i, na.rm=T)), format(max(i, na.rm=T)), format(median(i, na.rm=T)), format(sd(i, na.rm=T)), format(t.test(na.omit(i), conf.level=0.90)$conf.int), format(t.test(na.omit(i), conf.level=0.90)$conf.int - mean(i, na.rm=T)), format((t.test(na.omit(i), conf.level=0.90)$conf.int - mean(i, na.rm=T))/median(i, na.rm=T)), digits=5), file=myfiles[j], append=T, sep="\t")
cat(paste(length(na.omit(i))), file=myfiles[j], append=T, sep="\n")
}
}
}
我的 csv 文件如下所示:
NA NA NA NA NA NA 2 NA NA 12.1 NA
NA NA NA NA NA NA 4 NA NA 10 NA
NA NA NA NA NA NA 12.1 NA NA 8.5 NA
NA NA NA NA NA NA 14.8 NA NA 6 NA
NA NA NA NA NA NA 15 NA NA 7.4 NA
R 给我一个很好的结果,但只在一个单元格中(在 csv 文件中) - 但我需要在单独的列中的每一个。我试图改变“sep”的种类,但没有奏效。
我应该怎么办?