similar to: counting entries in vector

Displaying 20 results from an estimated 40000 matches similar to: "counting entries in vector"

2010 May 18
2
Counting Frequencies in Data Frame
Hi, I am sure there is an easy way to do it, but I can't find it. I have a data frame that has 15 columns and 7000 rows. The only values inside the data.frame are "aa", "ab", "bb" as you can see an example bellow. 1 2 3 1 aa ab ab 2 ab ab ab 3 aa aa aa 4 bb bb bb What I would like to do, is to generate a vector (or another data.frame) with 7000 rows, and 3
2006 Mar 29
3
Sub-vector
Dear list, Given a vector of logical values, say >a <- c(TRUE,TRUE,TRUE,FALSE,FALSE,FALSE,FALSE,TRUE,TRUE,TRUE) Are there any R functions that can tell whether there are two or more "TRUE" in a row in this vector? Thanks, Wuming
2010 Feb 22
1
counting repeating sequence lengths in a vector
Hello, I have a very long (~50,000) sequence of repeating numbers. The first 100 are: [1] 0 0 0 0 0 0 0 0 0 0 0 429 [13] 429 429 429 429 429 429 429 858 858 858 858 858 [25] 858 1287 1287 1287 1287 1287 1716 2145 2145 2574 2574 3003 [37] 3003 3432 3432 3861 4290 4719 5148 5577 5577 6006 6006
2006 Oct 24
4
avoiding a loop
I think I asked a similar question 3 years ago to the Splus list and I think the answer was no or noone answered so noone should spend more than 5 minutes on this because it could definitely be a waste of time. My question is whether the function below can be rewritten without a for loop. apply is fine if it can be done that way but i doubt it. I call it a lot and would prefer to not loop.
2007 Nov 15
2
counting strings of identical values in a matrix
Hello I have this problem. I have a large matrix of this sort: > prova [,1] [,2] [,3] [,4] [1,] 3 3 3 3 [2,] 3 3 3 1 [3,] 1 3 3 3 [4,] 1 1 1 3 [5,] 3 1 1 3 [6,] 3 1 1 3 [7,] 1 3 1 3 [8,] 1 3 3 3 What I want to do is to count the number of sequences of ones and stack the results in a
2008 Oct 27
3
counting run lengths
Hello, I have the following problem. I am running simulations on possible states of a set of agents (1=employed, 0=unemployed). I store these simulated time series in a matrix like the following, where rows indicates time periods, columns the number of agents (4 agents and 8 periods in this case): Atr=[ 1 1 1 1 1 1 0 1 1 1 0 1 1 1 0 1 0 1 0 1 0
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.
2011 Jan 14
2
selecting elements in vector
Hi everybody, I have the following problem. I have a vector containing character elements, such as: list = c("aa","bb","cc","dd","ee") I want to create an index which identifies the elements that are different from, e.g. "aa" and "bb". When I do the following: jj = list!="aa" & list!="bb" > jj
2009 Jul 30
2
Retrieving original data frame after repetition
Dear R users, Consider the first two columns of a data frame like this: > z[,1:2] x y 1 1 1 2 2 2 3 3 3 4 1 4 Imagine that y represents the times that the value x happens in a population. But z is not exactly a frequency table, because in z we have x=1 twice. So, the x=1 in the first line and the x=1 in the fourth are not the same, differing according to a third variable in
2010 May 26
3
Counting indexes
Hallo! I have a vector of ID's like so, id <- c(1,2,2,3,3,3,4,5,5) I would like to create a [start,stop] pair of vectors that index the first and last observation per ID. For the ID list above, it would look like 1 1 2 3 4 6 7 7 8 9 I haven't worked with indexes/data manipulation much in R, so any pointers would be helpful. Many thanks! ~~~~~~~~~~~~~~~~~~~ -Robin Jeffries Dr.P.H.
2011 Jun 23
3
problem (and solution) to rle on vector with NA values
Hello there R-help, I'm not sure if this should be posted here - so apologies if this is the case. I've found a problem while using rle and am proposing a solution to the issue. Description: I ran into a niggle with rle today when working with vectors with NA values (using R 2.31.0 on Windows 7 x64). It transpires that a run of NA values is not encoded in the same way as a run of other
2003 Mar 28
1
overlapping pattern match (errata 2.0)
well! excuse me again but... your.string <- "aaacdf" nc1 <- nchar(your.string)-1 x <- unlist(strsplit(your.string, NULL)) ######## CORRECT x2 <- c() for (i in 1:nc1) x2 <- c(x2, paste(x[i], x[i+1], sep="")) ######## ERRATA 2 cat("ocurrences of <aa> in <your.string>: ", length(grep("aa", x2)), sep="", fill=TRUE) Fran
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
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
2017 Jul 07
2
Factor vs character in a data.frame vs vector
This is not? serious problem but I just wonder if someone can explain what is happening. The same command within a dataframe is giving me a factor and as a plain vector is giving me a character.? It's probably something simple that I have read and forgotten but I thought I'd ask. Thanks #================================================ dat1 <- data.frame(aa = letters[1:10]) str(dat1)
2017 Jul 07
0
Factor vs character in a data.frame vs vector
> On Jul 7, 2017, at 6:03 AM, John Kane via R-help <r-help at r-project.org> wrote: > > This is not serious problem but I just wonder if someone can explain what is happening. > The same command within a dataframe is giving me a factor and as a plain vector is giving me a character. It's probably something simple that I have read and forgotten but I thought I'd ask.
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]]
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 >
2018 Feb 27
3
Aggregate over multiple and unequal column length data frames
Thank you Pikal and Bert. My apology for posting parts of my previous email in HTML. Bert's suggestion will work but i am wondering if there is an alternative especially in the case where the data frames are big; that is the difference in lengths among them is large. Below is a list of sample date frames and desired result. EK
2017 Jul 08
2
Factor vs character in a data.frame vs vector
Thanks Marc. It never occurred to me that I would need a ""stringsAsFactors" expression in a data.frame.? I could have sworn I never did before when mocking up some data but clearly I was wrong or there has been a change in R v. 3.4.1 which seems unlikely. On Friday, July 7, 2017, 10:37:29 AM EDT, Marc Schwartz <marc_schwartz at me.com> wrote: > On Jul 7, 2017, at 6:03