2015-12-21 69 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等可能不是數字。

首先將數據轉換爲適當的格式。