Calculate Mode with R

Hello ,
I have a dataframe with two columns, query and rang_min_reponse.
What we mean by rang_min_reponse is the minimum rank of the answer clicked for example if we click on answer 5 and 2 rang_min_reponse will take 2.
I need to study the modes of the variable rang_min_reponse by queries - and that I identify the 3 queries with the most modalities.
Here's the code, can you help me improve it?
Excuse me for misspellings

the code :

Scriot en R :

#installer des packages
library(readr)
library(dplyr)

#charger des données
data <-read_table2(file = "data",header = TRUE, sep = "," , quote = """, dec = ".")
data
data %>% View()

#Extraire les données
data[,17]
data[,62]
data <- data[c(17,62)]
data %>% View()

#filtrer les données ayant un rang min>3
data <- filter(data, rang_min_reponse > 3)
data %>% View()

#regrouper les données par requete et determiner le mode
data<- data %>% group_by(requete) %>% summarise(rang_min_reponse = max(rang_min_reponse ,na.rm =FALSE ) %>%
data %>% View()

library(modeest)
install.packages("modeest")
mySamples <- data[,1]
mlv(mySamples, method = "mfv")
image

I appreciate your effort, but your code is not reproducible. We don't have access to your local files. Please go through the link to provide a small part of your dataset using the datapasta package. Alternatively, you can check here:

Being said that, note that there's a few problems with your code.

  1. Most probably, there's no file named data in your working directory. You need to mention a extension.

  2. read_table2 does no have the arguments header, sep, etc. Since you're using sep = ",", I think you may be using a CSV file. Check the read_csv function or read.csv.

Please resolve these and post a new reproducible example. It'll be better if you use the reprex package.

1 Like

This topic was automatically closed 21 days after the last reply. New replies are no longer allowed.

If you have a query related to it or one of the replies, start a new topic and refer back with a link.