在一个窗口中绘制许多csv文件 [英] Plot many csv files in one window

查看:144
本文介绍了在一个窗口中绘制许多csv文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个列表701给出 csv 文件。



这里是第一个文件的提取:

 日期,星期,星期,小时,价格,音量,销售/购买
18/03 / 2011,11,5 ,1,-3000.00,17416,卖
18/03 / 2011,11,5,1,-1001.10,17427,卖
18/03 / 2011,11,5,1,-1000.00, 18055,卖
18/03 / 2011,11,5,1,-500.10,18057,卖
18/03 / 2011,11,5,1,-500.00,18064,卖
18/03 / 2011,11,5,1,-400.10,18066,卖
18/03 / 2011,11,5,1,-400.00,18066,卖
18/03/2011 ,11,5,1,-300.10,18068,卖
18/03 / 2011,11,5,1,-300.00,18118,卖

现在我试图绘制 Volume Date 条件是 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)

但我收到此错误:

  strsplit中的错误(log,NULL):非字符参数

Price == 200

当你想合并的所有子集时,错误?

到一个图中,您可以使用以下函数:

  plotprice<  -  function(x){
文件< - 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 df,ylim = c(15000,45000),xlim = as.Date(c(2011-12-30,2013-01-20)),type =l)
}

使用 plotprice(200) 价格== 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 $ Date),format =%d /%m /%Y)
plot(Volume〜Date,df,ylim = c(15000,45000),xlim = as.Date(c -30,2013-01-20)),type =l)
}
}

ploteach(200)


I have a list of 701 given csv files. Each one has the same number of columns (7) but different number of rows (between 25000 and 28000).

Here is an extract of the first file:

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

Now I am trying to plot Volume and Date on condition that the Price is exactly 200.00. And then I am trying to get one window where I can see the progress of the Volume over the time.

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)

But I get this error:

error in strsplit(log, NULL): non-character argument

How can I avoid the error?

解决方案

When you want to combine all subsets for Price==200 into one plot, you can use the following function:

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")
}

With plotprice(200) you will everything in one plot for Price==200.


When you want a plot for each csv file, you can use:

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)

这篇关于在一个窗口中绘制许多csv文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆