gpt4 book ai didi

r - 在一个窗口中绘制多个 csv 文件

转载 作者:行者123 更新时间:2023-12-01 01:00:24 29 4
gpt4 key购买 nike

我有一个 701 的列表 csv文件。每个都有相同数量的列 (7) 但不同的行数(在 25000 和 28000 之间)。

这是第一个文件的摘录:

Date,Week,Week Day,Hour,Price,Volume,Sale/Purchase
18/03/2011,11,5,1,-3000.00,17416,Sell
18/03/2011,11,5,1,-1001.10,17427,Sell
18/03/2011,11,5,1,-1000.00,18055,Sell
18/03/2011,11,5,1,-500.10,18057,Sell
18/03/2011,11,5,1,-500.00,18064,Sell
18/03/2011,11,5,1,-400.10,18066,Sell
18/03/2011,11,5,1,-400.00,18066,Sell
18/03/2011,11,5,1,-300.10,18068,Sell
18/03/2011,11,5,1,-300.00,18118,Sell

现在我正在尝试绘制 VolumeDate条件是 Price正是 200.00 .然后我试图获得一个窗口,在那里我可以看到随着时间的推移音量的进度。
allenamen <- dir(pattern="*.csv")
alledat <- lapply(allenamen, read.csv, header = TRUE,
sep = ",", stringsAsFactors = FALSE)
verlauf <- function(a) {plot(Volume ~ Date, a,
data=subset(a, (Price=="200.00")),
ylim = c(15000, 45000),
xlim = as.Date(c("2011-12-30", "2013-01-20")), type = "l")}
lapply(alledat, verlauf)

但我收到此错误:
error in strsplit(log, NULL): non-character argument

我怎样才能避免错误?

最佳答案

当您想组合 Price==200 的所有子集时成一个图,您可以使用以下功能:

plotprice <- function(x) {
files <- list.files(pattern="*.csv")
df <- data.frame()
for(i in 1:length(files)){
xx <- read.csv(as.character(files[i]))
xx <- subset(xx, Price==x)
df <- rbind(df, xx)
}
df$Date <- as.Date(as.character(df$Date), format="%d/%m/%Y")
plot(Volume ~ Date, df, ylim = c(15000, 45000), xlim = as.Date(c("2011-12-30", "2013-01-20")), type = "l")
}

plotprice(200)您将在一个情节中获得所有内容 Price==200 .

当您想要每个 csv 的绘图时文件,您可以使用:
ploteach <- function(x) {
files <- list.files(pattern="*.csv")
for(i in 1:length(files)){
df <- read.csv(as.character(files[i]))
df <- subset(df, Price==x)
df$Date <- as.Date(as.character(df$Date), format="%d/%m/%Y")
plot(Volume ~ Date, df, ylim = c(15000, 45000), xlim = as.Date(c("2011-12-30", "2013-01-20")), type = "l")
}
}

ploteach(200)

关于r - 在一个窗口中绘制多个 csv 文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23930683/

29 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com