similar to: R version 3.3.2, Windows 10: Applying a function to each possible pair of rows from two different data-frames

Displaying 20 results from an estimated 20000 matches similar to: "R version 3.3.2, Windows 10: Applying a function to each possible pair of rows from two different data-frames"

2017 Jun 23
1
R version 3.3.2, Windows 10: Applying a function to each possible pair of rows from two different data-frames
Hello, Another way would be n <- nrow(expand.grid(1:nrow(D1), 1:nrow(D2))) D5 <- data.frame(distance=integer(n),difference=integer(n)) D5[] <- do.call(rbind, lapply(seq_len(nrow(D1)), function(i) t(sapply(seq_len(nrow(D2)), function(j){ c(distance=sqrt(sum((D1[i,1:2]-D2[j,1:2])^2)),difference=(D1[i,3]-D2[j,3])^2) } )))) identical(D3, D5) In my first answer I forgot to say that
2017 Jun 23
0
R version 3.3.2, Windows 10: Applying a function to each possible pair of rows from two different data-frames
Hello, The obvious way would be to preallocate the resulting data.frame, to expand an empty one on each iteration being a time expensive operation. n <- nrow(expand.grid(1:nrow(D1), 1:nrow(D2))) D4 <- data.frame(distance=integer(n),difference=integer(n)) k <- 0 for (i in 1:nrow(D1)){ for (j in 1:nrow(D2)) { k <- k + 1 D4[k, ] <-
2017 Jun 23
0
R version 3.3.2, Windows 10: Applying a function to each possible pair of rows from two different data-frames
You appear to be trying to write C code in R. Don't do this. If you can trade off space for efficiency, the calculation can be easily vectorized (assuming I correctly understand what you want to do, of course). set.seed(135) ## for reproducibility D1<-data.frame(x=1:5,y=6:10,z=rnorm(5)) D2<-data.frame(x=19:30,y=41:52,z=rnorm(12)) D.all <-merge(D1,D2, by.x=NULL,by.y=NULL) ##
2017 Sep 24
1
R version 3.3.2, Windows 10: gstat package: Error in fitting a variogram model using 'fit.variogram' function
Dear Members, I am trying to fit a variogram model using fit.variogram function from the gstat package. The figure showing my experimental variogram can be seen here: https://i.stack.imgur.com/UZXw4.png My code line for this operation is: > c2.vgm.fit<-fit.variogram(c2.vgm.exp,vgm(nugget=0, psill=400,model="Exp",range =40000),fit.method = 7) The system throws following error
2011 Jun 27
3
New to R, trying to use agnes, but can't load my ditance matrix
Hi, I'm mighty new to R. I'm using it on Windows. I'm trying to cluster using a distance matrix I created from the data on my own and called it D10.dist. I loaded the cluster package. Then tried the following command... > agnes("E:D10.dist", diss = TRUE, metric = "euclidean", stand = FALSE, > method = "average", par.method, keep.diss = n < 1000,
2009 May 25
2
apply fn to many dataframes
Hi, Say I have dataframes d1, d2, ... , dn, and I want to apply a function to all of them. For example, say I want to change the name of the second variable in each dataframe to "x2". The following doesn't work: a = list(d1,d2,d3,d4) lapply(a,function(x) names(x)[2] = "x2") What would work? Thanks for any help.
2010 Sep 14
3
extracting objects from lists
If you have 5 data frames and you append them to a list, how do you access the first data frame, not the first value of the first data frame while iterating in a for loop? list = c(d1,d2,d3,d4,d5) where d1..d5 are dataframes. for(i in 1: length(list)){ print(list[1]) } -- View this message in context: http://r.789695.n4.nabble.com/extracting-objects-from-lists-tp2539412p2539412.html Sent from
2009 Feb 22
2
how to recover a list structure
I am experiencing some problems at working with lists at high level. In the following "coef" contains the original DWT coefficients organized in a list. Thorugh applying the following two commands: coef.abs <- lapply(unlist(coef,recursive=FALSE,use.names =TRUE),abs) coef.abs.sorted <- sort(unlist(coef.abs),decreasing=TRUE) I get vector "coef.abs.sorted" containing
2008 Jun 03
3
How to solve a non-linear system of equations using R
Dear R-list members, I've had a hard time trying to solve a non-linear system (nls) of equations which structure for the equation i, i=1,...,4, is as follows: f_i(d_1,d_2,d_3,d_4)-k_i(l,m,s) = 0 (1) In the expression above, both f_i and k_i are known functions and l, m and s are known constants. I would like to estimate the vector d=(d_1,d_2,d_3,d_4) which is solution
2007 Aug 29
1
Plot command drops part of the plot for large plots in multiple figure environment
I have run into some surprising behaviour when plotting data in a 3x2 grid: random parts of the data on my graphs aren't rendered. Not on screen, not on file, and not when I send the plot to a printer. I don't get any error messages either. When I do the individual plots (not in a grid) they are each rendered correctly. My questions are: - Has anyone encountered something like this,
2011 Jan 15
2
Rounding variables in a data frame
Hi All I am trying to use the round function on some columns of a dataframe while leaving others unchanged. I wish to specify those columns to leave unchanged. My attempt is below - here, I would like the column d3 to be left but columns d1, d2 and d4 to be rounded to 0 decimal places. I would welcome any suggestions for a nicer way of doing this. d1= rnorm(10,10) d2= rnorm(10,6) d3=
2011 Apr 21
1
Help with matching rows
Dear Sir, Please excuse my akwardness as I a new to R and computers, but would kindly appreciate help. { a <- sample (1:10,100,replace=T ) b <-sample(10:20,100,replace=T) c <- sample(20:30,100,replace=T) d <- sample(30:40,100,replace=T) e <- sample(40:50,100,replace=T) } d1 <- a d2 <- b d3 <-c d4 <- d d5 <- e data.frame(d1,d2,d3,d4,d5) dd <-
2012 Nov 22
1
Data Extraction - benchmark()
Hi Berend, I see you are one of the contributors to the rbecnhmark package. I am sorry that I am bothering you again. I have tried to run your code (slightly tweaked) involving the benchmark function, and I am getting the following error message. What am I doing wrong? Error in benchmark(d1 <- s1(df), d2 <- s2(df), d3 <- s3(df), d4 <- s4(df), : could not find function
2010 Jun 14
2
Which is the easiest (most elegant) way to force "aov" to treat numerical variables as categorical ?
Hi R help, Hi R help, Which is the easiest (most elegant) way to force "aov" to treat numerical variables as categorical ? Sincerely, Andrea Bernasconi DG PROBLEM EXAMPLE I consider the latin squares example described at page 157 of the book: Statistics for Experimenters: Design, Innovation, and Discovery by George E. P. Box, J. Stuart Hunter, William G. Hunter. This example use
2009 Feb 09
2
How to plot multiple graphs each with multiple y variables
I am new to R and have a problem that I haven't been able to find the answer to in the guides or online. I have multiple datasets, D1, D2, D3, D4, D5, D6, D7 and D8, and I would like to produce two plots side by side using mfrow.  The first plot should contain data from D1-D4, the second should contain D5-D8. I can plot these separately using the code, par(mfrow=c(1,1))
2009 Mar 20
4
how to make aggregation in R ?
Hi, I am trying to aggregate the sum of my test data.frame as follow: testDF <- data.frame(v1 = c("a", "a", "a", "a", "a", "b", "b", "b", "b", "b", "c", "c", "c", "c", "c", "d", "d", "d", "d",
2011 May 17
2
Minimum value by ID
Hello, I have a longitudinal dataset where each individual has a different number of entries. Thus, it is of the following structure: x <- runif(12) id.var <- factor(c(rep("D1",4),rep("D2",2),rep("D3",3),rep("D4",3))) dat <- as.data.frame(x) dat$id.var <- id.var dat > dat x id.var 1 0.9611269 D1 2 0.6738606 D1 3
2018 Jul 10
9
[PATCH 0/7] PowerPC64 performance improvements
The following series adds initial vector support for PowerPC64. On POWER9, flac --best is about 3.3x faster. Amitay Isaacs (2): Add m4 macro to check for C __attribute__ features Check if compiler supports target attribute on ppc64 Anton Blanchard (5): configure.ac: Remove SPE detection code configure.ac: Add VSX enable/disable configure.ac: Fix FLAC__CPU_PPC on little endian, and add
2011 Dec 03
1
partial mantel tests in ecodist with intential NA values.
I would like to perform partial mantel tests on only within group values, with "between group" values assigned to NA. This is possible in package ncf partial.mantel.test, however this sues a different permutation to that used in ecodist.ecodist will not accept data with NA values, returning a "matrix is not square error. is it possible to perform this test in ecodist? many thanks
2010 Jul 19
3
invalid type error
>myDF = data.frame(id=c("A10","A20"),d1=c(.3,.3),d2=c(.4,.4),d3=c(-.2,.5),d4=c(-.3,.6),d5=c(.5,-.2),d6=c(.6,-.4),d7=c(-.9,-.5),d8=c(-.8,-.6)) >doit=function(x)c(x[1],sum_LK_positive=sum(x[-1][x[-1]>0]),sum_LK_negative=sum(x[-1][x[-1]<0])) > myDF id d1 d2 d3 d4 d5 d6 d7 d8 1 A10 0.3 0.4 -0.2 -0.3 0.5 0.6 -0.9 -0.8 2 A20 0.3 0.4 0.5 0.6 -0.2