[R] setting off-diagonals to zero

Berend Hasselman bhh at xs4all.nl
Thu Jan 24 06:44:03 CET 2013


On 24-01-2013, at 01:58, emorway <emorway at usgs.gov> wrote:

> I'm not following.  Printing SEQ to the screen at the intermediate steps
> using the following modified R code suggests that 'i' is fine and is not
> getting reset to 1 as you suggest?

You misread. I did not say anything about 'i'.

>  My understanding, or rather my desired
> output if someone else is able to weight-in, is that the values in the
> second line of output (731 732 733 etc.) should not be appearing in the 3rd
> line of output.  The third line of output should be missing 731 thru 736. 

Well then look at this

for (i in 731:732) {
 SEQ <- (i - 5):(i + 5)
 print(SEQ)
 SEQ <- SEQ[SEQ > 730 & SEQ < 1096]
 print(SEQ)
 print((731:1095)[-(-730+SEQ)])  # my modification
}

# [1] 726 727 728 729 730 731 732 733 734 735 736
# [1] 731 732 733 734 735 736
# [1]  737  738  739  740  741  742  743  744  745  746  747  748  749  750  751

which seems to give the desired output

> Any suggestions on how to modify the R code are certainly welcome. 
> Suggested revisions will be substituted back into the third FOR loop in my
> original post on this thread to prevent the main- and near-main-diagonal
> terms from being set equal to zero.
> 
> for (i in 731:732) {
>  SEQ <- (i - 5):(i + 5)
>  print(SEQ)
>  SEQ <- SEQ[SEQ > 730 & SEQ < 1096]
>  print(SEQ)
>  print((731:1095)[-SEQ])
> }
> 
> # [1] 726 727 728 729 730 731 732 733 734 735 736
> # [1] 731 732 733 734 735 736
> # [1]  731  732  733  734  735  736  737  738  739  740  741  742  743  744 
> 745  746  747  748  749  750  751  752  753  754  755  756...
> 
> 
> 
> 
> --
> View this message in context: http://r.789695.n4.nabble.com/setting-off-diagonals-to-zero-tp4656407p4656461.html
> Sent from the R help mailing list archive at Nabble.com.
> 
> ______________________________________________
> R-help at r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.



More information about the R-help mailing list