Unable to designate CSV column heads “as.factor” for R -Error









up vote
0
down vote

favorite












I am having an issue with assigning factors to my data CSV. Here is a summary of the data frame:



> data.frame': 303 obs. of 12 variables:
> PLOT : int 19 177 54 114 41 48 142 134 160 267 ...
> RANGE : int 2 12 4 8 3 4 10 9 11 18 ...
> ROW : int 4 12 9 9 11 3 7 14 10 12 ...
> REP : int 1 1 1 1 1 1 1 1 1 1 ...
> ENTRY : Factor w/ 184 levels "","17_YMG_0293",..: 40 40 77 82 87 88 102 103 103 6 ...
> PLOT_ID : Factor w/ 301 levels "","18_HZG_OvOv_001",..: 20 178 55 115 42 49 143 135 161 268 ...
> Shatter : num 9 9 9 9 9 9 9 9 9 8 ...
> Chaff.Color : Factor w/ 4 levels "","*Blank ones are segregating in color",..: 3 4 3 4 4 4 3 4 4 3 ...
> Heading_d.from.Jan.1: int 138 139 137 133 135 135 133 137 135 136 ...
> Height_cm : int 74 73 77 76 74 79 78 73 76 70 ...
> Plot.weight..kg. : num 0.26 0.18 0.19 0.14 0.33 0.19 0.13 0.11 0.24 0.18 ...


But I get this error:



HAYSData$Rep<-as.factor(HAYSData$Rep)
Error in `$<-.data.frame`(`*tmp*`, Rep, value = integer(0)) :
replacement has 0 rows, data has 303


I get the same type of error for Entry, Range, and Rows. I am not sure when I look at length(Entry) for example I get 300. I even tested with changing factor to numeric but it does not help.



I don't have an NA in my data each category is its own column as well.



I don't know if something is wrong with my CSV. I have worked this same script with another CSV but no issues in the part of the script for the other data.



Can someone please help me?










share|improve this question



























    up vote
    0
    down vote

    favorite












    I am having an issue with assigning factors to my data CSV. Here is a summary of the data frame:



    > data.frame': 303 obs. of 12 variables:
    > PLOT : int 19 177 54 114 41 48 142 134 160 267 ...
    > RANGE : int 2 12 4 8 3 4 10 9 11 18 ...
    > ROW : int 4 12 9 9 11 3 7 14 10 12 ...
    > REP : int 1 1 1 1 1 1 1 1 1 1 ...
    > ENTRY : Factor w/ 184 levels "","17_YMG_0293",..: 40 40 77 82 87 88 102 103 103 6 ...
    > PLOT_ID : Factor w/ 301 levels "","18_HZG_OvOv_001",..: 20 178 55 115 42 49 143 135 161 268 ...
    > Shatter : num 9 9 9 9 9 9 9 9 9 8 ...
    > Chaff.Color : Factor w/ 4 levels "","*Blank ones are segregating in color",..: 3 4 3 4 4 4 3 4 4 3 ...
    > Heading_d.from.Jan.1: int 138 139 137 133 135 135 133 137 135 136 ...
    > Height_cm : int 74 73 77 76 74 79 78 73 76 70 ...
    > Plot.weight..kg. : num 0.26 0.18 0.19 0.14 0.33 0.19 0.13 0.11 0.24 0.18 ...


    But I get this error:



    HAYSData$Rep<-as.factor(HAYSData$Rep)
    Error in `$<-.data.frame`(`*tmp*`, Rep, value = integer(0)) :
    replacement has 0 rows, data has 303


    I get the same type of error for Entry, Range, and Rows. I am not sure when I look at length(Entry) for example I get 300. I even tested with changing factor to numeric but it does not help.



    I don't have an NA in my data each category is its own column as well.



    I don't know if something is wrong with my CSV. I have worked this same script with another CSV but no issues in the part of the script for the other data.



    Can someone please help me?










    share|improve this question

























      up vote
      0
      down vote

      favorite









      up vote
      0
      down vote

      favorite











      I am having an issue with assigning factors to my data CSV. Here is a summary of the data frame:



      > data.frame': 303 obs. of 12 variables:
      > PLOT : int 19 177 54 114 41 48 142 134 160 267 ...
      > RANGE : int 2 12 4 8 3 4 10 9 11 18 ...
      > ROW : int 4 12 9 9 11 3 7 14 10 12 ...
      > REP : int 1 1 1 1 1 1 1 1 1 1 ...
      > ENTRY : Factor w/ 184 levels "","17_YMG_0293",..: 40 40 77 82 87 88 102 103 103 6 ...
      > PLOT_ID : Factor w/ 301 levels "","18_HZG_OvOv_001",..: 20 178 55 115 42 49 143 135 161 268 ...
      > Shatter : num 9 9 9 9 9 9 9 9 9 8 ...
      > Chaff.Color : Factor w/ 4 levels "","*Blank ones are segregating in color",..: 3 4 3 4 4 4 3 4 4 3 ...
      > Heading_d.from.Jan.1: int 138 139 137 133 135 135 133 137 135 136 ...
      > Height_cm : int 74 73 77 76 74 79 78 73 76 70 ...
      > Plot.weight..kg. : num 0.26 0.18 0.19 0.14 0.33 0.19 0.13 0.11 0.24 0.18 ...


      But I get this error:



      HAYSData$Rep<-as.factor(HAYSData$Rep)
      Error in `$<-.data.frame`(`*tmp*`, Rep, value = integer(0)) :
      replacement has 0 rows, data has 303


      I get the same type of error for Entry, Range, and Rows. I am not sure when I look at length(Entry) for example I get 300. I even tested with changing factor to numeric but it does not help.



      I don't have an NA in my data each category is its own column as well.



      I don't know if something is wrong with my CSV. I have worked this same script with another CSV but no issues in the part of the script for the other data.



      Can someone please help me?










      share|improve this question















      I am having an issue with assigning factors to my data CSV. Here is a summary of the data frame:



      > data.frame': 303 obs. of 12 variables:
      > PLOT : int 19 177 54 114 41 48 142 134 160 267 ...
      > RANGE : int 2 12 4 8 3 4 10 9 11 18 ...
      > ROW : int 4 12 9 9 11 3 7 14 10 12 ...
      > REP : int 1 1 1 1 1 1 1 1 1 1 ...
      > ENTRY : Factor w/ 184 levels "","17_YMG_0293",..: 40 40 77 82 87 88 102 103 103 6 ...
      > PLOT_ID : Factor w/ 301 levels "","18_HZG_OvOv_001",..: 20 178 55 115 42 49 143 135 161 268 ...
      > Shatter : num 9 9 9 9 9 9 9 9 9 8 ...
      > Chaff.Color : Factor w/ 4 levels "","*Blank ones are segregating in color",..: 3 4 3 4 4 4 3 4 4 3 ...
      > Heading_d.from.Jan.1: int 138 139 137 133 135 135 133 137 135 136 ...
      > Height_cm : int 74 73 77 76 74 79 78 73 76 70 ...
      > Plot.weight..kg. : num 0.26 0.18 0.19 0.14 0.33 0.19 0.13 0.11 0.24 0.18 ...


      But I get this error:



      HAYSData$Rep<-as.factor(HAYSData$Rep)
      Error in `$<-.data.frame`(`*tmp*`, Rep, value = integer(0)) :
      replacement has 0 rows, data has 303


      I get the same type of error for Entry, Range, and Rows. I am not sure when I look at length(Entry) for example I get 300. I even tested with changing factor to numeric but it does not help.



      I don't have an NA in my data each category is its own column as well.



      I don't know if something is wrong with my CSV. I have worked this same script with another CSV but no issues in the part of the script for the other data.



      Can someone please help me?







      r linear-regression






      share|improve this question















      share|improve this question













      share|improve this question




      share|improve this question








      edited Nov 10 at 9:04









      jay.sf

      4,22621436




      4,22621436










      asked Nov 10 at 7:38









      wardah m

      74




      74






















          1 Answer
          1






          active

          oldest

          votes

















          up vote
          0
          down vote













          It's case-sensitive, try with:



          HAYSData$REP <- as.factor(HAYSData$REP)
          HAYSData$ENTRY <- as.factor(HAYSData$ENTRY)
          HAYSData$RANGE <- as.factor(HAYSData$RANGE)
          HAYSData$ROW <- as.factor(HAYSData$ROW)





          share|improve this answer




















            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',
            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%2f53236964%2funable-to-designate-csv-column-heads-as-factor-for-r-error%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








            up vote
            0
            down vote













            It's case-sensitive, try with:



            HAYSData$REP <- as.factor(HAYSData$REP)
            HAYSData$ENTRY <- as.factor(HAYSData$ENTRY)
            HAYSData$RANGE <- as.factor(HAYSData$RANGE)
            HAYSData$ROW <- as.factor(HAYSData$ROW)





            share|improve this answer
























              up vote
              0
              down vote













              It's case-sensitive, try with:



              HAYSData$REP <- as.factor(HAYSData$REP)
              HAYSData$ENTRY <- as.factor(HAYSData$ENTRY)
              HAYSData$RANGE <- as.factor(HAYSData$RANGE)
              HAYSData$ROW <- as.factor(HAYSData$ROW)





              share|improve this answer






















                up vote
                0
                down vote










                up vote
                0
                down vote









                It's case-sensitive, try with:



                HAYSData$REP <- as.factor(HAYSData$REP)
                HAYSData$ENTRY <- as.factor(HAYSData$ENTRY)
                HAYSData$RANGE <- as.factor(HAYSData$RANGE)
                HAYSData$ROW <- as.factor(HAYSData$ROW)





                share|improve this answer












                It's case-sensitive, try with:



                HAYSData$REP <- as.factor(HAYSData$REP)
                HAYSData$ENTRY <- as.factor(HAYSData$ENTRY)
                HAYSData$RANGE <- as.factor(HAYSData$RANGE)
                HAYSData$ROW <- as.factor(HAYSData$ROW)






                share|improve this answer












                share|improve this answer



                share|improve this answer










                answered Nov 10 at 8:37









                arg0naut

                1,657312




                1,657312



























                    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.





                    Some of your past answers have not been well-received, and you're in danger of being blocked from answering.


                    Please pay close attention to the following guidance:


                    • 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%2f53236964%2funable-to-designate-csv-column-heads-as-factor-for-r-error%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

                    How to how show current date and time by default on contact form 7 in WordPress without taking input from user in datetimepicker

                    Syphilis

                    Darth Vader #20