title: Can't apply k means algorithm to my dataset Error in do_one(nmeth) : NA/NaN/Inf in foreign function call
body: <p>So I am trying to estimate the actual number of clusters with the <code>fviz_nbclust</code> function but it doesn't stop showing me this error:</p>
  <blockquote>
  <p>Error in do_one(nmeth) : NA/NaN/Inf in foreign function call (arg 1)</p>
  </blockquote>
  <p>In addition warning messages:</p>
  <blockquote>
  <p>1: In stats::dist(x) : NAs introduced by coercion</p>
  </blockquote>
  <blockquote>
  <p>2: In storage.mode(x) &lt;- &quot;double&quot; : NAs introduced by coercion</p>
  </blockquote>
  <p>I have used <code>sum(is.na(stand_numeric_data$variable))</code> for all the columns of my dataset and it returns 0 for all the variables so I am assuming I don't have NA values. Any tips? I am new to programming so any suggestion would be appreciated.</p>
  <pre><code>movies_data &lt;- read.csv(&quot;movies_metadata.csv&quot;, na.string = &quot;True&quot;)
  
  only_numeric &lt;- movies_data %&gt;% select(16, 17, 23, 24, 21) #subset of columns 
  
  only_numeric &lt;- subset(only_numeric, grepl('^\\d+$', only_numeric$revenue))
  
  only_numeric &lt;- subset(only_numeric, grepl('^\\d+$', only_numeric$runtime))
  
  only_numeric &lt;- subset(only_numeric, grepl('^\\d+$', only_numeric$vote_average))
  
  only_numeric &lt;- subset(only_numeric, grepl('^\\d+$', only_numeric$vote_count))
  
  library(caret) #standardization
  
  preproc1 &lt;- preProcess(only_numeric[,c(1:4,5)], method=c(&quot;center&quot;, &quot;scale&quot;))
  
  stand_numeric_data &lt;- predict(preproc1, only_numeric[,c(1:4,5)])
  
  sum(is.na(stand_numeric_data$revenue))
  
  library(factoextra) #estimate the actual number of clusters 
  
  fviz_nbclust(stand_numeric_data, kmeans, method = &quot;wss&quot;)
  
  </code></pre>
  <blockquote>
  <p>Error in do_one(nmeth) : NA/NaN/Inf in foreign function call (arg 1)</p>
  </blockquote>
  <p>In addition warning messages:</p>
  <blockquote>
  <p>1: In stats::dist(x) : NAs introduced by coercion</p>
  <p>2: In storage.mode(x) &lt;- &quot;double&quot; : NAs introduced by coercion</p>
  </blockquote>
  <pre><code>dput(head(movies_data, 5))
  </code></pre>
  <pre><code>structure(list(adult = c(&quot;False&quot;, &quot;False&quot;, &quot;False&quot;, &quot;False&quot;, 
  &quot;False&quot;), belongs_to_collection = c(&quot;{'id': 10194, 'name': 'Toy Story Collection', 'poster_path': '/7G9915LfUQ2lVfwMEEhDsn3kT4B.jpg', 'backdrop_path': '/9FBwqcd9IRruEDUrTdcaafOMKUq.jpg'}&quot;, 
  &quot;&quot;, &quot;{'id': 119050, 'name': 'Grumpy Old Men Collection', 'poster_path': '/nLvUdqgPgm3F85NMCii9gVFUcet.jpg', 'backdrop_path': '/hypTnLot2z8wpFS7qwsQHW1uV8u.jpg'}&quot;, 
  &quot;&quot;, &quot;{'id': 96871, 'name': 'Father of the Bride Collection', 'poster_path': '/nts4iOmNnq7GNicycMJ9pSAn204.jpg', 'backdrop_path': '/7qwE57OVZmMJChBpLEbJEmzUydk.jpg'}&quot;
  ), budget = c(&quot;30000000&quot;, &quot;65000000&quot;, &quot;0&quot;, &quot;16000000&quot;, &quot;0&quot;), 
      genres = c(&quot;[{'id': 16, 'name': 'Animation'}, {'id': 35, 'name': 'Comedy'}, {'id': 10751, 'name': 'Family'}]&quot;, 
      &quot;[{'id': 12, 'name': 'Adventure'}, {'id': 14, 'name': 'Fantasy'}, {'id': 10751, 'name': 'Family'}]&quot;, 
      &quot;[{'id': 10749, 'name': 'Romance'}, {'id': 35, 'name': 'Comedy'}]&quot;, 
      &quot;[{'id': 35, 'name': 'Comedy'}, {'id': 18, 'name': 'Drama'}, {'id': 10749, 'name': 'Romance'}]&quot;, 
      &quot;[{'id': 35, 'name': 'Comedy'}]&quot;), homepage = c(&quot;http://toystory.disney.com/toy-story&quot;, 
      &quot;&quot;, &quot;&quot;, &quot;&quot;, &quot;&quot;), id = c(&quot;862&quot;, &quot;8844&quot;, &quot;15602&quot;, &quot;31357&quot;, 
      &quot;11862&quot;), imdb_id = c(&quot;tt0114709&quot;, &quot;tt0113497&quot;, &quot;tt0113228&quot;, 
      &quot;tt0114885&quot;, &quot;tt0113041&quot;), original_language = c(&quot;en&quot;, &quot;en&quot;, 
      &quot;en&quot;, &quot;en&quot;, &quot;en&quot;), original_title = c(&quot;Toy Story&quot;, &quot;Jumanji&quot;, 
      &quot;Grumpier Old Men&quot;, &quot;Waiting to Exhale&quot;, &quot;Father of the Bride Part II&quot;
      ), overview = c(&quot;Led by Woody, Andy's toys live happily in his room until Andy's birthday brings Buzz Lightyear onto the scene. Afraid of losing his place in Andy's heart, Woody plots against Buzz. But when circumstances separate Buzz and Woody from their owner, the duo eventually learns to put aside their differences.&quot;, 
      &quot;When siblings Judy and Peter discover an enchanted board game that opens the door to a magical world, they unwittingly invite Alan -- an adult who's been trapped inside the game for 26 years -- into their living room. Alan's only hope for freedom is to finish the game, which proves risky as all three find themselves running from giant rhinoceroses, evil monkeys and other terrifying creatures.&quot;, 
      &quot;A family wedding reignites the ancient feud between next-door neighbors and fishing buddies John and Max. Meanwhile, a sultry Italian divorcÃ©e opens a restaurant at the local bait shop, alarming the locals who worry she'll scare the fish away. But she's less interested in seafood than she is in cooking up a hot time with Max.&quot;, 
      &quot;Cheated on, mistreated and stepped on, the women are holding their breath, waiting for the elusive \&quot;good man\&quot; to break a string of less-than-stellar lovers. Friends and confidants Vannah, Bernie, Glo and Robin talk it all out, determined to find a better way to breathe.&quot;, 
      &quot;Just when George Banks has recovered from his daughter's wedding, he receives the news that she's pregnant ... and that George's wife, Nina, is expecting too. He was planning on selling their home, but that's a plan that -- like George -- will have to change with the arrival of both a grandchild and a kid of his own.&quot;
      ), popularity = c(&quot;21.946943&quot;, &quot;17.015539&quot;, &quot;11.7129&quot;, &quot;3.859495&quot;, 
      &quot;8.387519&quot;), poster_path = c(&quot;/rhIRbceoE9lR4veEXuwCC2wARtG.jpg&quot;, 
      &quot;/vzmL6fP7aPKNKPRTFnZmiUfciyV.jpg&quot;, &quot;/6ksm1sjKMFLbO7UY2i6G1ju9SML.jpg&quot;, 
      &quot;/16XOMpEaLWkrcPqSQqhTmeJuqQl.jpg&quot;, &quot;/e64sOI48hQXyru7naBFyssKFxVd.jpg&quot;
      ), production_companies = c(&quot;[{'name': 'Pixar Animation Studios', 'id': 3}]&quot;, 
      &quot;[{'name': 'TriStar Pictures', 'id': 559}, {'name': 'Teitler Film', 'id': 2550}, {'name': 'Interscope Communications', 'id': 10201}]&quot;, 
      &quot;[{'name': 'Warner Bros.', 'id': 6194}, {'name': 'Lancaster Gate', 'id': 19464}]&quot;, 
      &quot;[{'name': 'Twentieth Century Fox Film Corporation', 'id': 306}]&quot;, 
      &quot;[{'name': 'Sandollar Productions', 'id': 5842}, {'name': 'Touchstone Pictures', 'id': 9195}]&quot;
      ), production_countries = c(&quot;[{'iso_3166_1': 'US', 'name': 'United States of America'}]&quot;, 
      &quot;[{'iso_3166_1': 'US', 'name': 'United States of America'}]&quot;, 
      &quot;[{'iso_3166_1': 'US', 'name': 'United States of America'}]&quot;, 
      &quot;[{'iso_3166_1': 'US', 'name': 'United States of America'}]&quot;, 
      &quot;[{'iso_3166_1': 'US', 'name': 'United States of America'}]&quot;
      ), release_date = c(&quot;1995-10-30&quot;, &quot;1995-12-15&quot;, &quot;1995-12-22&quot;, 
      &quot;1995-12-22&quot;, &quot;1995-02-10&quot;), revenue = c(373554033, 262797249, 
      0, 81452156, 76578911), runtime = c(81, 104, 101, 127, 106
      ), spoken_languages = c(&quot;[{'iso_639_1': 'en', 'name': 'English'}]&quot;, 
      &quot;[{'iso_639_1': 'en', 'name': 'English'}, {'iso_639_1': 'fr', 'name': 'FranÃ§ais'}]&quot;, 
      &quot;[{'iso_639_1': 'en', 'name': 'English'}]&quot;, &quot;[{'iso_639_1': 'en', 'name': 'English'}]&quot;, 
      &quot;[{'iso_639_1': 'en', 'name': 'English'}]&quot;), status = c(&quot;Released&quot;, 
      &quot;Released&quot;, &quot;Released&quot;, &quot;Released&quot;, &quot;Released&quot;), tagline = c(&quot;&quot;, 
      &quot;Roll the dice and unleash the excitement!&quot;, &quot;Still Yelling. Still Fighting. Still Ready for Love.&quot;, 
      &quot;Friends are the people who let you be yourself... and never let you forget it.&quot;, 
      &quot;Just When His World Is Back To Normal... He's In For The Surprise Of His Life!&quot;
      ), title = c(&quot;Toy Story&quot;, &quot;Jumanji&quot;, &quot;Grumpier Old Men&quot;, 
      &quot;Waiting to Exhale&quot;, &quot;Father of the Bride Part II&quot;), video = c(&quot;False&quot;, 
      &quot;False&quot;, &quot;False&quot;, &quot;False&quot;, &quot;False&quot;), vote_average = c(7.7, 
      6.9, 6.5, 6.1, 5.7), vote_count = c(5415L, 2413L, 92L, 34L, 
      173L)), row.names = c(NA, 5L), class = &quot;data.frame&quot;)
  </code></pre>
  <pre><code>summary(stand_numeric_data)
  
  revenue           runtime          vote_average       vote_count     
   Min.   :-0.1114   Min.   :-2.10206   Min.   :-1.5192   Min.   :-0.1414  
   1st Qu.:-0.1114   1st Qu.:-0.20831   1st Qu.:-1.5192   1st Qu.:-0.1381  
   Median :-0.1114   Median : 0.08303   Median : 0.1963   Median :-0.1381  
   Mean   : 0.0000   Mean   : 0.00000   Mean   : 0.0000   Mean   : 0.0000  
   3rd Qu.:-0.1114   3rd Qu.: 0.37438   3rd Qu.: 0.8825   3rd Qu.:-0.1248  
   Max.   :28.9583   Max.   :20.35581   Max.   : 1.9118   Max.   :29.3968  
      title          
   Length:11406      
   Class :character  
   Mode  :character  
  </code></pre>