search for: vec1

Displaying 20 results from an estimated 108 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...
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...
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 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...
2011 Apr 14
1
nesting multiple for loops
...ar_zounds' f1 <- c('ace', 'boy', 'car', 'dog') f2 <- c('van', 'wall', 'xes', 'zounds') # actual vectors are length 6 and 7, so I don't want to individually sum the 42 combinations. > var.table <- function(data, vec1, vec2) { table <- as.data.frame(matrix(nrow = length(vec1), ncol = length(vec2)), row.names = vec1) names(table) <- vec2 for (i in 1:length(vec1)) { for (j in 1:length(vec2)) { indices <- intersect(grep(vec1[j], names(data), value = TRUE), grep(cats[i], names(data), v...
2013 Mar 21
2
Displaying median value over the horizontal(median)line in the boxplot
...for troubling you but I am very very new to this programming and to R as you can see. <quote author='arun kirshna'> Hi, Lines1<-readLines(textConnection("Column1 -1,2,3,4,5,6,6,7 COlumn2- 3,4,5,6,7,8,8 Column3-- 45,66,7,8,89, COlumn4-5,6,7,7,8,9 Column5 -5,6,7,8,8")) vec1<-unlist(strsplit(Lines1,"-")) dat1<-as.data.frame(t(read.table(text=vec1[grepl(",",vec1)],sep=",",fill=TRUE))) row.names(dat1)<-NULL colnames(dat1)<-tolower(gsub(" $","",vec1[grepl("^C",vec1)])) dat1 #? column1 column2 column3...
2004 May 25
1
cor and missing values. Bug?
...() function works but I am not sure how to go about this. Rank function places missing values at the end by default thus skewing the rank relationship between two vectors: Example: R : Copyright 2003, The R Foundation for Statistical Computing Version 1.8.1 (2003-11-21), ISBN 3-900051-00-3 > vec1 <- 1:10 > vec2 <- 2*vec1 > vec1[c(1, 5)] <- NA > cor(vec1, vec2, use="pair", method="pearson") [1] 1 > cor(vec1[-c(1,5)], vec2[-c(1,5)], use="pair", method="pearson") [1] 1 #pearson is OK > cor(vec1, vec2, use="pair", method=...