如何在数据框列表中找到max

时间:2021-01-02 18:34:24

I have several input data files in my working dir, I would like to read all input data and find one MAX value of all values stored in those files. Here is the code:

我的工作目录中有几个输入数据文件,我想读取所有输入数据,并找到存储在这些文件中的所有值的一个MAX值。这是代码:

##. identify files to read in
filesToProcess  <- (Sys.glob("*.csv"))
filesToProcess 

## Read all file and store in a list
listOfFiles <- lapply(filesToProcess, function(x) read.table(x, header = FALSE))

max(listOfFiles) #-- error 

Can anyone give me suggestion how to get the MAX? Thanks a lot.

任何人都可以给我建议如何获得MAX?非常感谢。

1 个解决方案

#1


6  

The max operation is not defined for a list of data.frame's, only for vectors of numbers. To get the max value of all values, you can simply use:

没有为data.frame的列表定义max操作,仅针对数字向量。要获取所有值的最大值,您只需使用:

max(unlist(listOfFiles))

where unlist recursively reduces the list of data.frame's to one vector of numbers.

其中unlist以递归方式将data.frame的列表减少为一个数字向量。

#1


6  

The max operation is not defined for a list of data.frame's, only for vectors of numbers. To get the max value of all values, you can simply use:

没有为data.frame的列表定义max操作,仅针对数字向量。要获取所有值的最大值,您只需使用:

max(unlist(listOfFiles))

where unlist recursively reduces the list of data.frame's to one vector of numbers.

其中unlist以递归方式将data.frame的列表减少为一个数字向量。