x<- read.table('d:\\2.csv', sep=';', header=TRUE) x <- log(x) #логарифмируем x <- x[-1] #отбросим колонку с именами игроков x <- apply(x, 2, diff) #считаем разницу между последовательными элементами x <- t(x) #транспонируем таблицу kmeans(x, 5, 1000000) #будем разбивать на 25 кластеров, максимум 1000000 иттераций 

I read the prepared file - everything is read without problems.

Next, I want to make a simple logarithm x<-log(x) and an error crashes.

Error in Math.data.frame (x):

non-numeric variable (s) in data frame: X.stat1.stat2.stat4.

stat1, etc. - These are the names of the columns in the file.

How to me to put the initial data in order that there were no such errors? File link itself

    1 answer 1

    In general, if the numbers are symbolic vectors, you can reduce the values ​​to numeric using as.numeric :

     > values <- c("9", "100") > df <- data.frame(values) > log(as.numeric(df$values)) [1] 0.6931472 0.0000000 

    In your particular case, you can try this:

     x <- read.table(file, sep=';', header=TRUE) x <- x[-1] #отбросим колонку с именами игроков x <- log(x) #логарифмируем x <- apply(x, 2, diff) #считаем разницу между последовательными элементами x <- t(x) #транспонируем таблицу is.na(x) <- do.call(cbind,lapply(x, is.infinite)) # Заменить все Inf на NA is.na(x) <- do.call(cbind,lapply(x, is.nan)) # Заменить все NaN на NA x <- na.omit(x) # Удалить строки, содержащие NA kmeans(x, 5, 1000000) # будем разбивать на 25 кластеров, максимум 1000000 итераций 
    • Thanks for the answer, but I have a data table, 127 columns and 547 rows. and data there kind of real - Vladimr Vladimirovoch
    • @VladimrVladimirovoch Give an example with problem lines in the text of a question. I tested it with a data table, but only with integers. Just tried with numbers like 3.45 and 6.44, also works. - Wiktor Stribiżew
    • Corrected the question, now the full picture - Vladimr Vladimirovoch
    • What if x <- x[-1] swap with x <- log(x) ? - Wiktor Stribiżew
    • and the logic is not broken, I'm just an extremely newcomer to R - Vladimr Vladimirovoch