similar to: Create sequence given start and end vector

Displaying 20 results from an estimated 20000 matches similar to: "Create sequence given start and end vector"

2011 Jan 05
4
Match numeric vector against rows in a matrix?
Two posts in one day is not a good day...and this question seems like it should have an obvious answer: I have a matrix where rows are unique combinations of 1's and 0's: > combs=as.matrix(expand.grid(c(0,1),c(0,1))) > combs Var1 Var2 [1,] 0 0 [2,] 1 0 [3,] 0 1 [4,] 1 1 I want a single function that will give the row index containing an exact match
2011 Jan 05
3
How to 'explode' a matrix
Hi everyone, I'm looking for a way to 'explode' a matrix like this: > matrix(1:4,2,2) [,1] [,2] [1,] 1 3 [2,] 2 4 into a matrix like this: > matrix(c(1,1,2,2,1,1,2,2,3,3,4,4,3,3,4,4),4,4) [,1] [,2] [,3] [,4] [1,] 1 1 3 3 [2,] 1 1 3 3 [3,] 2 2 4 4 [4,] 2 2 4 4 My current kludge is this:
2012 Jan 28
2
Need very fast application of 'diff' - ideas?
Hi everyone, Speed is the key here. I need to find the difference between a vector and its one-period lag (i.e. the difference between each value and the subsequent one in the vector). Let's say the vector contains 10 million random integers between 0 and 1,000. The solution vector will have 9,999,999 values, since their is no lag for the 1st observation. In R we have: #Set up input vector
2006 Sep 23
2
Create a vector of indices from a matrix of start and end points
I have a very large dataframe and wish to extract a subset of rows. I have a two column matrix listing the starting and ending indices of one subset on each row. My idea is to create a vector of indices that could be applied to the dataframe and I have a solution using a for loop (below). But surely there is some more elegant way to do this! I looked thorough the archives without
2011 Apr 14
3
Find number of elements less than some number: Elegant/fast solution needed
Take vector x and a subset y: x=1:10 y=c(4,5,7,9) For each value in 'x', I want to know how many elements in 'y' are less than 'x'. An example would be: sapply(x,FUN=function(i) {length(which(y<i))}) [1] 0 0 0 0 1 2 2 3 3 4 But this solution is far too slow when x and y have lengths in the millions. I'm certain an elegant (and computationally efficient)
2010 Nov 16
2
Pass character vector to function argument
A bit embarrassed to post this seemingly trivial question, but I can't find anything in the archive that's quite relevant: a1=1 a2=2 obs=objects(pattern=glob2rx("a?")) I want to utilize 'obs' as a function argument to produce something like: sum(a1,a2) Obviously, sum(obs) doesn't work, but I've tried variations of 'eval', 'parse',
2010 Feb 05
0
Plot point text labels over polygon w/o overlap?
Using pointLabel in the maptools package will plot text labels for points to avoid overlap of text. But is there a way to avoid/minimize overlap of text labels with the outline of an underlying polygon? For example, when plotting location of cities, one would like the text labels to not fall on top of nearby country/state borders, etc. Many thanks, Kevin Ummel Central European University
2009 Jan 09
3
create sequences from two "from" and "to" vectors
hi all, how can I create sequences that start from a known vector, say x1 and end with another say x2- also suppose all the sequences will be the same length. I don't want to use a for loop x1<-c(1,2,3,4); x2<-(3,4,5,6); what I want is 1 2 3 4 2 3 4 5 3 4 5 6 Thanks ----- Yasir H. Kaheil Columbia University -- View this message in context:
2008 Aug 26
4
sequence with start and stop positions
Hi, I have a vector of start positions, and another vector of stop positions, eg start<-c(1,20,50) stop<-c(7,25,53) Is there a quick way to create a sequence from these vectors? new<-c(1,2,3,4,5,6,7,20,21,22,23,24,25,50,51,52,53) the way Im doing it at the moment is pos<-seq(start[1],stop[1]) for (i in 2:length(start)){ new<-seq(start[i],stop[i]) pos<-c(pos,new) }
2010 Jul 20
3
Sequence from 2 Vectors
I would like to create a vector that is a sequence from 2 vectors. Could anyone provide suggestion on this? For example > a<-c(1,2,3) > b<-a+2 > b [1] 3 4 5 I would like to have a vector that is a sequence which starting from a and ending at b c = c(1:3,2:4,3:5) c = c(1,2,3,2,3,4,3,4,5) Thank you Best Regards, Suphajak Ngamlak Equity and Derivatives Trading Phatra Securities
2005 Feb 11
3
formatC with illegal input crashes Rgui (PR#7686)
Full_Name: Peter Ehlers Version: rw2001pat (2005-02-03) OS: Win XP Submission from: (NULL) (136.159.61.115) formatC(1, flag="s") crashes Rgui. Similarly for flag=[SnZ]. Stupid input, of course, but I'm error-prone. Peter
2006 Aug 30
4
Create a vector from another vector
Dear list Suppose I have the following vector: x <- c(3,4,2,5,6) Obviously, this sums to 20. Now, I want to have a second vector, call it x2, that sums to x where 5 <= x <= 20, but there are constraints. 1) The new vector must be same length as x 2) No element of the new vector can be 0 3) Element x2[i] of the new vector cannot be larger than element x[i] of the original vector 4)
2008 Feb 23
2
counting sequence mismatches
Hello I have 2 columns of short sequences that I would like to compare and count the number of mismatches and record the number of mismatches in a new column. The sequences are part of a data frame that looks like this: seq1=c("CGGTGTAGAGGAAAAAAAGGAAACAGGAGTTC","CGGTGGTCAGTCTGGGACCTGGGCAGCAGGCT", "CGGGCCTCTCGGCCTGCAGCCCCCAACAGCCA")
2011 Nov 02
1
Generate a sequence of vectors of different length
Hi everyone After the following setup sector=2 # Define Number of Sectors sectors=LETTERS[seq( from = 1, to = sector )] # Name sectors No_ent=round(3/runif(sector)) # Number of entities per sector #Tot_No_ent=sum(No_ent) Goal is to get a List like (A1, A2, A3, B1, B2, B3, B4) where A is denoting an industrial sector and then a numbered sequence of companies within the sector. The step
2007 Sep 03
3
element wise opertation between a vector and a list
I want to try to get a result of element wise addition between a vector and a list. It can be done with "for statement." In order to reducing computing time, I have tried to avoid "for state." If anybody give me an idea, I would apprecite it much. for example, with a & b as below lines, a<- list(c(1,3),c(1,2),c(2,3)) b<-c(10,20,30) I would like to have a list (like
2011 Sep 29
1
multiplying list with vector
hello everybody, i have got a question about lists: i have got the following commands: mylist <- list("v1"=c(1,2,2,1),"v2"=c(2,2,2,1),"v3"=c(1,1,1,1)) myvector <- c(100,10000,1000000) now i would like to multiply each element of the list with the corresponding element of the vector, that is to say: v1*100 v2*10000 v3*1000000 i only could think of lapply
2009 Jun 03
1
Vectorize fails for function with ... arglist
Vectorize is defined to return a function that acts as if 'mapply' was called. So we have: > mapply(dput,1:2) # mapply form 1L # calls dput on each element of 1:2 2L [1] 1 2 > Vectorize(dput)(1:2) # Vectorize form 1L # same behavior 2L [1] 1 2 Same thing with a named argument: >
2017 Sep 28
3
building random matrices from vectors of random parameters
Thanks for both the mapply and array approaches! However, although intended to generate the same result, they don't: # mapply approach n = 3 sa <- rnorm(n,0.8,0.1) so <- rnorm(n,0.5,0.1) m <- rnorm(n,1.2,0.1) mats = mapply(function(sa1, so1, m1) matrix(c(0,sa1*m1,so1,sa1),2,2,byrow=T), sa, so, m, SIMPLIFY = FALSE) print(mats) [[1]] ????????? [,1]????? [,2] [1,] 0.0000000
2020 Oct 04
3
how to get a numeric vector?
Hi, a <- c(1, 4) b <- c(5, 8) a:b [1] 1 2 3 4 5 Warning messages: 1: In a:b : numerical expression has 2 elements: only the first used 2: In a:b : numerical expression has 2 elements: only the first used how to get: c(1:5, 4:8) Thanks.
2009 Jun 26
2
Indexing a list with a list
Dear list, I have two lists: one with data and one with TRUE/FALSE values for data I want to further analyze (see example below). I have been able to use a for loop to extract the data that I want to keep, but think that there probably exists a way to do it without a loop. Any ideas? #sample data set.seed(100) example = list(letters[1:10], letters[1:10], letters[1:10]) ind =