我正在从一个HOBOware记录器下载文件,它产生的CSV是杂乱的。我需要删除第1、5-8列,并跳过第一行。
有很多文件,我试图一次上传它们,但跳过行给我带来了问题
多亏了另一个线程,我几乎可以做我想做的事情,但是CSV中的一个空白行导致数据无法正确上载,从而创建了空白单元格
这是单独读取每个CSV时运行的代码
library(readr)
Pool_620180212 <- read_csv("Pool 6/Pool_620180212.csv",
col_types = cols(`Date Time, GMT-05:00` = col_datetime(format = "%m/%d/%y %H:%M:%S")),
skip = 1)因此,我认为我可以通过执行以下操作来克服它
setwd("C:/Users/Christopher/Desktop/NEW R/Converted HOBO files")
mydir = "Pool 6"
myfiles = list.files(path=mydir, pattern="*.csv", full.names=TRUE, Skip = 1)我不知道如何格式化参数以包含以下格式,以便每个CSV都能够正确读取
"col_types = cols(`Date Time, GMT-05:00` = col_datetime(format = "%m/%d/%y %H:%M:%S")),
skip = 1)"我对R没有太多的经验,所以任何删除不需要的列的建议也会很好,我一直在为每个列做这件事,这是非常麻烦的
file$column = NULL发布于 2019-06-15 03:44:20
试试这个:
library(data.table)
setwd("C:/Users/Christopher/Desktop/NEW R/Converted HOBO files")
x = lapply(list.files(pattern="*\\.csv"), function(x){
fread(x)
})%>% rbindlist()您可以删除循环后的列。
或者在循环中指定它:我不确定您的列是什么,但它将如下所示:
library(data.table)
library(lubridate)
setwd("C:/Users/Christopher/Desktop/NEW R/Converted HOBO files")
x = lapply(list.files(pattern="*\\.csv"), function(x){
fread(x)
x$date = ymd_hms(x$date)
x$col = NULL
})%>% rbindlist()https://stackoverflow.com/questions/56604217
复制相似问题