[R] logical operator for different dimensions

uday uday_143_4u at hotmail.com
Mon Feb 13 11:08:52 CET 2012


I have some dataset 


 sci.pre <- 0.30    0.38    0.50    0.65    0.80    1.03    1.33    1.72   
2.22
  2.87    3.81    5.06    6.75    9.00   11.97   14.15   16.34   19.04
  22.27   25.49   29.72   34.67   40.47   47.29   55.29   64.67   75.6
   88.50  103.50  121.10  141.70  165.80  194.00  227.00  265.00  308.00
356.50  411.00  441.60  472.20  506.35  540.50  578.55  616.60  637.75
  658.90  680.05  701.20  724.65  748.10  771.55  795.00  820.95  846.90
  872.85  898.80  927.35  955.90  984.45 1013.00  ( length is 60)

sci.avgkernal < - 0.30    0.38    0.50    0.65    0.80    1.03    1.33   
1.72    2.22
2.87    3.81    5.06    6.75    9.00   11.97   14.15   16.34   19.04
 22.27   25.49   29.72   34.67   40.47   47.29   55.29   64.67   75.65
 88.50  103.50  121.10  141.70  165.80  194.00  227.00  265.00  308.00
356.50  411.00  441.60  472.20  506.35  540.50  578.55  616.60  637.75
658.90  680.05  701.20  724.65  748.10  771.55  795.00  820.95  846.90
  872.85  898.80  927.35  955.90  984.45 1013.00 ( length is 60)

pres.interptimes <-          [,1]      [,2]     [,3]     [,4]     [,5]    
[,6]     [,7]     [,8]
[1,] 1016.1267 1005.9741 989.9127 970.0237 945.6067 880.5082 790.4647
675.8315
[2,]  875.6320  866.8767 853.0258 835.8741 814.8176 758.6784 681.0275
582.1712
[3,]  996.0351  986.0758 970.3201 950.8098 926.8576 862.9984 774.6692
662.2184
[4,]  996.0353  986.0760 970.3203 950.8100 926.8578 862.9987 774.6694
662.2187
[5,] 1008.0222  997.9431 981.9978 962.2527 938.0123 873.3847 783.9926
670.1888
[6,]  999.8343  989.8371 974.0214 954.4367 930.3932 866.2906 777.6247
664.7453
         [,9]    [,10]    [,11]    [,12]    [,13]    [,14]    [,15]    [,16]
[1,] 544.3248 410.3611 289.4130 237.2794 191.5622 152.3020 119.1842 91.68080
[2,] 468.7636 353.2371 248.9350 203.9765 164.5513 130.6945 102.1346 78.41645
[3,] 533.2153 401.8020 283.1566 232.0154 187.1686 148.6559 116.1686 89.18875
[4,] 533.2155 401.8022 283.1568 232.0157 187.1688 148.6561 116.1688 89.18898
[5,] 539.6334 406.6388 286.5657 234.8092 189.4227 150.4466 117.5683 90.26387
[6,] 535.2505 403.3363 284.2386 232.9026 187.8848 149.2253 116.6141 89.53148
        [,17]    [,18]    [,19]     [,20]
[1,] 69.12170 50.81654 24.30808 0.8657024
[2,] 58.96213 43.17629 20.31615 0.1001228
[3,] 67.05913 49.10247 23.09867 0.1025881
[4,] 67.05936 49.10270 23.09890 0.1028196
[5,] 67.86797 49.69524 23.37854 0.1057444
[6,] 67.31751 49.29240 23.18949 0.1057560 ( dim is 6 20) 

sci.prediff   <- diff(sci.pre) 
sci.prediff   <- c(sci.pre[1],sci.prediff) 
sum(sci.avgkernal*sci.prediff )/sum(sci.prediff )
pres.interptimes  <- pres.interptime[,-20]#skip last level
tm3.avgkernal <-array(NA,c(length(1:nobs),19))
for (k in 1:nobs){
   for (h in 1:19){
 	  sel                <- sci.pre <= pres.interptimes[k,h] & sci.pre >
pres.interptimes[k,h+1]
 	  tm3.avgkernal[k,h] <- sum((sci.avgkernal * sci.prediff)[sel]) /
sum(sci.prediff[sel])
 	}
       }

after running code I get error 

Error: subscript out of bounds

How to fix this error ?


--
View this message in context: http://r.789695.n4.nabble.com/logical-operator-for-different-dimensions-tp4383316p4383316.html
Sent from the R help mailing list archive at Nabble.com.



More information about the R-help mailing list