similar to: function in argument

Displaying 20 results from an estimated 50000 matches similar to: "function in argument"

2012 Oct 08
1
Any better way of optimizing time for calculating distances in the mentioned scenario??
Dear All, I'm dealing with a case, where 'manhattan' distance of each of 100 vectors is calculated from 10000 other vectors. For achieving this, following 4 scenarios are tested: 1) scenario 1: > x<-read.table("query.vec") > v<-read.table("query.vec2") > d<-matrix(nrow=nrow(v),ncol=nrow(x)) > for (i in 1:nrow(v)){ + d[i,]<-
2009 Oct 22
1
loop vs. apply(): strange behavior with data frame?
Hi everybody, I noticed a strange behavior when using loops versus apply() on a data frame. The example below "explicitly" computes a distance matrix given a dataset. When the dataset is a matrix, everything works fine. But when the dataset is a data.frame, the dist.for function written using nested loops will take a lot longer than the dist.apply ######## USING FOR ####### dist.for
2006 Aug 16
1
help about agnes
Hello. I have the following distance matrix between 8 points: [1,] 0.000000 3.162278 7.280110 8.544004 7.071068 9.899495 6.403124 8.062258 [2,] 3.162278 0.000000 5.000000 6.403124 4.472136 8.944272 6.082763 8.062258 [3,] 7.280110 5.000000 0.000000 1.414214 1.000000 5.000000 4.242641 5.830952 [4,] 8.544004 6.403124 1.414214 0.000000 2.236068 4.123106 4.472136 5.656854 [5,] 7.071068 4.472136
2011 May 17
1
simprof test using jaccard distance
Dear All, I would like to use the simprof function (clustsig package) but the available distances do not include Jaccard distance, which is the most appropriate for pres/abs community data. Here is the core of the function: > simprof function (data, num.expected = 1000, num.simulated = 999, method.cluster = "average", method.distance = "euclidean", method.transform =
2003 Nov 27
2
Getting rid of loops?
I wrote a function to calculate cosine distances between rows of a matrix. It uses two loops and is slow. Any suggestions to speed this up? Thanks in advance. theta.dist <- function(x){ res <- matrix(NA, nrow(x), nrow(x)) for (i in 1:nrow(x)){ for(j in 1:nrow(x)){ if (i > j) res[i, j] <- res[j, i] else { v1 <- x[i,] v2 <- x[j,]
2023 Feb 27
1
Undocumented change of dirname("C:/") on R-devel on Windows
Hi Tomas, There has been an R CMD check error with xfun and r-devel on Windows for a while: https://www.r-project.org/nosvn/R.check/r-devel-windows-x86_64/xfun-00check.html Basically it means that the following would return TRUE before: normalizePath('a/b', mustWork = FALSE) == normalizePath('./a/b', mustWork = FALSE) but it became FALSE at some point in r-devel. I think
2007 Mar 03
3
How to convert List object to function arguments?
Dear R gurus, I have a function "goftests" that receives the following arguments: * a vector "x" of data values; * a distribution name "dist"; * the dots list ("...") containing a list a parameters to pass to CDF function; and calls several goodness-of-fit tests on the given data values against the given distribution. That is: ##### BEGIN CODE SNIP #####
2010 Jul 20
1
p-values pvclust maximum distance measure
Hi, I am new to clustering and was wondering why pvclust using "maximum" as distance measure nearly always results in p-values above 95%. I wrote an example programme which demonstrates this effect. I uploaded a PDF showing the results Here is the code which produces the PDF file: ------------------------------------------------------------------------------------- s <-
2007 Feb 07
2
blank upper or lower triangle of cor-matrix
Dear altogether, I want to blank the lower (or upper) part of a correlation matrix as it is done by dist() example: ( d <- cor(matrix(runif(12),nrow=4)) ) If I do the following d[lower.tri(d)] <- "" of course everything is changed to character - that's not what should be. Additionally, it does not work to assign "0" or anything else. The same is true for
2011 Nov 29
2
Parameters setting in functions optimization
Good afternoon everybody, I'm quite new in functions optimization on R and, whereas I've read lot's of function descriptions, I'm not sure of the correct settings for function like "optimx" and "nlminb". I'd like to minimize my parameters and the loglikelihood result of the function. My parameters are a mean distance of dispersion and a proportion of
2009 Nov 20
3
help me avoid nested for() loops!
Hi R folks, I have a massive array (object name "points") in the following form [,1] [,2] [1,] 1369 22 [2,] 1370 22 [3,] 1368 23 [4,] 1369 23 [5,] 1370 23 [6,] 1371 23 (10080 rows truncated) These represent pixel coordinates of interest in a jpeg image. I need to find the distance from each point to all other points of interest. The only way I can see to do this
2009 Jan 14
2
Vectorization of three embedded loops
Dear R-programmer, I wrote an adapted implementation of the Kennard-Stone algorithm for sample selection of multivariate data (R 2.7.1 under MacBook Pro, Processor 2.2 GHz Intel Core 2 Duo, Memory 2 GB 667 MHZ DDR2 SDRAM). I used for the heart of the script three embedded loops. This makes it especially for huge datasets very slow. For a datamatrix of 1853*1853 and the selection of 556
2013 Jan 10
1
merging command
HI Eliza, You could do this: set.seed(15) mat1<-matrix(sample(1:800,124*12,replace=TRUE),nrow=12) # smaller dataset #Your codes ?list1<-list() ?for(i in 1:ncol(mat1)){ ? list1[[i]]<-t(apply(mat1,1,function(x) x[i]-x)) ? list1} ?x<-list1?? x<-matrix(unlist(x),nrow=12) x<-abs(x) ?y<-colSums(x, na.rm=FALSE) z<-matrix(y,ncol=10) ?z<-as.dist(z) ?z ?# ?? 1?? 2?? 3?? 4?? 5??
2013 May 02
2
Calculating distance matrix for large dataset
Dear R users I wondered if any of you ever tried to calculate distance matrix with very large data set, and if anyone out there can confirm this error message I got actually mean that my data is too large for this task. negative length vectors are not allowed My data size and code used dim(mydata_nor)[1] 365000 144> d <- dist(mydata_nor, method = "euclidean") Here my
2004 Apr 04
1
How to improve this code?
Hi all, I've got some functioning code that I've literally taken hours to write. My 'R' coding is getting better...it used to take days :) I know I've done a poor job of optimizing the code. In addition, I'm missing an important step and don't know where to put it. So, three questions: 1) I'd like the resulting output to be sorted on distance (ascending) and
2007 Oct 10
3
as.dist with diagonal unequal zero
Hello and sorry that I still haven?t found a solution for my problem. I need to extract the lower and upper triangle from a square matrix including the diagonal. This diagonal is not zero in that special case. I tried with as.dist w<-as.dist(w, diag = TRUE) > w 1 2 3 4 5 1 0 2 2 0 3 3 8 0 4 4 9 14 0 5 5 10 15 20 0 but found no way to keep the diagonal that is in the
2008 Sep 16
1
Spatial join – optimizing code
Hi, Few days ago I have asked about spatial join on the minimum distance between 2 sets of points with coordinates and attributes in 2 different data frames. Simon Knapp sent code to do it when calculating distance on a sphere using lat, long coordinates and I've change his code to use Euclidian distances since my data had UTM coordinates. Typically one data frame has around 30 000 points
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 =
1997 Nov 17
1
R-beta: autoloading a required library
I wanted to use the dist() function from the mva library in my own library, so I put require(mva) in my files. When my library loads, a message about "Autoloading ... mva" appears. But when I call dist() now within my functions the message Error in .C("dist", as.double(x), nrow(x), ncol(x), double(len), as.integer(method)) : C/Fortran function not in load table appears.
2017 Dec 31
1
Perform mantel test on subset of distance matrix
I'm trying to perform a mantel test that ignores specific pairs in my distance matrices. The reasoning is that some geographic distances below a certain threshold suffer from spatial autocorrelation, or perhaps ecological relationships become less relevant that stochastic processes above a certain threshold. The problem is that I can't find a way to do it. If I replace values in either or