Even after converting my file as factor why does my output give factor(0) 30956 Levels?Why are these numbers not equal?Numeric comparison difficulty in RHow to create a stratified sample by state in RConverting Data factors to DateError in predict.lm in R: factor as.factor(daily) has new level 2For all levels of a factor, return all levels of another factor from same dataframe - using dplyr ? rFactoring data in RR confusionMatrix() & Table() give the Error in sort.list(y) : 'x' must be atomic for 'sort.list' Have you called 'sort' on a list?error in running factor() on a column of a data frameconverting POSIXct back to factorConverting list to factor in RSort.list/unlist in Kripp.Alpha

Constitutional limitation of criminalizing behavior in US law?

Game artist computer workstation set-up – is this overkill?

Krull dimension of the ring of global sections

What do you call a painting on a wall?

Understanding ties

What was the first story to feature the plot "the monsters were human all along"?

Which US defense organization would respond to an invasion like this?

Speed up this NIntegrate

Why didn't this character get a funeral at the end of Avengers: Endgame?

Can my 2 children, aged 10 and 12, who are US citizens, travel to the USA on expired American passports?

How do I, as a DM, handle a party that decides to set up an ambush in a dungeon?

Is 'contemporary' ambiguous and if so is there a better word?

All superlinear runtime algorithms are asymptotically equivalent to convex function?

Where are the "shires" in the UK?

Dihedral group D4 composition with custom labels

Is there a proof that the set of real numbers can exactly represent distances?

Why does sound not move through a wall?

How can a hefty sand storm happen in a thin atmosphere like Martian?

GitLab account hacked and repo wiped

How to properly store the current value of int variable into a token list?

Piano: quaver triplets in RH v dotted quaver and semiquaver in LH

The origin of list data structure

Motion-trail-like lines

In linear regression why does regularisation penalise the parameter values as well?



Even after converting my file as factor why does my output give factor(0) 30956 Levels?


Why are these numbers not equal?Numeric comparison difficulty in RHow to create a stratified sample by state in RConverting Data factors to DateError in predict.lm in R: factor as.factor(daily) has new level 2For all levels of a factor, return all levels of another factor from same dataframe - using dplyr ? rFactoring data in RR confusionMatrix() & Table() give the Error in sort.list(y) : 'x' must be atomic for 'sort.list' Have you called 'sort' on a list?error in running factor() on a column of a data frameconverting POSIXct back to factorConverting list to factor in RSort.list/unlist in Kripp.Alpha






.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty height:90px;width:728px;box-sizing:border-box;








6















I am new to R and working on the below dataset:



I have a file called zippopinc



Repex:



head(zippopinc)

Year Zip Total_Population Median_Income City State
1 1 2017 ZCTA5 00601 17599 11757 Adjuntas PR
2 2 2017 ZCTA5 00602 39209 16190 Aguada PR
3 3 2017 ZCTA5 00603 50135 16645 Aguadilla PR
4 4 2017 ZCTA5 00606 6304 13387 Maricao PR
5 5 2017 ZCTA5 00610 27590 18741 Anasco PR
6 6 2017 ZCTA5 00612 62566 17744 Arecibo PR
Poptoincomeratio
1.4968955
2.4218036
3.0120156
0.4709046
1.4721733
3.5260370


poptoincomeratio is basically Total_Population/Median_Income



My objective is to find which zip code has the highest Poptoincomeratio:



My input:



max(sapply(zippopinc$Poptoincomeratio, max))


Output:



4.454182


So I tried,



zippopinc$Zip[demograph_ratio$Poptoincomeratio == 4.454182]


But this gave me:



factor(0)
30956 Levels


I then tried to convert zipopinc as a factor but got the below error:



> as.factor(zippopinc)
Error in sort.list(y) : 'x' must be atomic for 'sort.list'
Have you called 'sort' on a list?


How can I fix this?










share|improve this question






























    6















    I am new to R and working on the below dataset:



    I have a file called zippopinc



    Repex:



    head(zippopinc)

    Year Zip Total_Population Median_Income City State
    1 1 2017 ZCTA5 00601 17599 11757 Adjuntas PR
    2 2 2017 ZCTA5 00602 39209 16190 Aguada PR
    3 3 2017 ZCTA5 00603 50135 16645 Aguadilla PR
    4 4 2017 ZCTA5 00606 6304 13387 Maricao PR
    5 5 2017 ZCTA5 00610 27590 18741 Anasco PR
    6 6 2017 ZCTA5 00612 62566 17744 Arecibo PR
    Poptoincomeratio
    1.4968955
    2.4218036
    3.0120156
    0.4709046
    1.4721733
    3.5260370


    poptoincomeratio is basically Total_Population/Median_Income



    My objective is to find which zip code has the highest Poptoincomeratio:



    My input:



    max(sapply(zippopinc$Poptoincomeratio, max))


    Output:



    4.454182


    So I tried,



    zippopinc$Zip[demograph_ratio$Poptoincomeratio == 4.454182]


    But this gave me:



    factor(0)
    30956 Levels


    I then tried to convert zipopinc as a factor but got the below error:



    > as.factor(zippopinc)
    Error in sort.list(y) : 'x' must be atomic for 'sort.list'
    Have you called 'sort' on a list?


    How can I fix this?










    share|improve this question


























      6












      6








      6








      I am new to R and working on the below dataset:



      I have a file called zippopinc



      Repex:



      head(zippopinc)

      Year Zip Total_Population Median_Income City State
      1 1 2017 ZCTA5 00601 17599 11757 Adjuntas PR
      2 2 2017 ZCTA5 00602 39209 16190 Aguada PR
      3 3 2017 ZCTA5 00603 50135 16645 Aguadilla PR
      4 4 2017 ZCTA5 00606 6304 13387 Maricao PR
      5 5 2017 ZCTA5 00610 27590 18741 Anasco PR
      6 6 2017 ZCTA5 00612 62566 17744 Arecibo PR
      Poptoincomeratio
      1.4968955
      2.4218036
      3.0120156
      0.4709046
      1.4721733
      3.5260370


      poptoincomeratio is basically Total_Population/Median_Income



      My objective is to find which zip code has the highest Poptoincomeratio:



      My input:



      max(sapply(zippopinc$Poptoincomeratio, max))


      Output:



      4.454182


      So I tried,



      zippopinc$Zip[demograph_ratio$Poptoincomeratio == 4.454182]


      But this gave me:



      factor(0)
      30956 Levels


      I then tried to convert zipopinc as a factor but got the below error:



      > as.factor(zippopinc)
      Error in sort.list(y) : 'x' must be atomic for 'sort.list'
      Have you called 'sort' on a list?


      How can I fix this?










      share|improve this question
















      I am new to R and working on the below dataset:



      I have a file called zippopinc



      Repex:



      head(zippopinc)

      Year Zip Total_Population Median_Income City State
      1 1 2017 ZCTA5 00601 17599 11757 Adjuntas PR
      2 2 2017 ZCTA5 00602 39209 16190 Aguada PR
      3 3 2017 ZCTA5 00603 50135 16645 Aguadilla PR
      4 4 2017 ZCTA5 00606 6304 13387 Maricao PR
      5 5 2017 ZCTA5 00610 27590 18741 Anasco PR
      6 6 2017 ZCTA5 00612 62566 17744 Arecibo PR
      Poptoincomeratio
      1.4968955
      2.4218036
      3.0120156
      0.4709046
      1.4721733
      3.5260370


      poptoincomeratio is basically Total_Population/Median_Income



      My objective is to find which zip code has the highest Poptoincomeratio:



      My input:



      max(sapply(zippopinc$Poptoincomeratio, max))


      Output:



      4.454182


      So I tried,



      zippopinc$Zip[demograph_ratio$Poptoincomeratio == 4.454182]


      But this gave me:



      factor(0)
      30956 Levels


      I then tried to convert zipopinc as a factor but got the below error:



      > as.factor(zippopinc)
      Error in sort.list(y) : 'x' must be atomic for 'sort.list'
      Have you called 'sort' on a list?


      How can I fix this?







      r dplyr






      share|improve this question















      share|improve this question













      share|improve this question




      share|improve this question








      edited Mar 23 at 7:53









      Z.Lin

      14.6k32345




      14.6k32345










      asked Mar 23 at 2:18









      KidCodeKidCode

      504




      504






















          1 Answer
          1






          active

          oldest

          votes


















          0














          If you want to find which zip code has the highest Poptoincomeratio do :



          zippopinc$Zip[which.max(zippopinc$Poptoincomeratio)]


          The reason why it doesn't yield you any output with current approach is because there are some limitations in comparing floating point values. Read more here



          • Numeric comparison difficulty in R

          • Why are these numbers not equal?

          Even for the shared example, we can see that 3.5260370 is the highest value in Poptoincomeratio column but when we compare the values we get



          zippopinc$Poptoincomeratio == 3.5260370
          #[1] FALSE FALSE FALSE FALSE FALSE FALSE


          but if you use which.max it returns the highest Zip value



          zippopinc$Zip[which.max(zippopinc$Poptoincomeratio)]
          #[1] 612





          share|improve this answer

























          • Thanks.This is just a reproducible example and not the entire dataset, that is why you dont see 4.454182 @Ronak Shah. I mentioned #Repex.

            – KidCode
            Mar 23 at 2:41












          • @KidCode I know. Can you run zippopinc$Zip[which.max(zippopinc$Poptoincomeratio)] on your real data and compare the answer?

            – Ronak Shah
            Mar 23 at 2:41












          • Yes, I got it and marked your answer correct. :) thanks

            – KidCode
            Mar 23 at 2:43











          Your Answer






          StackExchange.ifUsing("editor", function ()
          StackExchange.using("externalEditor", function ()
          StackExchange.using("snippets", function ()
          StackExchange.snippets.init();
          );
          );
          , "code-snippets");

          StackExchange.ready(function()
          var channelOptions =
          tags: "".split(" "),
          id: "1"
          ;
          initTagRenderer("".split(" "), "".split(" "), channelOptions);

          StackExchange.using("externalEditor", function()
          // Have to fire editor after snippets, if snippets enabled
          if (StackExchange.settings.snippets.snippetsEnabled)
          StackExchange.using("snippets", function()
          createEditor();
          );

          else
          createEditor();

          );

          function createEditor()
          StackExchange.prepareEditor(
          heartbeatType: 'answer',
          autoActivateHeartbeat: false,
          convertImagesToLinks: true,
          noModals: true,
          showLowRepImageUploadWarning: true,
          reputationToPostImages: 10,
          bindNavPrevention: true,
          postfix: "",
          imageUploader:
          brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
          contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
          allowUrls: true
          ,
          onDemand: true,
          discardSelector: ".discard-answer"
          ,immediatelyShowMarkdownHelp:true
          );



          );













          draft saved

          draft discarded


















          StackExchange.ready(
          function ()
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55309993%2feven-after-converting-my-file-as-factor-why-does-my-output-give-factor0-30956%23new-answer', 'question_page');

          );

          Post as a guest















          Required, but never shown

























          1 Answer
          1






          active

          oldest

          votes








          1 Answer
          1






          active

          oldest

          votes









          active

          oldest

          votes






          active

          oldest

          votes









          0














          If you want to find which zip code has the highest Poptoincomeratio do :



          zippopinc$Zip[which.max(zippopinc$Poptoincomeratio)]


          The reason why it doesn't yield you any output with current approach is because there are some limitations in comparing floating point values. Read more here



          • Numeric comparison difficulty in R

          • Why are these numbers not equal?

          Even for the shared example, we can see that 3.5260370 is the highest value in Poptoincomeratio column but when we compare the values we get



          zippopinc$Poptoincomeratio == 3.5260370
          #[1] FALSE FALSE FALSE FALSE FALSE FALSE


          but if you use which.max it returns the highest Zip value



          zippopinc$Zip[which.max(zippopinc$Poptoincomeratio)]
          #[1] 612





          share|improve this answer

























          • Thanks.This is just a reproducible example and not the entire dataset, that is why you dont see 4.454182 @Ronak Shah. I mentioned #Repex.

            – KidCode
            Mar 23 at 2:41












          • @KidCode I know. Can you run zippopinc$Zip[which.max(zippopinc$Poptoincomeratio)] on your real data and compare the answer?

            – Ronak Shah
            Mar 23 at 2:41












          • Yes, I got it and marked your answer correct. :) thanks

            – KidCode
            Mar 23 at 2:43















          0














          If you want to find which zip code has the highest Poptoincomeratio do :



          zippopinc$Zip[which.max(zippopinc$Poptoincomeratio)]


          The reason why it doesn't yield you any output with current approach is because there are some limitations in comparing floating point values. Read more here



          • Numeric comparison difficulty in R

          • Why are these numbers not equal?

          Even for the shared example, we can see that 3.5260370 is the highest value in Poptoincomeratio column but when we compare the values we get



          zippopinc$Poptoincomeratio == 3.5260370
          #[1] FALSE FALSE FALSE FALSE FALSE FALSE


          but if you use which.max it returns the highest Zip value



          zippopinc$Zip[which.max(zippopinc$Poptoincomeratio)]
          #[1] 612





          share|improve this answer

























          • Thanks.This is just a reproducible example and not the entire dataset, that is why you dont see 4.454182 @Ronak Shah. I mentioned #Repex.

            – KidCode
            Mar 23 at 2:41












          • @KidCode I know. Can you run zippopinc$Zip[which.max(zippopinc$Poptoincomeratio)] on your real data and compare the answer?

            – Ronak Shah
            Mar 23 at 2:41












          • Yes, I got it and marked your answer correct. :) thanks

            – KidCode
            Mar 23 at 2:43













          0












          0








          0







          If you want to find which zip code has the highest Poptoincomeratio do :



          zippopinc$Zip[which.max(zippopinc$Poptoincomeratio)]


          The reason why it doesn't yield you any output with current approach is because there are some limitations in comparing floating point values. Read more here



          • Numeric comparison difficulty in R

          • Why are these numbers not equal?

          Even for the shared example, we can see that 3.5260370 is the highest value in Poptoincomeratio column but when we compare the values we get



          zippopinc$Poptoincomeratio == 3.5260370
          #[1] FALSE FALSE FALSE FALSE FALSE FALSE


          but if you use which.max it returns the highest Zip value



          zippopinc$Zip[which.max(zippopinc$Poptoincomeratio)]
          #[1] 612





          share|improve this answer















          If you want to find which zip code has the highest Poptoincomeratio do :



          zippopinc$Zip[which.max(zippopinc$Poptoincomeratio)]


          The reason why it doesn't yield you any output with current approach is because there are some limitations in comparing floating point values. Read more here



          • Numeric comparison difficulty in R

          • Why are these numbers not equal?

          Even for the shared example, we can see that 3.5260370 is the highest value in Poptoincomeratio column but when we compare the values we get



          zippopinc$Poptoincomeratio == 3.5260370
          #[1] FALSE FALSE FALSE FALSE FALSE FALSE


          but if you use which.max it returns the highest Zip value



          zippopinc$Zip[which.max(zippopinc$Poptoincomeratio)]
          #[1] 612






          share|improve this answer














          share|improve this answer



          share|improve this answer








          edited Mar 23 at 2:38

























          answered Mar 23 at 2:31









          Ronak ShahRonak Shah

          51.9k104371




          51.9k104371












          • Thanks.This is just a reproducible example and not the entire dataset, that is why you dont see 4.454182 @Ronak Shah. I mentioned #Repex.

            – KidCode
            Mar 23 at 2:41












          • @KidCode I know. Can you run zippopinc$Zip[which.max(zippopinc$Poptoincomeratio)] on your real data and compare the answer?

            – Ronak Shah
            Mar 23 at 2:41












          • Yes, I got it and marked your answer correct. :) thanks

            – KidCode
            Mar 23 at 2:43

















          • Thanks.This is just a reproducible example and not the entire dataset, that is why you dont see 4.454182 @Ronak Shah. I mentioned #Repex.

            – KidCode
            Mar 23 at 2:41












          • @KidCode I know. Can you run zippopinc$Zip[which.max(zippopinc$Poptoincomeratio)] on your real data and compare the answer?

            – Ronak Shah
            Mar 23 at 2:41












          • Yes, I got it and marked your answer correct. :) thanks

            – KidCode
            Mar 23 at 2:43
















          Thanks.This is just a reproducible example and not the entire dataset, that is why you dont see 4.454182 @Ronak Shah. I mentioned #Repex.

          – KidCode
          Mar 23 at 2:41






          Thanks.This is just a reproducible example and not the entire dataset, that is why you dont see 4.454182 @Ronak Shah. I mentioned #Repex.

          – KidCode
          Mar 23 at 2:41














          @KidCode I know. Can you run zippopinc$Zip[which.max(zippopinc$Poptoincomeratio)] on your real data and compare the answer?

          – Ronak Shah
          Mar 23 at 2:41






          @KidCode I know. Can you run zippopinc$Zip[which.max(zippopinc$Poptoincomeratio)] on your real data and compare the answer?

          – Ronak Shah
          Mar 23 at 2:41














          Yes, I got it and marked your answer correct. :) thanks

          – KidCode
          Mar 23 at 2:43





          Yes, I got it and marked your answer correct. :) thanks

          – KidCode
          Mar 23 at 2:43



















          draft saved

          draft discarded
















































          Thanks for contributing an answer to Stack Overflow!


          • Please be sure to answer the question. Provide details and share your research!

          But avoid


          • Asking for help, clarification, or responding to other answers.

          • Making statements based on opinion; back them up with references or personal experience.

          To learn more, see our tips on writing great answers.




          draft saved


          draft discarded














          StackExchange.ready(
          function ()
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55309993%2feven-after-converting-my-file-as-factor-why-does-my-output-give-factor0-30956%23new-answer', 'question_page');

          );

          Post as a guest















          Required, but never shown





















































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown

































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown







          Popular posts from this blog

          Kamusi Yaliyomo Aina za kamusi | Muundo wa kamusi | Faida za kamusi | Dhima ya picha katika kamusi | Marejeo | Tazama pia | Viungo vya nje | UrambazajiKuhusu kamusiGo-SwahiliWiki-KamusiKamusi ya Kiswahili na Kiingerezakuihariri na kuongeza habari

          Swift 4 - func physicsWorld not invoked on collision? The Next CEO of Stack OverflowHow to call Objective-C code from Swift#ifdef replacement in the Swift language@selector() in Swift?#pragma mark in Swift?Swift for loop: for index, element in array?dispatch_after - GCD in Swift?Swift Beta performance: sorting arraysSplit a String into an array in Swift?The use of Swift 3 @objc inference in Swift 4 mode is deprecated?How to optimize UITableViewCell, because my UITableView lags

          Access current req object everywhere in Node.js ExpressWhy are global variables considered bad practice? (node.js)Using req & res across functionsHow do I get the path to the current script with Node.js?What is Node.js' Connect, Express and “middleware”?Node.js w/ express error handling in callbackHow to access the GET parameters after “?” in Express?Modify Node.js req object parametersAccess “app” variable inside of ExpressJS/ConnectJS middleware?Node.js Express app - request objectAngular Http Module considered middleware?Session variables in ExpressJSAdd properties to the req object in expressjs with Typescript