Displaying 20 results from an estimated 108 matches for "vec2".
Did you mean:
vec
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...
2024 Jun 16
2
slowness when I use a list comprehension
...ion.
?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 <- 500
## s...
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, please let
2024 Jun 16
1
slowness when I use a list comprehension
...ion.
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 <- 500
## s...
2010 Jul 12
2
findInterval and data resolution
Hello Wise Ones...
I need a clever way around a problem with findInterval. Consider:
vec1 <- 1:10
vec2 <- seq(1, 10, by = 0.1)
x1 <- c(2:3)
a1 <- findInterval(x1, vec1); a1 # example 1
a2 <- findInterval(x1, vec2); a2 # example 2
In the problem I'm working on, vec* may be either integer or numeric, like
vec1 and vec2. I need to remove one or more sections of this vector; for
ins...
2024 Jun 16
1
slowness when I use a list comprehension
...c 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
+ (
vec1[...
2001 Nov 01
1
Erratic behaviour of sammon()
...ing.
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 wrapper function).
This I did on a Linux machine (R version 1.3.1):...
2004 Jul 09
3
Problem with bwplot
Try factor(vec2) in your bwplot() call.
-----Original Message-----
From: r-help-bounces at stat.math.ethz.ch
[mailto:r-help-bounces at stat.math.ethz.ch]On Behalf Of Ernesto Jardim
Sent: Friday, July 09, 2004 9:41 AM
To: Mailing List R
Subject: [R] Problem with bwplot
Hi,
I'm ploting some box-and-whisker...
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 <- function()
{
vec1 <...
2013 Apr 18
1
vectors with equal values
Hi,
Try:
?vec1<-c(1,1,1,1,1,1,1,1,1)
if(all(vec1==1)) "xxxxxxxxx" else? "yyyyyyyyyyy"
#[1] "xxxxxxxxx"
?vec2<-c(rep(1,4),2)
?if(all(vec2==1)) "xxxxxxxxx" else? "yyyyyyyyyyy"
#[1] "yyyyyyyyyyy"
#or
if(length(unique(vec1))==1) "xxxxxxxxx" else? "yyyyyyyyyyy"
#[1] "xxxxxxxxx"
? if(length(unique(vec2))==1) "xxxxxxxxx" else? "yyyyyy...
2007 Aug 23
0
indexing and regression testing
...PL2-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, verbose=TRUE)
finalized tree
user.self sys.self elapsed
sort...
2008 Dec 30
2
[LLVMdev] Folding vector instructions
...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],
name("selx"));
Value *ycmp = m_builder.CreateFCmpOLT(vec1[1], vec2[1], n...
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 East An...
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
2024 Jun 16
1
slowness when I use a list comprehension
...c 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
+ (
vec1[...
2015 May 04
2
[LLVMdev] Incorrect code generated for arm64
Hi all,
I’ve narrowed down a problem in my code to the following test case:
- - - -
typedef struct {float v[2];} vec2;
typedef struct {float v[3];} vec3;
vec2 getVec2();
vec3 getVec3()
{
vec2 myVec = getVec2();
vec3 res;
res.v[0] = myVec.v[0];
res.v[1] = myVec.v[1];
res.v[2] = 1;
return res;
}
- - - -
Compiling this with any level of optimization for arm64 gives incorrect code, unless my test case...
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
2010 Feb 02
1
Finding the difference between two vectors
Hello everyone,
I have two vectors having only one element different:
vector1 vector2
vector1
TWC TWC
TWC
VFC TWX
NA
VIA/B VFC
VFC
2013 Feb 17
1
addition in the initial question
Dear Elisa,
Try this:
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)
vec2<-vec1[1:26]
names(vec2)<-LETTERS[1:26]
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],"<x<=",i[2],sep="")))
?dat1<-data.frame(vec2,class=cut(vec2,breaks=seq(0,50,5),label...
2008 Sep 20
1
lower and upper limits in integrate as vectors
...values
"integrand" <- function(z)
{
return(z * z)
}
i do this with a for-loop
for(i in 2:4)
{
z <- integrate(integrand, i-1, i)$value
cat("z", z, "\n")
}
to speed up the computation for many values i tried vectors
in integrate to do this.
vec1<-1:3
vec2<-2:4
integrate(Vectorize(integrand), vec1, vec2)$value
but here it seems the integration works only for the first values of
vec1 and vec2.
If you have any advice how i can to this computations with vectors or
something like that, i would be very thankful,
best regards
Andreas