R 在ggplot中打印来自多个大型数据文件的数据

R 在ggplot中打印来自多个大型数据文件的数据,r,ggplot2,R,Ggplot2,我有几个数据文件(数字),大约有150000行和25列。在我使用gnuplot(其中脚本行是成比例的plot对象)来绘制数据之前,但由于我现在必须使用它进行一些额外的分析,我移动到了R和ggplot2 如何组织数据,思考?是否只有一个big data.frame和一个附加列来标记数据来自哪个文件才是唯一的选项?还是有办法解决这个问题 编辑:更准确地说,我将举一个我现在拥有数据的形式的例子: filelst=c("filea.dat", "fileb.dat", "filec.dat") dat=

我有几个数据文件(数字),大约有150000行和25列。在我使用gnuplot(其中脚本行是成比例的plot对象)来绘制数据之前,但由于我现在必须使用它进行一些额外的分析,我移动到了R和ggplot2

如何组织数据,思考?是否只有一个big data.frame和一个附加列来标记数据来自哪个文件才是唯一的选项?还是有办法解决这个问题

编辑:更准确地说,我将举一个我现在拥有数据的形式的例子:

filelst=c("filea.dat", "fileb.dat", "filec.dat")
dat=c()
for(i in 1:length(filelst)) {
    dat[[i]]=read.table(file[i])
}

你的问题有点含糊。如果我遵循正确的方法,我认为您有三个主要选择:

  • 按照您的建议进行操作,然后使用R中存在的任何一个“拆分-应用-合并”功能按组进行分析。这些功能可能包括
    by
    aggregate
    ave
    package(plyr)
    package(data.table)
    和许多其他功能
  • 将数据对象作为单独的元素存储在
    列表()
    中。然后使用
    lappy()
    和朋友对其进行操作
  • 在不同的数据对象中保持所有内容的独立性,并分别处理它们。这可能是最低效的做事方式,除非你有内存限制等等

  • 假设文件名以“.dat”结尾,下面是Chase提出的策略的一个模拟示例

    require(plyr)
    
    # list the files
    lf = list.files(pattern = "\.dat")
    str(lf)
    
    # 1. read the files into a data.frame
    d = ldply(lf, read.table, header = TRUE, skip = 1) # or whatever options to read
    str(d) # should contain all the data, and and ID column called L1
    
    # use the data, e.g. plot
    pdf("all.pdf")
    d_ply(d, "L1", plot, t="l")
    dev.off()
    # or using ggplot2
    ggplot(d, aes(x, y, colour=L1)) + geom_line()
    
    # 2. read the files into a list
    
    ld = lapply(lf, read.table, header = TRUE, skip = 1) # or whatever options to read
    names(ld) = gsub("\.dat", "", lf) # strip the file extension
    str(ld) 
    
    # use the data, e.g. plot
    pdf("all2.pdf")
    lapply(names(l), function(ii) plot(l[[ii]], main=ii), t="l")
    dev.off()
    
    # 3. is not fun
    

    谢谢那有帮助!你能就前两点举个例子吗?