Hi, I'm trying to figure out how to properly construct a graph of frequencies of a difference between 2 values, that is | i | - | j |. I'd like to know the best way to store the actual data because of course doing my_vector[i -j] will not work because the index could be negative. I know there's no hash table so what's the best solution, simplicity-wise ? Use a list of pair of values {index, i - j} ? Or can I somehow use negative index, perhaps using 0array ? Any help would be appreciated :) ATM, I use as.character (i-j) to index my data, but I lose all the processing power of R there after. Sorry If it's written somewhere, but I read a lot of docs about it, searched through the ML archives and didn't manage to find an answer. Please also answer me back at my email address as I am not subscribed to the list. Best regards, --Stephane
Do you mean something like abs( my_vector[i] - my_vector[j] ) See if reading help("subset") helps. On Wed, 2004-07-28 at 01:42, StephaneDemurget wrote:> Hi, > > I'm trying to figure out how to properly construct a graph of > frequencies of a difference between 2 values, that is | i | - | j |. > I'd like to know the best way to store the actual data because of course > doing my_vector[i -j] will not work because the index could be negative. > > I know there's no hash table so what's the best solution, > simplicity-wise ? Use a list of pair of values {index, i - j} ? Or can I > somehow use negative index, perhaps using 0array ? Any help would be > appreciated :) > > ATM, I use as.character (i-j) to index my data, but I lose all the > processing power of R there after. > > Sorry If it's written somewhere, but I read a lot of docs about it, > searched through the ML archives and didn't manage to find an answer. > > Please also answer me back at my email address as I am not subscribed to > the list. > > Best regards, > > --Stephane > > ______________________________________________ > R-help at stat.math.ethz.ch mailing list > https://www.stat.math.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html >
Can you give a simple example of what you are trying to do? Would the following help?> x <- sample(10) > diffMat <- outer(x, x, "-") > x[1] 1 10 5 8 9 6 3 2 4 7> diffMat[,1] [,2] [,3] [,4] [,5] [,6] [,7] [,8] [,9] [,10] [1,] 0 -9 -4 -7 -8 -5 -2 -1 -3 -6 [2,] 9 0 5 2 1 4 7 8 6 3 [3,] 4 -5 0 -3 -4 -1 2 3 1 -2 [4,] 7 -2 3 0 -1 2 5 6 4 1 [5,] 8 -1 4 1 0 3 6 7 5 2 [6,] 5 -4 1 -2 -3 0 3 4 2 -1 [7,] 2 -7 -2 -5 -6 -3 0 1 -1 -4 [8,] 1 -8 -3 -6 -7 -4 -1 0 -2 -5 [9,] 3 -6 -1 -4 -5 -2 1 2 0 -3 [10,] 6 -3 2 -1 -2 1 4 5 3 0> diffTab <- table(diffMat[lower.tri(diffMat, diag=FALSE)]) > diffTab-8 -7 -6 -5 -4 -3 -2 -1 1 2 3 4 5 6 7 8 9 1 2 3 3 3 4 5 4 5 3 3 3 2 1 1 1 1> diffTab <- table(abs(diffMat[lower.tri(diffMat, diag=FALSE)])) > diffTab1 2 3 4 5 6 7 8 9 9 8 7 6 5 4 3 2 1 Andy> From: StephaneDemurget > > Hi, > > I'm trying to figure out how to properly construct a graph of > frequencies of a difference between 2 values, that is | i | - | j |. > I'd like to know the best way to store the actual data > because of course > doing my_vector[i -j] will not work because the index could > be negative. > > I know there's no hash table so what's the best solution, > simplicity-wise ? Use a list of pair of values {index, i - j} > ? Or can I > somehow use negative index, perhaps using 0array ? Any help would be > appreciated :) > > ATM, I use as.character (i-j) to index my data, but I lose all the > processing power of R there after. > > Sorry If it's written somewhere, but I read a lot of docs about it, > searched through the ML archives and didn't manage to find an answer. > > Please also answer me back at my email address as I am not > subscribed to > the list. > > Best regards, > > --Stephane > > ______________________________________________ > R-help at stat.math.ethz.ch mailing list > https://www.stat.math.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide! > http://www.R-project.org/posting-guide.html > >
StephaneDemurget <demurget at aleks.com> writes:> Hi, > > I'm trying to figure out how to properly construct a graph of > frequencies of a difference between 2 values, that is | i | - | j |. > I'd like to know the best way to store the actual data because of > course doing my_vector[i -j] will not work because the index could be > negative. > > I know there's no hash table so what's the best solution, > simplicity-wise ? Use a list of pair of values {index, i - j} ? Or can > I somehow use negative index, perhaps using 0array ? Any help would be > appreciated :)(i and j are integer vectors, right?) How about this: f <- i - j f <- factor(f,levels=min(f):max(f)) table(f) -- O__ ---- Peter Dalgaard Blegdamsvej 3 c/ /'_ --- Dept. of Biostatistics 2200 Cph. N (*) \(*) -- University of Copenhagen Denmark Ph: (+45) 35327918 ~~~~~~~~~~ - (p.dalgaard at biostat.ku.dk) FAX: (+45) 35327907
Apparently Analagous Threads
- lists within a list / data-structure problem
- Efficient way to Calculate the squared distances for a set of vectors to a fixed vector
- indexing a vector starting from 0
- pls help: lattice graph with both negative and positive value, x and y cross at 0 and negative value bars are plotted just oppositive direction in contrast to positive
- Negative numbers in range searches