簡體   English   中英

R中的dist()函數返回“ dist(x,method =“ binary”)中的錯誤:未使用的參數(方法=“ binary”)?

[英]dist() function in R returning “Error in dist(x, method = ”binary“) : unused argument (method = ”binary")?

我正在嘗試在分類變量上使用dist創建一個距離矩陣。 我對分類變量成功執行了dummy.data.frame ,但是當我運行dist() R時返回以下消息:

dist(dummyClusterdf,method =“ binary”)中的錯誤:未使用的參數(method =“ binary”)“

有沒有其他人有這個問題? 任何幫助,將不勝感激。

#dummify categorical variables
dummyClusterdf <- dummy.data.frame(data = clusterdf, sep = ".", dummy.classes = "ALL", all = FALSE)
glimpse(dummyClusterdf)

#distance matrix
surveydist <- dist(dummyClusterdf, method = "binary")

dist(dummyClusterdf,method =“ binary”)中的錯誤:未使用的參數(method =“ binary”)

這是數據示例:

> dput(head(dummyClusterdf))
structure(list(`Age_Range.23 - 25` = c(0L, 0L, 0L, 1L, 0L, 0L
), `Age_Range.26 - 30` = c(1L, 0L, 0L, 0L, 0L, 0L), `Age_Range.30 +` = c(0L, 
1L, 1L, 0L, 1L, 1L), User_Role.Faculty = c(0L, 1L, 1L, 0L, 0L, 
1L), User_Role.Staff = c(1L, 0L, 0L, 1L, 1L, 0L), User_Role.Administration = c(0L, 
0L, 0L, 0L, 0L, 0L), `Sustainability_Importance.Extremely Unimportant` = c(0L, 
0L, 0L, 0L, 0L, 0L), Sustainability_Importance.Neutral = c(0L, 
0L, 0L, 0L, 0L, 0L), `Sustainability_Importance.Very important` = c(0L, 
1L, 1L, 0L, 0L, 1L), `Sustainability_Importance.Extremely important` = c(1L, 
0L, 0L, 1L, 1L, 0L), `Self_rate_Sustainable_Lifestyle.Somewhat disagree` = c(0L, 
0L, 0L, 0L, 0L, 0L), `Self_rate_Sustainable_Lifestyle.Neither agree nor disagree` = c(0L, 
1L, 0L, 0L, 0L, 0L), `Self_rate_Sustainable_Lifestyle.Somewhat agree` = c(1L, 
0L, 1L, 1L, 1L, 1L), `Self_rate_Sustainable_Lifestyle.Strongly agree` = c(0L, 
0L, 0L, 0L, 0L, 0L), `School_Prioritizes_Sustainability.A little` = c(0L, 
0L, 0L, 0L, 0L, 0L), `School_Prioritizes_Sustainability.A moderate amount` = c(1L, 
0L, 1L, 0L, 0L, 0L), `School_Prioritizes_Sustainability.A lot` = c(0L, 
0L, 0L, 0L, 0L, 0L), `School_Prioritizes_Sustainability.A great deal` = c(0L, 
1L, 0L, 1L, 1L, 1L), Lights_on_Empty_Room.Never = c(0L, 0L, 0L, 
0L, 0L, 0L), Lights_on_Empty_Room.Sometimes = c(0L, 0L, 1L, 0L, 
0L, 0L), `Lights_on_Empty_Room.About half the time` = c(0L, 0L, 
0L, 0L, 0L, 0L), `Lights_on_Empty_Room.Most of the time` = c(1L, 
0L, 0L, 0L, 0L, 1L), Lights_on_Empty_Room.Always = c(0L, 1L, 
0L, 1L, 1L, 0L), Look_kWh_on_Bill.Yes = c(1L, 1L, 1L, 1L, 0L, 
1L), Look_kWh_on_Bill.No = c(0L, 0L, 0L, 0L, 1L, 0L), `Real_time_Updates_Reduce_Use.Strongly disagree` = c(0L, 
0L, 0L, 0L, 0L, 0L), `Real_time_Updates_Reduce_Use.Somewhat disagree` = c(0L, 
0L, 0L, 0L, 0L, 0L), `Real_time_Updates_Reduce_Use.Neither agree nor disagree` = c(0L, 
0L, 0L, 0L, 0L, 0L), `Real_time_Updates_Reduce_Use.Somewhat agree` = c(1L, 
0L, 1L, 0L, 0L, 0L), `Real_time_Updates_Reduce_Use.Strongly agree` = c(0L, 
1L, 0L, 1L, 1L, 1L), `Electric_Cost_Importance.Slightly important` = c(0L, 
0L, 0L, 0L, 0L, 0L), `Electric_Cost_Importance.Moderately important` = c(0L, 
0L, 1L, 0L, 0L, 0L), `Electric_Cost_Importance.Very important` = c(1L, 
0L, 0L, 1L, 1L, 1L), `Electric_Cost_Importance.Extremely important` = c(0L, 
1L, 0L, 0L, 0L, 0L), `Electric_Environment_Importance.Slightly important` = c(0L, 
0L, 0L, 0L, 0L, 0L), `Electric_Environment_Importance.Moderately important` = c(1L, 
0L, 1L, 0L, 0L, 0L), `Electric_Environment_Importance.Very important` = c(0L, 
0L, 0L, 1L, 0L, 1L), `Electric_Environment_Importance.Extremely important` = c(0L, 
1L, 0L, 0L, 1L, 0L), Work_Can_Change_Thermostat.Yes = c(0L, 0L, 
0L, 0L, 0L, 0L), Work_Can_Change_Thermostat.No = c(1L, 1L, 1L, 
1L, 1L, 1L), `Peacock_VS_Campus_Efficiency.Not efficient at all` = c(0L, 
0L, 0L, 0L, 0L, 0L), `Peacock_VS_Campus_Efficiency.Slightly efficient` = c(0L, 
0L, 1L, 0L, 0L, 0L), `Peacock_VS_Campus_Efficiency.Moderately efficient` = c(1L, 
1L, 0L, 1L, 1L, 0L), `Peacock_VS_Campus_Efficiency.Very efficient` = c(0L, 
0L, 0L, 0L, 0L, 1L), `Peacock_VS_Campus_Efficiency.Extremely efficient` = c(0L, 
0L, 0L, 0L, 0L, 0L), `Display_Useful.Not at all useful` = c(0L, 
0L, 1L, 0L, 0L, 0L), `Display_Useful.Slightly useful` = c(1L, 
0L, 0L, 0L, 0L, 0L), `Display_Useful.Moderately useful` = c(0L, 
0L, 0L, 1L, 0L, 1L), `Display_Useful.Very useful` = c(0L, 1L, 
0L, 0L, 1L, 0L), `Display_Useful.Extremely useful` = c(0L, 0L, 
0L, 0L, 0L, 0L), `Display_Impact.None at all` = c(0L, 0L, 1L, 
0L, 0L, 0L), `Display_Impact.A little` = c(1L, 0L, 0L, 0L, 0L, 
1L), `Display_Impact.A moderate amount` = c(0L, 1L, 0L, 1L, 1L, 
0L), `Display_Impact.A lot` = c(0L, 0L, 0L, 0L, 0L, 0L), Gender.Male = c(0L, 
1L, 0L, 0L, 0L, 1L), Gender.Female = c(1L, 0L, 1L, 1L, 1L, 0L
), `Gender.Prefer not to answer` = c(0L, 0L, 0L, 0L, 0L, 0L), 
    `Race/Ethnicity.I would prefer not to answer` = c(0L, 0L, 
    0L, 0L, 0L, 0L), `Race/Ethnicity.Other` = c(1L, 0L, 0L, 0L, 
    0L, 0L), `Race/Ethnicity.Asian/Asian American` = c(0L, 1L, 
    0L, 0L, 0L, 0L), `Race/Ethnicity.Hispanic or Latino` = c(0L, 
    0L, 0L, 0L, 0L, 0L), `Race/Ethnicity.White or Caucasian` = c(0L, 
    0L, 1L, 1L, 1L, 1L), `Prize_Participation.Yes please!` = c(1L, 
    1L, 1L, 1L, 1L, 1L), `Prize_Participation.No thanks, I'd like to be finished` = c(0L, 
    0L, 0L, 0L, 0L, 0L)), dummies = list(Age_Range = 1:3, User_Role = 4:6, 
    Sustainability_Importance = 7:10, Self_rate_Sustainable_Lifestyle = 11:14, 
    School_Prioritizes_Sustainability = 15:18, Lights_on_Empty_Room = 19:23, 
    Look_kWh_on_Bill = 24:25, Real_time_Updates_Reduce_Use = 26:30, 
    Electric_Cost_Importance = 31:34, Electric_Environment_Importance = 35:38, 
    Work_Can_Change_Thermostat = 39:40, Peacock_VS_Campus_Efficiency = 41:45, 
    Display_Useful = 46:50, Display_Impact = 51:54, Gender = 55:57, 
    `Race/Ethnicity` = 58:62, Prize_Participation = 63:64), row.names = c("1", 
"2", "3", "4", "5", "6"), class = "data.frame")

Mankind_008回答了問題! (通過使用stats :: dist解決)

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM