search for: vec1

Displaying 20 results from an estimated 113 matches for "vec1".

Did you mean: vec
2012 Aug 24
6
updating elements of a vector sequentially - is there a faster way?
I would like to know whether there is a faster way to do the below operation (updating vec1). My objective is to update the elements of a vector (vec1), where a particular element i is dependent on the previous one. I need to do this on vectors that are 1 million or longer and need to repeat that process several hundred times. The for loop works but is slow. If there is a faster way, ple...
2010 Feb 02
1
Build a matrix from another matrix by specifying the indexes
Hello R specialists, I have a base vector called vBase with 102 elements. I have another vector vec1 which elements are only part of vBase but is shorter. I transform vec1 so I get a vector with the same size as vBase and with each common element on the same indexed row. If a value is missing in vec1 then I put a Na like this: vec1 vBase Amsterdam Amsterdam Na...
2002 Jun 18
5
insert number in vector
Hello R-users, I need to create a vector inserting an 1 after each value of another vector. For example: vec1<-c(2,3,4) I need to create a vector with the values 2,1,3,1,4 Does anyone know how create this vector without loops (vec1 could have 1000 elements) Thank you, Juan -.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.- r-help mailing list -- Read http://www.ci.tuwi...
2024 Jun 16
1
slowness when I use a list comprehension
This can be vectorized. Try ix <- seq_along(vec2) S_diff2 <- sapply(seq_len(N1-(N2-1)*ratio_sampling), \(j) sum((vec1[(ix-1)*ratio_sampling+j] - vec2[ix])**2)) On Sun, Jun 16, 2024 at 11:27?AM Laurent Rhelp <laurentRHelp at free.fr> wrote: > > Dear RHelp-list, > > I try to use the package comprehenr to replace a for loop by a list > comprehension. > > I wrote the code but I certai...
2013 Feb 17
6
histogram
HI Elisa, You could use ?cut() vec1<-c(33,18,13,47,30,10,6,21,39,25,40,29,14,16,44,1,41,4,15,20,46,32,38,5,31,12,48,27,36,24,34,2,35,11,42,9,8,7,26,22,43,17,19,28,23,3,49,37,50,45) label1<-unlist(lapply(mapply(c,lapply(seq(0,45,5),function(x) x),lapply(seq(5,50,5),function(x) x),SIMPLIFY=FALSE),function(i) paste(i[1],"<...
2001 Nov 01
1
Erratic behaviour of sammon()
I'm not sure this list is the right place for this thing. I noticed some erratic behaviour in sammon(). Running sammon on two nearly identical sets of data results in very different results. Below is an example. I create an initial configuration with cmdscale() and store it into 'vec1'. I write this to file, and read it back in again to 'vec2'. According to cor() on the three columns of 'vec1' and 'vec2', they are identical. However, if I use sammon() with initialising from 'vec1' or 'vec2', I get different results. (SAMMON() is a wrap...
2006 Feb 13
2
?bug? strange factors produced by chron
...ac<-as.factor(rep(vec,c(5,5,5))) split(rnorm(15),fac) $"1Q.04" [1] 1.9803999 -0.3672215 -1.0441346 0.5697196 -0.1350546 $"1Q.05" [1] 2.40161776 -0.03924000 0.68973936 0.02800216 -0.74327321 $"1Q.06" [1] 0.1887923 -1.8049586 1.4655549 0.1532533 2.1726117 vec1<-as.Date(Sys.time()) vec1<-c(vec1, vec1-100, vec1-300) vec1<-rep(vec1,c(5,5,5)) fac1<-interaction(quarters(as.chron(as.POSIXct(vec1))), format(vec1,"%y")) > split(rnorm(15),fac1) Error in split(x, f) : second argument must be a factor ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^...
2008 May 12
1
lexicographic comparison of two vectors
Is there any built-in way to lexicographically compare two vectors of the same length in R? The textbook algorithm could be coded as follows: lex.cmp <- function (vec1,vec2) { for (j in 1:length(vec1)) { if (vec1[j] < vec2[j]) { return(-1) } if (vec1[j] > vec2[j]) { return(1) } } return(0) } Thanks, Gabriel
2013 Oct 11
3
matrix values linked to vector index
Hi, In the example you showed: m1<- matrix(0,length(vec),max(vec)) 1*!upper.tri(m1) #or ?m1[!upper.tri(m1)] <-? rep(rep(1,length(vec)),vec) #But, in a case like below, perhaps: vec1<- c(3,4,5) ?m2<- matrix(0,length(vec1),max(vec1)) ?indx <- cbind(rep(seq_along(vec1),vec1),unlist(tapply(vec1,list(vec1),FUN=seq),use.names=FALSE)) m2[indx]<- 1 ?m2 #???? [,1] [,2] [,3] [,4] [,5] #[1,]??? 1??? 1??? 1??? 0??? 0 #[2,]??? 1??? 1??? 1??? 1??? 0 #[3,]??? 1??? 1??? 1??? 1???...
2009 Jul 27
1
how to use do.call together with cbind and get inside a function
Dear R-helpers: I have a question related to using do.call to call cbind and get. #the following works vec1 <- c(1,2) vec2 <- c(3,4) ColNameVec <- c('vec1','vec2') mat <- do.call("cbind",lapply(ColNameVec,get)) mat #put code above into a function then it does not work #before doing so, first remove vec1 and vec2 from global environment rm(vec1,vec2) test <- func...
2007 Aug 23
0
indexing and regression testing
...ackages were developed under 2.5.1 and I plan to publish them under a GPL2-QA, a GPL2 clone that obliges users to participate in some kind of regression testing (to be defined). Best regards Jens Oehlschl?gel P.S. > # some timings using timefactor(regtest) > library(rindex) > > Vec1 <- c(NA, paste('a', 1:1000000, sep="")) > Vec2 <- c(paste('a', 1:1000000, sep=""), NA) > iVec1 <- index(Vec1, verbose=TRUE) user.self sys.self elapsed sort 7.85 0.01 7.86 tree 0.00 0.00 0.00 > iVec2 <- index(Vec2,...
2008 Dec 30
2
[LLVMdev] Folding vector instructions
...;min", the conversion involves in 'extract' the vector, create less-than-compare, create 'select' instruction, and create 'insert-element' instruction. <code> llvm::Value * Instructions::min(llvm::Value *in1, llvm::Value *in2) { std::vector<llvm::Value*> vec1 = extractVector(in1); // generate LLVM extract element std::vector<llvm::Value*> vec2 = extractVector(in2); Value *xcmp = m_builder.CreateFCmpOLT(vec1[0], vec2[0], name("xcmp")); Value *selx = m_builder.CreateSelect(xcmp, vec1[0], vec2[0],...
2012 Nov 08
5
map two names into one
Thanks. Yes. Your approach can identify: Glaxy ace S 5830 and S 5830 Glaxy ace But you can not identify using same program: Iphone 4S 16 G Iphone 4S 16G How should I solve both in same time. Kind regards,Tammy [[alternative HTML version deleted]]
2010 Aug 24
3
multiple assignments ?
Simple one, have read and googled, still no luck! I want to create several empty vectors all of the same length. I would like multiple empty vectors (vec1, vec2, vec3) and want to create them all in one line. I've tried vec1,vec2,vec3 <- vector(length=5) and c(vec1,vec2,vec3) <- vector(length=5) and several other attempts but nothing seems to work ... suggestions? Thanks Jim =============================== Dr. Jim Maas University of E...
2011 Jun 03
2
Arules: R Crashes when running eclat with tidLists=TRUE
..., Dirk /*---------------------------------------------------------------------- Item Set Report Function ----------------------------------------------------------------------*/ static void _report_R (int *ids, int cnt, int supp, int *tal, void *data) { (...) if (flags & OF_LIST) { vec1 = (int*)realloc(ruleset->trnb, size1 *sizeof(int)); if (!vec1) { if (vec) free(vec); if (vec2) free(vec2); _cleanup(); error(msg(E_NOMEM));} ruleset->trnb = vec1; } (...) if (flags & OF_LIST) { /* if to list the transactions, */ h = ruleset->t...
2013 Mar 22
2
A question on function return
Hello again, Let say I have following user defined function: fn <- function(x, y) { Vec1 <- letters[1:6] Vec2 <- 1:5 return(list(ifelse(x > 0, Vec1, NA), ifelse(y > 0, Vec2, NA))) } Now I have following calculation: > fn(-3, -3) [[1]] [1] NA [[2]] [1] NA > fn(3, -3) [[1]] [1] "a" [[2]] [1] NA Here I can not understand why in the second case, I ge...
2024 Jun 16
2
slowness when I use a list comprehension
...omprehension. ?I wrote the code but I certainly miss something because it is very slower compared to the for loops. May you please explain to me why the list comprehension is slower in my case. Here is my example. I do the calculation of the square difference between the values of two vectors vec1 and vec2, the ratio sampling between vec1 and vec2 is equal to ratio_sampling. I have to use only the 500th value of the first serie before doing the difference with the value of the second serie (vec2). Thank you Best regards Laurent library(tictoc) library(comprehenr) ratio_sampling <-...
2024 Jun 16
1
slowness when I use a list comprehension
...omprehension. I wrote the code but I certainly miss something because it is very slower compared to the for loops. May you please explain to me why the list comprehension is slower in my case. Here is my example. I do the calculation of the square difference between the values of two vectors vec1 and vec2, the ratio sampling between vec1 and vec2 is equal to ratio_sampling. I have to use only the 500th value of the first serie before doing the difference with the value of the second serie (vec2). Thank you Best regards Laurent library(tictoc) library(comprehenr) ratio_sampling <-...
2013 Jun 18
1
transform 3 numeric vectors empty of 0/1
Dear all, Without a loop, I would like transform 3 numeric vectors empty of 0/1 of same length Vec1 : transform 1 to A and 0 to "" Vec2 : transform 1 to B and 0 to "" Vec3 : transform 1 to C and 0 to "" to obtain only 1 vector Vec who is the paste of the 3 vectors (Ex : ABC, BC, AC, AB,...) Any idea ? Thank you for your help -- Michel ARNAUD
2024 Jun 16
1
slowness when I use a list comprehension
...them to manage numeric vactors. In some cases you can switch to matrices or arrays to remove even more list manipulations from the script. library(microbenchmark) ratio_sampling <- 500 ## size of the first serie N1 <- 70000 ## size of the second serie N2 <- 100 ## mock data set.seed(123) vec1 <- rnorm(N1) vec2 <- runif(N2) dloop <- function( N1, M2, ratio_sampling, vec1, vec2 ) { S_diff2 <- numeric( N1-(N2-1)*ratio_sampling ) for( j in 1:length(S_diff2) ) { sum_squares <- 0 for( i in 1:length(vec2)){ sum_squares <- ( sum_squares...