2015-12-21 207 views
-4

我有下面的代码,这是给我的一个错误:[R k均值

# Read input dataset from CSV file 
input_dataset <-  
read.csv("C:\\Users\\sw029693\\Desktop\\Overtime_work_hrs_analytics\\input_dataset.csv", header = TRUE) 

wss <- (nrow(input_dataset)-1)*sum(apply(input_dataset,2,var)) 

它提供了以下错误:

Warning messages: 
1: In FUN(newX[, i], ...) : NAs introduced by coercion 
2: In FUN(newX[, i], ...) : NAs introduced by coercion 
3: In FUN(newX[, i], ...) : NAs introduced by coercion 
4: In FUN(newX[, i], ...) : NAs introduced by coercion 
5: In FUN(newX[, i], ...) : NAs introduced by coercion 

> wss 
[1] NA 

> colnames(input_dataset) 
[1] "client"   "domain"   "user_name"    
"cdf_display"  "position"   "shift_start"  
[7] "shift_end"   "shift_length_avg" "patients_seen_cnt" 

它看起来像WSS是不,我不知道为什么。有任何想法吗?

+5

您的数据中有NA?你看了?严重的是,在你跑步之前走路。在您尝试做任何数学计算之前,请务必检查您的数据是否是您认为的数据。检查列是数字。检查缺少的值。检查它,写一个函数来检查它,然后编写一个函数来检查该函数。 – Spacedman

回答

0

K-means仅支持数值数据。

您列user_name等可能不是数字。

首先将数据转换为适当的格式。