R中的外部函数调用(arg 1)中的NA/NaN/Inf

R中的外部函数调用(arg 1)中的NA/NaN/Inf,r,R,我正在尝试创建K-mean集群,并在外部函数调用(arg1)中接收错误NA/NaN/Inf。这是我的密码 library(tidyverse) library(readr) library(jsonlite) library(dplyr) df<-fromJSON('https://raw.githubusercontent.com/lequanngo/WorldHappiness/master/WorldHappiness.json') df <- na.omit(df) glim

我正在尝试创建K-mean集群,并在外部函数调用(arg1)中接收错误NA/NaN/Inf。这是我的密码

library(tidyverse)
library(readr)
library(jsonlite)
library(dplyr)
df<-fromJSON('https://raw.githubusercontent.com/lequanngo/WorldHappiness/master/WorldHappiness.json')
df <- na.omit(df)
glimpse(df)
Observations: 156
Variables: 11
$ Country            <chr> "Finland", "Denmark", "Norway", "Iceland", "Netherlan…
$ Ladder             <int> 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16…
$ SD_of_ladder       <int> 4, 13, 8, 9, 1, 11, 18, 15, 23, 10, 26, 62, 14, 3, 16…
$ Positive_affect    <int> 41, 24, 16, 3, 12, 44, 34, 22, 18, 64, 47, 4, 104, 62…
$ Negative_affect    <int> 10, 26, 29, 3, 25, 21, 8, 12, 49, 24, 37, 87, 69, 19,…
$ Social_support     <int> 2, 4, 3, 1, 15, 13, 25, 5, 20, 31, 7, 42, 38, 27, 9, …
$ Freedom            <int> 5, 6, 3, 7, 19, 11, 10, 8, 9, 26, 17, 16, 93, 28, 63,…
$ Corruption         <int> 4, 3, 8, 45, 12, 7, 6, 5, 11, 19, 13, 58, 74, 9, 15, …
$ Generosity         <int> 47, 22, 11, 3, 7, 16, 17, 8, 14, 25, 6, 75, 24, 30, 4…
$ Log_of_GDP_per_cap <int> 22, 14, 7, 15, 12, 8, 13, 26, 19, 16, 18, 67, 31, 2, …
$ Healthy_life_exp   <int> 27, 23, 12, 13, 18, 4, 17, 14, 8, 15, 10, 28, 11, 16,…


set.seed(12345) 
countries <- df 
df_clus <- df[-1]
cluster_solution <- kmeans(df_clus, centers = 5)
库(tidyverse)
图书馆(readr)
图书馆(jsonlite)
图书馆(dplyr)

df当我运行你的代码,并且
scape(df)
它将
Positive\u impact
之后的变量显示为字符而不是整数。如果将它们转换为整数,并删除/省略NAs,则
kmeans
不会给出任何错误。谢谢!是的,我把它们都转换成了整数,并且删除了NAs,它成功了!