Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to find max in the list of data frames

Tags:

r

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:

##. 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.

like image 455
Thuy Nguyen Hong Avatar asked Nov 20 '13 20:11

Thuy Nguyen Hong


People also ask

How do you find the max of a data frame?

Pandas DataFrame max() Method The max() method returns a Series with the maximum value of each column. By specifying the column axis ( axis='columns' ), the max() method searches column-wise and returns the maximum value for each row.

How do I find the max of a list in R?

How to get the max value in a list in R? First, use the unlist() function to convert the list into a vector, and then use the max() function to get the maximum value.

How will you find the top 5 records of a data frame?

Select first N Rows from a Dataframe using head() function In Python's Pandas module, the Dataframe class provides a head() function to fetch top rows from a Dataframe i.e. It returns the first n rows from a dataframe. If n is not provided then default value is 5.

How do you return a max value from a list in Python?

In Python, there is a built-in function max() you can use to find the largest number in a list. To use it, call the max() on a list of numbers. It then returns the greatest number in that list.


1 Answers

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:

max(unlist(listOfFiles))

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

like image 164
Paul Hiemstra Avatar answered Oct 12 '22 12:10

Paul Hiemstra