similar to: how to use by function

Displaying 20 results from an estimated 10000 matches similar to: "how to use by function"

2012 Jul 27
4
why order doesn't work?
hi all, I want to get a cumsum according to the order of some variable. However, it doesnt' work. For example, ********************** test<-data.frame(cbind(x=c(3,5,2,6,7),y=c(8,1,4,9,0))) test[order(test$x),]$sumy<-cumsum(test[order(test$x),]$y) ********************** R complians Warning message: In `[<-.data.frame`(`*tmp*`, order(test$x), , value = list(x = c(2, : provided 3
2011 Dec 21
2
unique combinations
Hi there, I have a vector and would like to create a data frame, which contains all unique combination of two elements, regardless of order. myVec <- c(1,2,3) what expand.grid does: 1,1 1,2 1,3 2,1 2,2 2,3 3,1 3,2 3,3 what I would like to have 1,1 1,2 1,3 2,2 2,3 3,3 Can anybody help?
2004 Dec 21
3
R code for var-cov matrix given variances and correlations
Dear list members, Where can I find code for computing the p*p variance-covariance matrix given a vector of p variances (ordered varA, varB, ..., varp) and a vector of all possible correlations (ordered corAB, corAC, ..., corp-1,p)? I know that the covariance between 2 variables is equal to the product of their correlation and their standard deviations: corAB * varA^.5 * varB^.5 and so:
2005 Mar 28
2
Generating list of vector coordinates
Hi. Can anyone suggest a simple way to obtain in R a list of vector coordinates of the following form? The code below is Mathematica. In[5]:= Flatten[Table[{i,j,k},{i,3},{j,4},{k,5}], 2] Out[5]= {{1,1,1},{1,1,2},{1,1,3},{1,1,4},{1,1,5},{1,2,1},{1,2,2},{1,2,3},{1 ,2,4},{1,2, 5},{1,3,1},{1,3,2},{1,3,3},{1,3,4},{1,3,5},{1,4,1},{1,4,2},{1,4,3}, {1,4,
2008 May 27
4
help with simple function
I have a matrix of frequency counts from 0-160. x<-as.matrix(c(0,1,0,0,1,0,0,0,1,0,0,0,0,1)) I would like to apply a function creating a new column (x[,2])containing values equal to: a) log(x[m,1]) if x[m,1] > 0; and b) for all x[m,1]= 0, log(next x[m,1] > 0 / count of preceding zero values +1) for example, x[1,2] should equal log(x[2,1]/2) = log(1/2) = -0.6931472 whereas x[3,2] should
2009 Sep 10
2
index of min elements in matrix
Hi, All, How can I get the indices of the minimum elements in a matrix without using a loop? For example, if the matrix is 4 5 2 2 8 9 5 2 3 Then I want to output (1,3), (2,1), (3,2). Thanks, Annie [[alternative HTML version deleted]]
2011 Jun 20
3
Unreasonable syntax error
http://r.789695.n4.nabble.com/file/n3612530/PSC.r PSC.r Hi all, I just wrote a program in R by editing it in Microsoft Word and then pasting into the text editor of R. The above is the file. And below is what the console complains.... Why doesn't it recognise 'r'?? I have to mention that at least when I typed this first several lines into the console, the first error didn't
2012 Jul 03
1
Wrapper function for multivariate arrays for ode
I am trying to to write a wrapper function for the ode solver (under the package desolve) to enable it to take multivariate arrays. I know how to do it for 1 dimension arrays but my code breaks down when I try to do it for 2 dimensional arrays. Here is my code diffwrap<-function(t,y,mu)vdpol(t=t,A[1:3,1:4]<-y[1:12],B[1:12]<-y[13:24],mu=mu) vdpol<-function(t,A,B,mu) { list(c(mu,
2012 Aug 17
5
specific matrix element tranformation
Hi guys, I am trying to write a function that allows me to perform specific transformations to each element of a 2 by 2 matrix to generate a 3 by 3 matrix. Input into function-2 by 2 matrix Output from function -3 by 3 matrix For example: # a is my original 2 by 2 matrix #b is my new 3 by 3 matrix set.seed(2) a=matrix(rnorm(4),ncol=2) #let's say these are the transformations i wish to
2004 May 14
5
Tagging identical rows of a matrix
I would like to generate a vector having the same length as the number of rows in a matrix. The vector should contain an integer indicating the "group" of the row, where identical matrix rows are in a group, and a unique row has a unique integer. Thus, for a <- c(1,2) b <- c(1,3) c <- c(1,2) d <- c(1,2) e <- c(1,3) f <- c(2,1) mat <- rbind(a,b,c,d,e,f) I would
2006 Mar 25
2
pairwise combinatons of variables
Dear WizaRds, although this might be a trivial question to the community, I was unable to find anything solving my problem in the help files on CRAN. Please help. Suppose I have 4 variables and want to use all possible combinations: 1,2 1,3 1,4 2,3 2,4 3,4 for a further kmeans partitioning. I tried permutations() of package e1071, but this is not what I need. Thank you for your help and
2011 Jul 19
2
Taking all "complete" diagonals of a matrix
Hi R-Help! I am trying to find a nicer way of extracting all the "complete" diagonals of a matrix. I am working with very large matrices that have many more rows than columns. I want to be able to extract each of the diagonals that are as long as the number of columns in the matrix. I have written a rather ugly function that presently does the job. It illustrates what I am trying to
2005 Jun 24
1
r programming help II
Dear List, Suppose we have a variable K.JUN defined as (with 1=wet, 0=dry): K.JUN1984 = c(1, 0, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1) K.JUN1985 = c(0, 1, 0, 1, 0, 0, 1, 0, 0, 1, 0, 0, 1, 1, 1, 1, 1, 0, 0, 1, 1, 0, 0, 1, 1, 1, 1, 1, 1, 1) K.JUN1986 = c(0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 1, 1)
2007 Apr 11
1
Programming Problem (for loop, random # control, 3 dimentional graph)
Dear List, This is just a programming problem which i cannot seem to figure out. I am trying to get a set of power from a test (say, kolmogorov smirnov) out of a distribution (say, G-K distribution) as follows. I am trying to reduce to pain of writing the whole set of data points (p# below) using "for" loop. However, I seem to have some problem in it as the output "M" does not
2012 Oct 31
1
party tree coordinates
I'm hoping that folks out there with expertise in working with the party package can help me out here. My team is trying to convert party tree output into a text file format that can be read by our image processing software. We are running into difficulties because the way the two different programs identify their nodes is different. R numbers it's nodes 1, 2, 3, 4, 5, 6 etc. down the
2011 Dec 08
2
Relationship between covariance and inverse covariance matrices
Hi, I've been trying to figure out a special set of covariance matrices that causes some symmetric zero elements in the inverse covariance matrix but am having trouble figuring out if that is possible. Say, for example, matrix a is a 4x4 covariance matrix with equal variance and zero covariance elements, i.e. [,1] [,2] [,3] [,4] [1,] 4 0 0 0 [2,] 0 4
2010 Jun 15
2
Integration problem: error in invoking an outside function
Dear all, Currently I am trying to integrate a function which depends on four variables, two of which are given, one is given in the integrate function, so there is one variable to integrate on. The code is as follows: Pmatrix = function(th) { P = matrix(nrow=6, ncol=6, data=0) P[1,1] = P[2,1]=P[3,2]=P[4,3]=P[5,4]=P[6,5]= exp(-th) P[,6] = 1-exp(-th) return(P)} lim.verd =
2008 Feb 04
3
counts of each column that are not NA, and/or greater than column means
Hi, Given a test matrix, test <- matrix(c(1,2,3,NA,2,3,NA,NA,2), 3,3) A) How to compute the counts of each column (excluding the NA) i.e., 3, 2, 1 B) How to compute the counts of each column (excluding the NA) that are greater than the column means ? i.e., 1, 1, 0 I could write a for loop, but hope to use better alternative. [[alternative HTML version deleted]]
2010 Jun 19
2
Call by reference or suggest workaround
I have written code to compute multi-indices in R [1] and due to the recursive nature of the computation I need to pass around the *same* matrix object (where each row corresponds to one multi-index). As pass by reference wasn't the default behavior I declared a global matrix (mat) and used the <<- operator to write to the global matrix. So the usage would be to call genMultiIndices(3,2)
2003 Apr 02
7
Index of item in matrix
Hello All, Is there a fast way to find the index(row and column) of a point in a matrix? Thanks, John. -- -------------------------------------------------------------------------- Dr. John Janmaat Department of Economics, Acadia University, Wolfville, NS, B4P 2R6 E-mail: jjanmaat at acadiau.ca Web: http://ace.acadiau.ca/~jjanmaat Tel: 902-585-1461 Fax: 902-585-1070