[R] setting off-diagonals to zero
arun
smartpink111 at yahoo.com
Thu Jan 24 03:56:28 CET 2013
HI,
Not sure this is what you wanted.
for (i in 731:732) {
SEQ <- (i - 5):(i + 5)
print(SEQ)
SEQ <- SEQ[SEQ > 730 & SEQ < 1096]
print(SEQ)
vec1<-731:741
print(vec1[!vec1%in%SEQ])
}
#[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
# [1] 727 728 729 730 731 732 733 734 735 736 737
#[1] 731 732 733 734 735 736 737
#[1] 738 739 740 741
A.K.
----- Original Message -----
From: emorway <emorway at usgs.gov>
To: r-help at r-project.org
Cc:
Sent: Wednesday, January 23, 2013 7:58 PM
Subject: Re: [R] setting off-diagonals to zero
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? 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.
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