similar to: Merge sort

Displaying 20 results from an estimated 60000 matches similar to: "Merge sort"

2016 Apr 20
1
Merge sort
I indeed used is.na() to check length, as I was not sure weather lenght() was a simple query or would go through the whole vector to count the elements. So to sum up, function calls are expensive, therefore recursion should be avoided, and growing the size of a vector (which is probably reassigning and copying?) is also expensive. Thank you for your help! On 04/19/2016 11:51 PM, Duncan
2016 Apr 19
0
Merge sort
On 19/04/2016 3:39 PM, Gaston wrote: > Hello everyone, > > I am learning R since recently, and as a small exercise I wanted to > write a recursive mergesort. I was extremely surprised to discover that > my sorting, although operational, is deeply inefficient in time. Here is > my code : > >> merge <- function(x,y){ >> if (is.na(x[1])) return(y) >>
2008 Jul 03
3
apply with a division
Hi, I'd like to normalize a dataset by dividing each row by the first row. Very simple, right? I tried this: > expt.fluor X1 X2 X3 1 124 120 134 2 165 163 174 3 52 51 43 4 179 171 166 5 239 238 235 >first.row <- expt.fluor[1,] > normed <- apply(expt.fluor, 1, function(r) {r / first.row}) >normed [[1]] X1 X2 X3 1 1 1 1 [[2]] X1 X2 X3 1
2004 Aug 25
4
bugfix: indeterministic file choice from multiple sources
Hello, some time ago I reported a bug, where we saw indeterministic behaviour of rsync (all versions since 2.5), when having the same file appearing in multiple sources. Sometimes the file in the first source was copied, other times the file was copied from one of the other sources. The attached mstest.tgz contains a test to reproduce the behaviour under darwin and solaris. The bug did
2011 Jun 24
4
How to capture console output in a numeric format
Hi, I would like to know how to capture the console output from running an algorithm for further analysis. I can capture this using capture.output() but that yields a character vector. I would like to extract the actual numeric values. Here is an example of what I am trying to do. fr <- function(x) { ## Rosenbrock Banana function on.exit(print(f)) x1 <- x[1] x2 <- x[2]
2006 Apr 23
2
distribution of the product of two correlated normal
Hi, Does anyone know what the distribution for the product of two correlated normal? Say I have X~N(a, \sigma1^2) and Y~N(b, \sigma2^2), and the \rou(X,Y) is not equal to 0, I want to know the pdf or cdf of XY. Thanks a lot in advance. yu [[alternative HTML version deleted]]
2006 Jul 03
6
macro facility in R
R 2.2 on windows XP I have a dataset with multiple columns. Some of the columns represent independent variables, some represent dependent variables. I would like to run the same analyses on a fixed set of independent variables, changing only the dependent variable, e.g. y1-y2=x1+x2+x3 y3-y4=x1+x2+x3 y5-y6=x1+x2+x3, etc. I know I can write a function to perform the analyses, however in order to
2010 Jul 20
3
simplify if statement in R ?
I found a form of the if statement that works but it is very long. I'm attempting to check the value of of two different variables to see if they evaluate to either of two different values, which will result in a division by 0 in the final equation. This first if statement works for me _______ if ((x0.trial01 == 0.0)||(x0.trial01 == npt01)||(x1.trial01 == 0.0)||(x1.trial01 == npt01))
2006 Sep 29
2
X-axis labels in histograms drawn by the "truehist" function
Hi, I have a simple problem that I would appreciate getting some tips. I am using the "truehist" function within an "apply" call to plot multiple histograms. I can't figure out how to get truehist to use the column names of the matrix as the labels for the x-axis of the histograms. Here is a simple example: X <- matrix(runif(4000),ncol=4) colnames(X)
2010 Nov 15
3
merge two dataset and replace missing by 0
Hi r users, I have two data sets (X1, X2). For example, time1<-c( 0, 8, 15, 22, 43, 64, 85, 106, 127, 148, 169, 190 ,211 ) outpue1<-c(171 ,164 ,150 ,141 ,109 , 73 , 47 ,26 ,15 ,12 ,6 ,2 ,1 ) X1<-cbind(time1,outpue1) time2<-c( 0 ,8 ,15 , 22 ,43 , 64 ,85 ,106 ,148) output2<-c( 5 ,5 ,4 ,5 ,5 ,4 ,1 ,2 , 1 ) X2<-cbind(time2,output2) I want to
2009 Aug 02
1
Inaccurate complex arithmetic of R (Matlab is accurate)
Dear All, Hans Borchers and I have been trying to compute "exact" derivatives in R using the idea of complex-step derivatives that Hans has proposed. This is a really, really cool idea. It gives "exact" derivatives with only a minimal effort (same as that involved in computing first-order forward-difference derivative). Unfortunately, we cannot implement this in R as the
2013 Apr 26
4
Help with merge function
Dear all, I'm trying to merge 2 dataframes, but I'm not being entirely successful and I can't understand why. Dataframe x1 State_prov Shape_name bob2009 bob 2010 bob2011 Nova Scotia Annapolis 0 0 1 Nova Scotia Antigonish 0 0 0 Nova Scotia Gly NA NA
2009 Nov 05
2
Merge records in the same dataframe
Hi: Suppose that I have a data frame as below x1 x2 x3 ... x10 wk1 wk2 ... Wk208 (these are the column names) For each record, x1, x2, x3 ... x10 are attributes. and wk1, wk2, ..., wk208 are the sales recoreded for this attribute combination. Suppose that now, that I want to do the following 1. Merge the data frame so that I have a new data frame grouped by values of x2 and x3 (for example).
2006 Mar 12
2
Numerical Derivatives in R
Hi, Suppose I have an arbitrary function: arbfun<-function(x) {...} Is there a robust implementation of a numerical derivative routine in R which I can use to take it's derivative ? Something a bit more than simple division by delta of the difference of evaluating the function at x and x+delta... Perhaps there is a way to do this using D or deriv but I could not figure it out.
2007 Aug 02
1
Multivariable correlation
Given a square matrix of variables X, is there any way to compute a multivariable correlation among all the variables in the array? It is possible to calculate the correlation of all pairs of variables in the array, but I want to know the correlation of all the variables taken together, i.e. for the matrix X=x1 x2 x3 x4 x5 x6 x7 x8 x9 I don't want the pair-wise correlations
2010 Aug 10
1
Multiple imputation, especially in rms/Hmisc packages
Hello, I have a general question about combining imputations as well as a question specific to the rms and Hmisc packages. The situation is multiple regression on a data set where multiple imputation has been used to give M imputed data sets. I know how to get the combined estimate of the covariance matrix of the estimated coefficients (average the M covariance matrices from the individual
2011 Apr 21
1
passing a vector of variable names to the ... pairlist function argument
Hi, I have a character vector that contains the names of several objects that I would like to pass to a function (specifically, the ridge function in the survival package, but cbind is a similar example). I've been struggling with how to do this so that the object values get interpreted by the function, rather than the object names. For example, x1 <- 1:4 x2 <- 2:5 x3 <-
2008 Sep 22
4
sort a data matrix by all the values and keep the names
Dear all, If I have a data frame x<-data.frame(x1=c(1,7),x2=c(4,6),x3=c(8,2)): x1 x2 x3 1 4 8 7 6 2 I want to sort the whole data and get this: x1 1 x3 2 x2 4 x2 6 x1 7 x3 8 If I do sort(X), R reports: Error in order(list(x1 = c(1, 7), x2 = c(4, 6), x3 = c(8, 2)), decreasing = FALSE) : unimplemented type 'list' in 'orderVector1' The only way
2009 Apr 22
3
Help using spg optimization in BB package
i'm trying to use the BB package to minimize the sum of the squared deviations for 2 vectors. The only thing am having trouble with is defining the project constraint. I got the upper and lower bounds to work but i am not sure how to create a constraint that the sum of x must be 1. Any help would be greatly appreciated. -- View this message in context:
2010 Jun 29
1
Model validation and penalization with rms package
I?ve been using Frank Harrell?s rms package to do bootstrap model validation. Is it the case that the optimum penalization may still give a model which is substantially overfitted? I calculated corrected R^2, optimism in R^2, and corrected slope for various penalties for a simple example: x1 <- rnorm(45) x2 <- rnorm(45) x3 <- rnorm(45) y <- x1 + 2*x2 + rnorm(45,0,3) ols0 <- ols(y