[R] how to improve the precison of this calculation?

2011-02-12 Thread zhaoxing731
Hello T I want to order some calculation "result", there will be lots of "result" that need to calculate and order PS: the "result" is just a intermediate varible and ordering them is the very aim # problem: # For fixed NT and CT, and some pair (c,n). order the pair by co

Re: [R] How can we make a vector call a function element-wise efficiently?

2011-02-11 Thread zhaoxing731
Dear Eik What a great idea!!! Thank you so much for your colossal improvment Yes, you have a unique eye on the numerical problem, I am worrying about this problem right now, hope you could give me new idea again Hi, you compute the same results for logx many times. So it is easier and time savin

[R] How can we make a vector call a function element-wise efficiently?

2011-02-10 Thread zhaoxing731
Hello I have a time-comsuming program which need to simplify, I have tested the annotated program as follow: > #define function which will be call > calsta <- function(c, n=10) + { + i <- seq(from=0, length=c) + logx <- lchoose(NT-n, CT-i) + lchoose(n, i) + logmax <- max(lo

[R] how to return multipy matrix in a function

2011-02-07 Thread zhaoxing731
Hello I have a 100*100 matrix which is from a intensive computation, e.g. mat. Is there any method/function that return the max of every row and the subscript of maximum value simultaneously #define the function > returnfunction<-function(x){ + value<-apply(x,1,max) + index<-apply(x,1,which.ma

[R] how to coerce part of each column of a matrix to a vector and merge them

2011-01-10 Thread zhaoxing731
Hello Suppose I have a matrix mat=(1:16,2) [,1] [,2] [,3] [,4] [1,]159 13 [2,]26 10 14 [3,]37 11 15 [4,]48 12 16 there is a vector end=c(2,3,1,3) #coerce the 1st 2 numbers of the 1st column to a vector [1] 1 2 #coerce the 1st 3 numbers of

[R] how to use "apply" function partial to each vector of a matrix

2011-01-10 Thread zhaoxing731
Hello Suppose I have a matrix mat=(1:16,2) [,1] [,2] [,3] [,4] [1,]159 13 [2,]26 10 14 [3,]37 11 15 [4,]48 12 16 I just want to use the "apply" function to the matrix partially there is a vector end=c(2,3,1,3) #sum the 1st 2 numbers of

[R] how to create and manage a matrix with vector of different length

2011-01-10 Thread zhaoxing731
Hello I have a data consisting of 245 counties, including the population, number of illness and the geographical information of each county. Fixing each county, I want to sort the other county by distance, which can make a 245*245 matrix with each cell is the corresponding index of the c

[R] how to calculate this natural logarithm

2011-01-07 Thread zhaoxing731
Hello I want to calculate natural logarithm of sum of combinations as follow: (R code) { com_sum=choose(200,482)*choose(100,118)+choose(200,483)*choose(100,117)+...+choose(200,i)*choose(100,600-i)+...+choose(200,600)*choose(100,0)

[R] matrices call a function element-wise

2011-01-03 Thread zhaoxing731
Hello I have 4 1000*1000 matrix A,B,C,D. I want to use the corresponding element of the 4 matrices. Using the "for loop" as follow: E<-o for (i in 1:1000) {for (j in 1:1000) { E<-fisher.test(matrix(c(A[i][j],B[i][j],C[i][j],D[i][j]),2))#call fisher.test for every element } }