我正在尝试使用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")
答案 0 :(得分:0)
Mankind_008回答了问题! (通过使用stats :: dist解决)