r - if() simple loop code -


say have 2 data sets. ill call first set train , here variables

month = c(1,1,1,2,2,2,3,3,3,4,4,4) day=c(3,8,12,3,8,12,3,8,12,3,8,12) trend=c(0.1,0.2,0.3,0.4,0.5,0.4,0.3,0.2,0.1,0.2,0.3,0.4)    train=cbind(month,day,trend) 

and second set called test, has month , day variables

tsmonth = c(1,2,2,3,3,3,4,4,4) tsday=c(3,3,12,3,8,12,3,8,12) 

now want fill in trend portion of test set using values training data example: in test set, january 3rd, had trend value of 0.1 there first value in test should 0.1 in end should

tstrend = 0.1, 0.4, 0.4....so on

i tried code gave me error msg , don't know change here

tstrend=rep(0,length(tsmonth)) (i in 1:length(tsmonth)){ (j in 1:length(month)){ if (tsday[i] = day[j] & tsmonth[i] =month[j]) { tstrend[i] = trend[j] } } } 

i appreciate help.

thank you, a

i don't quite understand trying do, definetly see wrong if() statement, should be:

if (tsday[i] == day[j] && tsmonth[i] == month[j]) 

== compare = assign value

in languages: boolean expression && boolean expression -> boolean (true/false) and

ex: true && true -> true

bit array & bit array 2 -> bitwise and

ex: 0011 & 0101 -> 0001


Comments

Popular posts from this blog

java - WrongTypeOfReturnValue exception thrown when unit testing using mockito -

php - Magento - Deleted Base url key -

android - How to disable Button if EditText is empty ? -