similar to: Calculating length of consecutive sequences within a vector

Displaying 20 results from an estimated 4000 matches similar to: "Calculating length of consecutive sequences within a vector"

2012 Jan 26
2
Calculate a function repeatedly over sections of a ts object
Hi, I want to apply a function (in my case SDF; package ?sapa?) repeatedly over discrete sections of a daily time series object by sliding a time window of constant length (e.g. 10 consecutive years or 1825 days) over the entire ts at increments of 1 time unit (e.g. 1 year or 365 days). So for example, the first SDF would be calculated for the daily values of my variable recorded between years 1
2008 Oct 22
3
coalesce columns within a data frame
Dear all, I searched the mail archives and the R site and found no guidance (tried "merge", "cbind" and terms like "coalesce" with no success). There surely is a way to coalesce (like in SQL) columns in a dataframe, right? For example, I would like to go from a dataframe with two columns to one with only one as follows: From Name.x Name.y nx1 ny1 nx2 NA
2005 Mar 11
2
Calculating lengths of runs of 0 or 1 sequences in meteorological data
Dear List Members, I need some help about programming in S language. My problem is as follows: I have meteorological data (about rainfall measurement each day from 1989-2002), say like http://www.angelfire.com/ab5/get5/data.rainfall.txt or http://www.angelfire.com/ab5/get5/R.rainfall.txt in a sequence of 0(denoting dry day)'s and 1(denoting wet day)'s. I want to construct a frequency
2005 May 01
1
opimization problem
hi, i want to execute the following opimization problem: max r*w s.t.: w*z=1 # sum of w is 1 r, w are [nx1] vectors, z is a [nx1] vector consisting of 1 so far so good, works fine with lp the problem arises with the additional restriction w' * V * w where V is a [nxn] matrix how can i include this restriction since w arises twice? thanks, gg --
2003 Aug 04
1
Novice question
Hello. I am new R user, so this question is probably quite stupid, but for the life of me I cannot figure out how to get predications using multivariate linear regression analysis. Single variable predictions work fine. I am trying the following: -- Known y's for known x's1 and x's2 ys <- c(133890, 135000, 135790, 137300, 138130, 139100, 139900, 141120, 141890, 143230, 144000,
2007 Oct 09
3
identify number of sequences from a vector
? stato filtrato un testo allegato il cui set di caratteri non era indicato... Nome: non disponibile Url: https://stat.ethz.ch/pipermail/r-help/attachments/20071009/365764b4/attachment.pl
1997 Sep 05
2
R-beta: help with R simulation
[[this bounced first, because it has 'help' in the Subject line ... -- Martin Maechler ]] I am a complete novice R programmer. (Though I know C quite well) I am trying to write some R code to do the following simulation. There is a 2-frame "movie" of noise and signal dots. the noise dots have random positions in each frame. The signal dots are placed randomly in frame 1,
2009 Jul 07
3
Error due to non-conformable arrays
Hello, Consider this function for generalized ridge regression: gre <- function (X,y,D){ n <- dim(X)[1] p <- dim(X)[2] intercept <- rep(1, n) X <- cbind(intercept, X) X2D <- crossprod(X,X)+ D Xy <- crossprod(X,y) bth <- qr.solve(X2D, Xy) } # suppose X is an (nxp) design matrix and y is an (nx1) response vector p <- dim(x)[2] D<- diag(rep(1.5,p)) bt
2007 Sep 03
2
The quadprog package
Hi everybody, I'm using Windows XP Prof, R 2.5.1 and a Pentium 4 Processor. Now, I want to solve a quadratic optimization program (Portfolio Selection) with the quadprog package I want to minimize (\omega'%*%\Sigma%*%\omega) Subject to (1) \iota' %*% \omega = 1 (full investment) (2) R'%*%\omega = \mu (predefined expectation value) (3) \omega \ge 0 (no short sales). Where
2008 Apr 29
1
Consecutive zeros in a vector
Suppose X is a long vector of integers (typically about 30000 elements). Is there an efficient way to detect whether there are at least N consecutive zeros in X, and if yes, where does this occur? for example, suppose X is: 1 2 3 4 5 0 0 0 0 0 0 0 0 0 0 0 0 0 0 3 4 2 0 1 2 0 0 0 2 2 2 2 2 ... and N is 10. I would like a foo(X, 10) to return something like c(6,19) (start and end positions in X
2008 May 13
2
Max consecutive increase in sequence
Hi all R helpers, I'm trying to comeup with nice and elegant way of "detecting" consecutive increases/decreases in the sequence of numbers. I'm trying with combination of which() and diff() functions but unsuccesifuly. For example: sq <- c(1, 2, 3, 4, 4, 4, 5, 6, 5, 4, 3, 2, 1, 1, 1, 1, 1); I'd like to find way to calculate a) maximum consecutive increase = 3 (from 1
2024 Feb 28
2
converting MATLAB -> R | element-wise operation
On Tue, 27 Feb 2024 13:51:25 -0800 Jeff Newmiller via R-help <r-help at r-project.org> wrote: > The fundamental data type in Matlab is a matrix... they don't have > vectors, they have Nx1 matrices and 1xM matrices. Also known as column vectors and row vectors. :) > Vectors don't have any concept of "row" vs. "column". They do in (numerical) linear
2009 Jul 07
3
Numbering sequences of non-NAs in a vector
Greetings, I have a vector of the form: [10,8,1,3,0,8,NA,NA,NA,NA,2,1,6,NA,NA,NA,0,5,1,9...] That is, a combination of sequences of non-missing values and missing values, with each sequence possibly of a different length. I'd like to create another vector which will help me pick out the sequences of non-missing values. For the example above, this would be:
2009 Oct 28
1
Need help locating the longest series of consecutive numbers in a matrix
I need to determine the length of the longest series of consecutive numbers (1's to be specific) and the start time of that series. For example, in the following sample, the first column is "time" and the second column indicates the presence of the target behavior. I would like a function that would return "21" as the start time and "17" as the length. sample
2009 Oct 29
1
How to turn individual consecutive information into survival objects?
Dear R List, I have a dataset with the following structure: """personal_id, p_0, p_1, p_2, .... , p_36, p_37 1, NA, 1, 4, .... , 1, NA 2, NA, NA, NA, .... , 4, NA . . . 6020, NA, 3, 3, ...., NA, NA 6021, NA, 2, 2, ...., 4, NA """ I used some made-up data. It is just meant to show the structure of the dataset. The variables of interest are p_0, ... p_37.
2010 Nov 17
1
Multiple Line Plots with xyplot
I'm trying to make multiple line plots, each with a different color, using the xyplot command. Specifically, I have an NxK matrix Y and an Nx1 matrix x. I would like the plot to contain a line for each (x, Y[,i]), i=1:K. I know something like xyplot(Y[,1] + Y[,2] + Y[,3] ~ x, type='l') will work, but if Y is large, this notation can get very awkward. Is there a way to do something
2010 Mar 11
1
how does R compute Std. Error's?
i am trying to duplicate R's computation of standard errors but having some trouble. i loaded some data into R and ran summary(lm(y~x1+x2+x3+0, data=data)), but i am not sure how the "Std. Error" values are computed. let y be the nx1 vector of dependent variables and X be the nx3 matrix of independent variables. let T(.) denote the transpose of a matrix/vector, and let I(.) denote
2011 Jun 01
3
Identifying sequences
Hallo Everybody Consider the following vector a=1:10 b=20:30 c=40:50 x=c(a,b,c) I need a function that can tell me that there are three set of continuos sequences and that the first is from 1:10, the second from 20:30 and the third from 40:50. In other words: a,b, and c. regards Christiaan [[alternative HTML version deleted]]
2011 Sep 20
2
Multivariate spline regression and predicted values
Hello, I am trying to estimate a multivariate regression of Y on X with regression splines. Y is (nx1), and X is (nxd), with d>1. I assume the data is generated by some unknown regression function f(X), as in Y = f(X) + u, where u is some well-behaved regression error. I want to estimate f(X) via regression splines (tensor product splines). Then, I want to get the predicted values for some new
2003 Sep 05
4
Basic Dummy Variable Creation
Hi There, While looking through the mailing list archive, I did not come across a simple minded example regarding the creation of dummy variables. The Gauss language provides the command "y = dummydn(x,v,p)" for creating dummy variables. Here: x = Nx1 vector of data to be broken up into dummy variables. v = Kx1 vector specifying the K-1 breakpoints p = positive integer in the range