For loop in R assigning to a data frame

后端 未结 1 1823
予麋鹿
予麋鹿 2021-01-26 05:22

I am having trouble assigning to a dataframe after running the for loop. When I use print it give my value, any explanation to it?

 salesdate<-rep(seq(from=as         


        
相关标签:
1条回答
  • 2021-01-26 06:21

    You are mixing vectorized processing with indexed. In the first example, you assign the one number from (length.....) to all elements of test, overwriting the numbers on each cycle. Only the last assignment is printed.

    something like:

    test = rep(NA,length(new))
    
    for (i in new)
      test[i] = your number
    

    will work. As Paul mentions, the code is not very R-ish, but since you did not provide msales, I cannot give you a better example.

    0 讨论(0)
提交回复
热议问题