similar to: subsets of vector

Displaying 20 results from an estimated 20000 matches similar to: "subsets of vector"

2009 Nov 11
2
partial cumsum
Hello, I am searching for a function to calculate "partial" cumsums. For example it should calculate the cumulative sums until a NA appears, and restart the cumsum calculation after the NA. this: x <- c(1, 2, 3, NA, 5, 6, 7, 8, 9, 10) should become this: 1 3 6 NA 5 11 18 26 35 45 any ideas? thank you and best regards, stefan
2006 Mar 25
2
problem with diff
dear R users I am having a problem with the output of diff for a numeric vector which has the values (2,4,6,7), one expects to get 2 2 1 but I am getting 4 6 7, here is the setup. info <- with(rle(x), data.frame(value = values, start = cumsum(lengths)-lengths+1, end = cumsum(lengths) )[lengths > 1,] ); > x <-
2003 Nov 14
2
bad performance of a function
Dear all I need to find a length of true sequences in logical vector (see example 1). I found a possible solution which is good but if I use it on a larger data set I experience a substantial decrease in performance (example 2). Example 1 set.seed(111) x <- sample(c(T,F),50, replace=T) system.time(cetnost <- as.numeric(table(which(x)-cumsum(x[which(x)])))) [1] 0.00 0.00 0.03 NA NA
2013 Jul 22
4
How to split two levels several times?
Hi, I have a small problem with the function split() and would appreciate your help. I have a table called ?XXX? with 2 columns and 49 rows. The 49 rows belong to 8 different levels (electrode1, ...,electrode8). I want to split the table always at the row where ?electrode1? starts again so that I can export 7 individual dataframes (numbered ?dataframe1? to ?dataframe7?) which contain always
2009 Dec 07
1
Subset of time observations where timediff > 60 secs
Dear list members I have a rather large vector (part of a data frame) giving the time (date + time, POSIXct) of observations. The times are irregular (with both small and large jumps) but increasing, and there are several millions of them. I now wish to reduce my data set, so that I only have observations which are at least (for example) 60 seconds apart. Basically, I need (all) the indices
2011 Jan 30
1
Extract subsets of different and unknown lengths from huge dataset
Dear prospective reader, I apologize for posting my problem but I've just no idea how to go on by processing this huge (over 70 MB) dataset. Thank you in advance for any help or comment! I do appreciate it! My textfile contains 1 column of interest (numbers/values only). The overall issue is to extract 'events', starting points of which are defined by at least 24 preceding values
2007 Dec 04
3
Inserting a subsequence between values of a vector
Hallo, suppose I have a vector: x <- c(1,1,1,2,2,3,3,3,3,3,4) How can I generate a vector/sequence in which a fixed number of zeroes (say 3) is inserted between the consecutive values, so I get 1,1,1,0,0,0,2,2,0,0,0,3,3,3,3,3,0,0,0,4 thanks a lot, Serguei [[alternative HTML version deleted]]
2007 Jun 19
4
How do I avoid a loop?
Hi, I start with an array of booleans: x <- c( TRUE, TRUE, TRUE, FALSE, FALSE, TRUE, TRUE, FALSE, TRUE ); I want to define an y <- f(x) such that: y <- c( 1, 2, 3, 0, 0, 1, 2, 0, 1 ); In other words, do a cumsum when I see a TRUE, but reset to 0 if I see a FALSE. I know I can do this with a very slow and ugly loop or maybe use apply, but I was hoping there are some R experts out
2010 May 26
5
counts of a vector
Hi, I need help to find an efficient way to transform a vector like: a<-c(1,1,0,1,0,0,0,1,1,1,1,0,1,0,1,1) in a vector that counts only di 1 elements, like: b<-c(1,2,0,1,0,0,0,1,2,3,4,0,1,0,1,2) Thank you! -- View this message in context: http://r.789695.n4.nabble.com/counts-of-a-vector-tp2232047p2232047.html Sent from the R help mailing list archive at Nabble.com.
2005 Jan 27
5
Finding "runs" of TRUE in binary vector
I have a binary vector and I want to find all "regions" of that vector that are runs of TRUE (or FALSE). > a <- rnorm(10) > b <- a<0.5 > b [1] TRUE TRUE TRUE FALSE TRUE FALSE TRUE TRUE TRUE TRUE My function would return something like a list: region[[1]] 1,3 region[[2]] 5,5 region[[3]] 7,10 Any ideas besides looping and setting start and ends directly?
2010 Mar 27
4
replace id by running number
Dear all, I want to replace an (unsorted) id variable in a large dataset by a running number without changing the order of the cases. E.g., y <- c(4,4,4,2,45,12,12) should be replaced by something like x <- c(1,1,1,2,3,4,4) Sorry for this simple question & thank you very much for your help! [[alternative HTML version deleted]]
2011 Jun 07
1
count length of continues elements in a vector
I am performing a precipitation analysis. data is in the form of daily precipitation amounts, e.g. x<- c(4,5,3,0,0,0,2,4,6,4,0,0,0,2,2,0,3,4,1,0,...) I would like to find the length of the "storm", length of storm would be defined as the number of days with continues precipitation. in this case the returned vector would be: (3,4,2,3,...) I would also like the amount of
2008 Jun 19
1
replacing segments of vector by their averages
Given a vector of numeric of length n, I need to find segments that are >= 0.2, compute the average of individual segments, and replace the original values in each segment by their corresponding averages. For example, there are three segments that are >= 0.2, the average of 1st segment is 0.3, 2nd is 0.5, and the 3rd is 0.5333333 >
2010 Nov 25
6
help: program efficiency
hey guys, I am working on a function to make a duplicated value unique. For example, the original vector would be like : a = c(2,1,1,3,3,3,4) I'll like to transform it into: a.nodup = 2, 1.01, 1.02, 3.01, 3.02, 3.03, 4 basically, find the duplicates and assign a unique value by adding a small amount and keep it in order. I come up with the following codes, but it runs slow if t is large. Is
2010 May 26
3
Peak Over Threshold values
Dear List I hope you can help me: I?ve got a dataframe (df) within which I am looking for Peak Over Threshold values as well as the length of the events. An event starts when walevel equals 5.8 and it should end when walevel equals the lower threshold value (5.35). I tried ?clusters (?)? from ?evd package?, and varied r (see example) but it did not work for all events (again
2005 Nov 29
2
qcc
violating.runs I read from the news cran.r-project.org/doc/Rnews/Rnews_2004-1.pdf that the criteria for the violating is 5 but 1)I cannot find "5" in the code of the function. Where is the "5" ? 2)What is the easiest way to change it ? 3)Is there any more criterias made somewhere ? Yours sincerelly, Tommi Viitanen
2002 Jul 24
4
cumsum and subsets of a data frame?
I have a question about using cumsum on subsets of a data frame. Suppose I have a frame that looks something like this > tmp f x y 1 left 1 0 2 left 2 0 3 left 3 9 4 left 4 10 5 left 5 23 6 left 6 45 7 left 7 13 8 left 8 2 9 left 9 6 10 right 1 10 11 right 2 26 12 right 3 9 13 right 4 50 14 right 5 78 15 right 6 20 16 right 7 7 17 right 8 20 18 right 9 19
2011 Jul 06
3
identifying a 'run' in a vector
Hi, How can I discern which elements in x (see below) are in 'order', but more specifically.. only the 1st 'ordered run'? I would like for it to return elements 1:8... there may be ordered values after 1:8, but those are not of interest. x <- c(1, 2, 3, 4, 5, 6, 7, 8, 20, 21, 22, 45) Thanks for any suggestions. -- View this message in context:
2024 Nov 27
1
R Processing dataframe by group - equivalent to SAS by group processing with a first. and retain statments
Was wondering when this would be suggested. But the question was about getting the final dataframe... newdta <- olddta newdta$FirstDay <- ave(newdata$date, newdata$ID, FUN = \(x) x[1L]) On November 27, 2024 11:13:49 AM PST, Rui Barradas <ruipbarradas at sapo.pt> wrote: >?s 16:30 de 27/11/2024, Sorkin, John escreveu: >> I am an old, long time SAS programmer. I need to
2006 Jul 17
6
Nested functions
Hi there, I'm having myself a hard time writing an algorithm for finding patterns within a given melody. In a vector I'd like to find ALL sequences that occur at least twice, without having to check all possible patterns via pattern matching. I finally found a solution in a style that I'm used from C, i.e. calling one function from within another. GNU R doesn't seem to like that,