if statements give me several warnings what do they mean?










-1















 fkelly6 = matrix(data = NA, nrow = 252, 3)

for(i in 1:252)

fkelly6[i,] = matrix(c(ftmp6[i,],1-sum(ftmp6[i,])),1,3)
if(fkelly6[i,]>= 15)
fkelly6[i,]<-15




I want check if all the f are >= 15 and in case substitute them with 15.
the code works but it gives me several warnings that say: "In if (fkelly6[i, ] >= 15) { ... :
the condition has length > 1 and only the first element will be used"
what do them mean?
thanks










share|improve this question
























  • the error is because in your if you have a vector of length 3 (in this case) and it's compared to a scalar (15), so the condition as length > 1. Basically you have something like c(10, 15, 10) > 15, the if can't work this way.

    – RLave
    Nov 13 '18 at 8:10











  • so I have to create a vector of length 3 and fill it up with 15?

    – Tommaso Dellolmo
    Nov 13 '18 at 8:10















-1















 fkelly6 = matrix(data = NA, nrow = 252, 3)

for(i in 1:252)

fkelly6[i,] = matrix(c(ftmp6[i,],1-sum(ftmp6[i,])),1,3)
if(fkelly6[i,]>= 15)
fkelly6[i,]<-15




I want check if all the f are >= 15 and in case substitute them with 15.
the code works but it gives me several warnings that say: "In if (fkelly6[i, ] >= 15) { ... :
the condition has length > 1 and only the first element will be used"
what do them mean?
thanks










share|improve this question
























  • the error is because in your if you have a vector of length 3 (in this case) and it's compared to a scalar (15), so the condition as length > 1. Basically you have something like c(10, 15, 10) > 15, the if can't work this way.

    – RLave
    Nov 13 '18 at 8:10











  • so I have to create a vector of length 3 and fill it up with 15?

    – Tommaso Dellolmo
    Nov 13 '18 at 8:10













-1












-1








-1








 fkelly6 = matrix(data = NA, nrow = 252, 3)

for(i in 1:252)

fkelly6[i,] = matrix(c(ftmp6[i,],1-sum(ftmp6[i,])),1,3)
if(fkelly6[i,]>= 15)
fkelly6[i,]<-15




I want check if all the f are >= 15 and in case substitute them with 15.
the code works but it gives me several warnings that say: "In if (fkelly6[i, ] >= 15) { ... :
the condition has length > 1 and only the first element will be used"
what do them mean?
thanks










share|improve this question
















 fkelly6 = matrix(data = NA, nrow = 252, 3)

for(i in 1:252)

fkelly6[i,] = matrix(c(ftmp6[i,],1-sum(ftmp6[i,])),1,3)
if(fkelly6[i,]>= 15)
fkelly6[i,]<-15




I want check if all the f are >= 15 and in case substitute them with 15.
the code works but it gives me several warnings that say: "In if (fkelly6[i, ] >= 15) { ... :
the condition has length > 1 and only the first element will be used"
what do them mean?
thanks







r if-statement






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Nov 13 '18 at 8:06







Tommaso Dellolmo

















asked Nov 13 '18 at 8:04









Tommaso DellolmoTommaso Dellolmo

75




75












  • the error is because in your if you have a vector of length 3 (in this case) and it's compared to a scalar (15), so the condition as length > 1. Basically you have something like c(10, 15, 10) > 15, the if can't work this way.

    – RLave
    Nov 13 '18 at 8:10











  • so I have to create a vector of length 3 and fill it up with 15?

    – Tommaso Dellolmo
    Nov 13 '18 at 8:10

















  • the error is because in your if you have a vector of length 3 (in this case) and it's compared to a scalar (15), so the condition as length > 1. Basically you have something like c(10, 15, 10) > 15, the if can't work this way.

    – RLave
    Nov 13 '18 at 8:10











  • so I have to create a vector of length 3 and fill it up with 15?

    – Tommaso Dellolmo
    Nov 13 '18 at 8:10
















the error is because in your if you have a vector of length 3 (in this case) and it's compared to a scalar (15), so the condition as length > 1. Basically you have something like c(10, 15, 10) > 15, the if can't work this way.

– RLave
Nov 13 '18 at 8:10





the error is because in your if you have a vector of length 3 (in this case) and it's compared to a scalar (15), so the condition as length > 1. Basically you have something like c(10, 15, 10) > 15, the if can't work this way.

– RLave
Nov 13 '18 at 8:10













so I have to create a vector of length 3 and fill it up with 15?

– Tommaso Dellolmo
Nov 13 '18 at 8:10





so I have to create a vector of length 3 and fill it up with 15?

– Tommaso Dellolmo
Nov 13 '18 at 8:10












1 Answer
1






active

oldest

votes


















0














This is how you can change some values without a loop:



m <- matrix(1:6, nrow = 2, ncol = 3)
m
# [,1] [,2] [,3]
# [1,] 1 3 5
# [2,] 2 4 6

m[m>=4] <- 0 # every value which is >=4 will be set to zero
m
# [,1] [,2] [,3]
# [1,] 1 3 0
# [2,] 2 0 0





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',
    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%2f53276385%2fif-statements-give-me-several-warnings-what-do-they-mean%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














    This is how you can change some values without a loop:



    m <- matrix(1:6, nrow = 2, ncol = 3)
    m
    # [,1] [,2] [,3]
    # [1,] 1 3 5
    # [2,] 2 4 6

    m[m>=4] <- 0 # every value which is >=4 will be set to zero
    m
    # [,1] [,2] [,3]
    # [1,] 1 3 0
    # [2,] 2 0 0





    share|improve this answer



























      0














      This is how you can change some values without a loop:



      m <- matrix(1:6, nrow = 2, ncol = 3)
      m
      # [,1] [,2] [,3]
      # [1,] 1 3 5
      # [2,] 2 4 6

      m[m>=4] <- 0 # every value which is >=4 will be set to zero
      m
      # [,1] [,2] [,3]
      # [1,] 1 3 0
      # [2,] 2 0 0





      share|improve this answer

























        0












        0








        0







        This is how you can change some values without a loop:



        m <- matrix(1:6, nrow = 2, ncol = 3)
        m
        # [,1] [,2] [,3]
        # [1,] 1 3 5
        # [2,] 2 4 6

        m[m>=4] <- 0 # every value which is >=4 will be set to zero
        m
        # [,1] [,2] [,3]
        # [1,] 1 3 0
        # [2,] 2 0 0





        share|improve this answer













        This is how you can change some values without a loop:



        m <- matrix(1:6, nrow = 2, ncol = 3)
        m
        # [,1] [,2] [,3]
        # [1,] 1 3 5
        # [2,] 2 4 6

        m[m>=4] <- 0 # every value which is >=4 will be set to zero
        m
        # [,1] [,2] [,3]
        # [1,] 1 3 0
        # [2,] 2 0 0






        share|improve this answer












        share|improve this answer



        share|improve this answer










        answered Nov 13 '18 at 8:14









        RLaveRLave

        3,8501922




        3,8501922



























            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%2f53276385%2fif-statements-give-me-several-warnings-what-do-they-mean%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







            這個網誌中的熱門文章

            How to read a connectionString WITH PROVIDER in .NET Core?

            In R, how to develop a multiplot heatmap.2 figure showing key labels successfully

            Museum of Modern and Contemporary Art of Trento and Rovereto