Re: [R] fast way to find most common value across columns dataframe

2020-10-31 Thread Rui Barradas
Hello, Here is a comparative test of 3 options. cumstats::Mode returns a list with two members, Values: all the modes. Frequency: their frequency The value of the mode must be extracted after. cumstats::Mode is by far the slowest but returns more information. The function below is in this S

Re: [R] fast way to find most common value across columns dataframe

2020-10-31 Thread Luigi Marongiu
Thank you. The problem was not finding the mode but applying it the R way (I have the tendency to loop into each line of the dataframes, which I believe is NOT the R way). I'll try them. Best regards Luigi On Sat, Oct 31, 2020 at 5:40 PM Bert Gunter wrote: > > As usual, a web search ("find statis

Re: [R] fast way to find most common value across columns dataframe

2020-10-31 Thread Bert Gunter
As usual, a web search ("find statistical mode in R") brought up something that is possibly useful -- Did you try this before posting? If not, please do so in future and let us know what your results were if you subsequently post here. Here's what SO suggested: Mode <- function(x) { ux <- uniq

Re: [R] fast way to find most common value across columns dataframe

2020-10-31 Thread Jim Lemon
Hi Luigi, If I understand your request: library(prettyR) apply(as.matrix(df),1,Mode) [1] "C" "B" "D" ">1 mode" ">1 mode" ">1 mode" "D" [8] "C" "B" ">1 mode" Jim On Sat, Oct 31, 2020 at 7:56 PM Luigi Marongiu wrote: > Hello, > I have a large dataframe (1 000 000 ro

[R] fast way to find most common value across columns dataframe

2020-10-31 Thread Luigi Marongiu
Hello, I have a large dataframe (1 000 000 rows, 1000 columns) where the columns contain a character. I would like to determine the most common character for each row. In the example below, I can parse one row at the time and find the most common character (apart for ties...). But I think this will