similar to: questions about counting numbers

Displaying 20 results from an estimated 20000 matches similar to: "questions about counting numbers"

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 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
2010 May 13
3
select subset based on another variable
Hi, dear R-helpers, I have a simple question regarding selecting subset of a variable based on another variable. Here is the example: xx=rnorm(10) id=sample(1:10, 10) temp=c(6, 1, 8, 2) Now, all I want is xx's that their id are 6, 1, 8, 2, instead of the position. Any suggestions ? Thank you all your help !! Carrie [[alternative HTML version deleted]]
2013 Apr 29
3
Counting number of consecutive occurrences per rows
Hi, I would appreciate if somebody could help me with following calculation. I have a dataframe, by 10 minutes time, for mostly one year data. This is small example: > dput(test) structure(list(jul = structure(c(14655, 14655, 14655, 14655, 14655, 14655, 14655, 14655, 14655, 14655, 14655, 14655, 14655, 14655, 14655, 14655), origin = structure(0, class = "Date")), time =
2010 Jun 26
4
integration of two normal density
Hello everyone, I have a question about integration of two density function Intuitively, I think the value after integration should be 1, but they are not. Am I missing something here ? > t=function(y){dnorm(y, mean=3)*dnorm(y/2, mean=1.5)} > integrate(t, -Inf, Inf) 0.3568248 with absolute error < 4.9e-06 Also, is there any R function or package could do multivariate integration ?
2010 Jun 23
3
integrate dmvtnorm
Hello, everyone, I have a question about integration of product of two densities. Here is the sample code; however the mean of first density is a function of another random variable, which is to be integrated. ## f=function(x) {dmvnorm(c(0.6, 0.8), mean=c(0.75, 0.75/x))*dnorm(x, mean=0.6, sd=0.15)} integrate(f, lower=-Inf, upper=Inf) ## error message Error in dmvnorm(c(0.6, 0.8), mean = c(0.75,
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
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.
2010 Jun 25
1
what "density" is plotting ?
Hi everyone, I am confused regarding the function "density". suppose that there is a sample x of 100 data points, and plot(density(x)) gives it's pdf ? or it's more like histogram only ? thanks for any answering Carrie [[alternative HTML version deleted]]
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
2011 May 08
1
questions about the output of "gee" and its summary
Dear R-helpers, I am using the package "gee" to run a marginal model. Here is the output. In my simulated data, both x and z are time-varying, so I include their interaction terms with time indicator (i.e. tind=0, if time 1, and 1 if time 2) The data is simulated, so the true parameter of z both at time 1 and time 2 is 5, which is very close from the model output for time 1, z =
2011 Feb 13
3
String manipulation
Please consider following string: MyString <- "ABCFR34564IJVEOJC3434" Here you see that, there are 4 groups in above string. 1st and 3rd groups are for english letters and 2nd and 4th for numeric. Given a string, how can I separate out those 4 groups? Thanks for your time [[alternative HTML version deleted]]
2013 Mar 13
3
Assign the number to each group of multiple rows
Dear R users, My data have repeating "beh" parameter : 1 or 2 - type of animal behavior in subsequent locations. I need to assign unique number to each sequence of locations. My data is: >data=data.frame(row=seq(1:10),beh=c(1,1,1,2,2,2,1,1,2,2)) >attach(data) >data row beh 1 1 1 2 2 1 3 3 1 4 4 2 5 5 2 6 6 2 7 7 1 8
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)
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
2011 Jun 01
5
Recode numbers
Dear all, I have two sets of numbers that look like a <- c(1, 2, 3, 3, 4, 4, 5, 6, 1, 2, 2, 3, 1, 2, 1, 2, 3, 3, 4, 5, 1, 2, 3, 4) b <- c(1, 5, 8, 9, 14, 20, 3, 10, 12, 6, 16, 7, 11, 13, 17, 18, 2, 4, 15, 19) I just want to use ?b? to encode ?a? so that ?a? looks like a1<- c(1, 5, 8, 8, 9, 9, 14, 20, 3, 10, 10, 12, 6, 16, 7, 11, 13, 13, 17, 18, 2, 4, 15, 19) Does anyone have a
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.
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()
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