Python решение:
# Initialise pandas, and mode in session:
import pandas as pd
from statistics import mode
# Scalar denoting the full path to file (including file name): filepath => string scalar
filepath = ''
# Read in the Excel sheet: df => Data Frame
df = pd.read_excel(filepath)
# Find modal element per row: k2 => string vector
df['k2'] = [*map(lambda x: mode(str(x).split(',')), df['knumbers'])]
Базовое решение R:
# Define a function to retrieve the modal element in a factor/character vector: mode_stat => function
mode_stat <- function(chr_vec){names(sort(table(as.character(chr_vec)), decreasing = TRUE)[1])}
# Apply the function to a list of split knumber strings: k2 => character vector
df$k2 <- sapply(strsplit(df$knumbers, ","), mode_stat)
Данные (реконструировать в R):
df <- structure(list(Total = c(446, 346, 332, 308), knumbers = c("K10401",
"K10413,K10413,K10412", "K13844,K13844,K13845", "K19206,K19207,K19207"
)), row.names = c(NA, -4L), class = c("tbl_df", "tbl", "data.frame"))
В Excel:
(goodluck)