Displaying 20 results from an estimated 10000 matches similar to: "Counting value changes"
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
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
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.
2009 Feb 04
7
counting entries in vector
Hi all,
I've a vector with entries, which are all of the same type, e.g. string:
k <- c("bb", "bb", "bb", "aa", "cc", "cc")
and want to create a second vector containing the number of each entry
in k in the same order as in k, i.e.
c(3, 1, 2)
or:
k <- c(5,5,5,5,2,2,4)
=> c(4,2,1)
thanks
2011 Nov 25
3
counting values with some conditions in a simulation
Dear R users,
I am running simulations (1000), and in my simulation I am looking at
specific sums. For example, if the sum is >=4 then count this, if say <3,
then don't count, if the sum=3, then generate a random number from uniform
distribution, if this number is say less than 0.5, then count this sum, if
greater than 0.5, then don't count. I am having trouble with introducing
this
2011 Feb 07
2
questions about counting numbers
Hello R-helpers,
I have a question about counting numbers.
Here is a simple example.
a=c(2, 3, 3,4)
> table(a)
a
2 3 4
1 2 1
so, I can to create another variables that has the corresponding counting
numbers.
In this case, I want to have:
b=c(1,2,2,1)
Is there any way coding for this ?
Thanks for helps!
Carrie--
[[alternative HTML version deleted]]
2006 Sep 30
1
counting a sequence of charactors or numbers
I have the following sequence of characters. These could be integers as
well. For this problem, only two values are valid.
S S S S S S W W W W W W W W S S S S S S S S W W W W W W W W S S S S S S
S S S S S S S W W W W W W W W W
I need to determine the count of the classes/groups in sequence. as
6,8,8,8,13,9 where the sum of these equal my total observations.
Any help is greatly appreciated.
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
2012 Mar 08
3
Calculating length of consecutive sequences within a vector
Hi all,
I have a nx1 logical array of zeros and ones and I want to calculate the individual lengths of all 1-consecutive sequences contained in it. Is there an easy quick way to do this in R? So, if I have a vector such as
111001101000011111110
I would like to get (1) 3, (2) 2, (3) 1, (4) 7
Any help would be appreciated! thanks!
Jorge
[[alternative HTML version deleted]]
2013 Mar 26
2
Feed rle() output to hist()
I want to make a histogram from the lengths vector which is part of the
output of rle. But I don't know how to access that vector so that I use it
as an argument of hist(). What argument must I use so that I use the
lengths vector as an input to hist()?
Example output is:
Run Length Encoding
lengths: int [1:4] 1 2 3 3
values : num [1:4] -1 1 -1 1
A printout of the function rle() may
2011 Oct 13
5
Counting the number of integers at one swoop
Dear R users,
I'd like to count the number of integers in a vector y.
Here is an example.
y <- c(0,1,1,3,3,3,5,5,6)
In fact, I know how to count the number of specific number in y.
sum(y==0) -> 1
sum(y==1) -> 2
sum(y==2) -> 0
sum(y==3) -> 3
sum(y==4) -> 0
sum(y==5) -> 2
sum(y==6) -> 1
However, in one computation I want to get this vector [1,2,0,3,0,2,1].
Thank
2011 Nov 02
3
how to count number of occurrences
Dear R users,
I have this data frame,
y samp
8 0.03060419 X
18 0.06120838 Y
10 0.23588374 X
3 0.32809965 X
1 0.36007100 X
7 0.36730571 X
20 0.47176748 Y
13 0.65619929 Y
11 0.72014201 Y
17 0.73461142 Y
6 0.76221313 X
2 0.77005691 X
4 0.92477243 X
9 0.93837591 X
5 0.98883581 X
16 1.52442626 Y
12 1.54011381 Y
14 1.84954487 Y
2005 Jun 24
1
r programming help II
Dear List,
Suppose we have a variable K.JUN defined as (with
1=wet, 0=dry):
K.JUN1984 = c(1, 0, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 1,
1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1)
K.JUN1985 = c(0, 1, 0, 1, 0, 0, 1, 0, 0, 1, 0, 0, 1,
1, 1, 1, 1, 0, 0, 1, 1, 0, 0, 1, 1, 1, 1, 1, 1, 1)
K.JUN1986 = c(0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1,
1, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 1, 1)
2008 May 27
4
help with simple function
I have a matrix of frequency counts from 0-160.
x<-as.matrix(c(0,1,0,0,1,0,0,0,1,0,0,0,0,1))
I would like to apply a function creating a new column (x[,2])containing
values equal to:
a) log(x[m,1]) if x[m,1] > 0; and
b) for all x[m,1]= 0, log(next x[m,1] > 0 / count of preceding zero values
+1)
for example, x[1,2] should equal log(x[2,1]/2) = log(1/2) = -0.6931472
whereas x[3,2] should
2008 Oct 24
1
count zero or one in a list
I have a list of {0,1} values, say
y<-c(0,0,0,1,1,0,0,1,0,1,1,1,1)
I want to compute the first few zeros and the last few ones. So the output I
expect is 3 and 4 for this vector. Is there a fast way to match the numbers
easily?
[[alternative HTML version deleted]]
2009 Jun 01
1
Generating a count variable
Dear All,
I am practicing data manipulation and I would like to generarte a count
variable. My data looks like this:
Country MID
1 NA
1 0
1 0
1 1
1 0
2 0
2 1
2 0
2 0
2 0
I would like to to generate a variable
2011 Jan 06
2
algorithm help
Hi, I am seeking help on designing an algorithm to identify the locations of
stretches of 1s in a vector of 0s and 1s. Below is an simple example:
> dat<-as.data.frame(cbind(a=c(F,F,T,T,T,T,F,F,T,T,F,T,T,T,T,F,F,F,F,T)
,b=c(4,12,13,16,18,20,28,30,34,46,47,49,61,73,77,84,87,90,95,97)))
> dat
a b
1 0 4
2 0 12
3 1 13
4 1 16
5 1 18
6 1 20
7 0 28
8 0 30
9 1 34
10 1 46
11 0
2018 May 11
3
add one variable to a data frame
Hi All,
I have a data frame dat1:
dat1 <-data.frame(N=seq(1, 12,1), B=c("29_log","29_log", "29_log", "27_cat", "27_cat",
"1_log", "1_log", "1_log", "1_log", "1_log",
2010 Nov 11
1
Count continuous dates
Dear List,
I have a series of dates and I am needing to know the greatest length of
continuous dates - i.e. the number of dates before a break in the series.? For
example, below there are three continuous series of dates with lengths 4, 6, and
8.? How can I count the number of continuous dates?? rle() will do it for
constant integers, but I can't figure a way to modify it for continuous
2008 Aug 02
2
lapply, sapply
Hello everybody,
I have problem with a lapply command, which rather proves that I don't
fully understand it.
I want to extract from a list that consists of dataframes, the length
of the first sequences from a given variable (its part of a simulation
exercises).
Below is code which does the job, but I think it should be possible to
make it more compact.
### Example Data
dat <-list()