【问题标题】:how to plot the data of one column in the listA which is contained in a listB already如何绘制列表中已经包含在列表中的一列的数据
【发布时间】:2016-06-10 12:59:26
【问题描述】:

我在提取数据并将它们一起列在 R 中时遇到问题。

我有 24 个文件:1.out24.out。所有 24 个文件都包含相同的 5 列,我想提取每个文件的第 5 列,然后将所有 24 个文件的第 5 列一起直方图。

temp = list.files(pattern="*.out")  
for (i in 1:length(temp)) assign(temp[i], read.table(temp[i], header = TRUE))

我使用这个命令读取文件,然后我知道temp[1] 将包含第一个文件名,但是如何进入文件,并提取第 5 列。我试过了:

file <- for (i in 1:length(temp)) assign(temp[i], read.table(temp[i[[5]]], header = TRUE))

显然,这是不正确的。提取所有第 5 列后,如何一次对所有列进行直方图。

【问题讨论】:

    标签: r multithreading file plot histogram


    【解决方案1】:

    您可以遍历文件,读取文件,提取第五列,将它们存储在向量中,然后应用直方图,而不是将每个表分配给变量:

    temp = list.files(pattern = "*.out")
    hist(sapply(temp, function(fileName) read.table(fileName, header = TRUE)[5]))
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2019-02-01
      • 1970-01-01
      • 2021-12-03
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多