Re: [R] Counting confidence intervals

2013-03-18 Thread Jorge I Velez
Hi Jim, Try either of the following (untested): sum( x[1, ] 12 x[2, ] 12) sum(apply(x, 2, function(x) x[1] 12 x[2] 12)) where x is your 2x1000 matrix. HTH, Jorge.- On Tue, Mar 19, 2013 at 12:03 AM, Jim Silverton wrote: Hi, I have a 2 x 1 matrix of confidence intervals. The

Re: [R] Counting confidence intervals

2013-03-18 Thread Jeff Newmiller
sum(M[1]12 12=M[2]) untested, no data --- Jeff NewmillerThe . . Go Live... DCN:jdnew...@dcn.davis.ca.usBasics: ##.#. ##.#. Live Go...

Re: [R] Counting confidence intervals

2013-03-18 Thread arun
,]    7   29 #[2,]   11   30 #[3,]    3   30 #[4,]    2   26 #[5,]   10   22 #[6,]    6   22 A.K. From: Jim Silverton jim.silver...@gmail.com To: r-help@r-project.org Sent: Monday, March 18, 2013 9:03 AM Subject: Re: [R] Counting confidence intervals Hi, I

Re: [R] Counting confidence intervals

2013-03-18 Thread Jim Silverton
Thanks. Jeff On Mon, Mar 18, 2013 at 9:30 AM, Jeff Newmiller jdnew...@dcn.davis.ca.uswrote: sum(M[1]12 12=M[2]) untested, no data --- Jeff NewmillerThe . . Go Live...

Re: [R] Counting confidence intervals

2013-03-18 Thread Jorge I Velez
29 #[2,] 11 30 #[3,]3 30 #[4,]2 26 #[5,] 10 22 #[6,]6 22 A.K. From: Jim Silverton To: r-help@r-project.org Sent: Monday, March 18, 2013 9:03 AM Subject: Re: [R] Counting confidence intervals Hi, I have a 2 x 1

Re: [R] Counting confidence intervals

2013-03-18 Thread arun
   0.502  res1 #[1] 80070 A.K. From: Jim Silverton jim.silver...@gmail.com To: arun smartpink...@yahoo.com Sent: Monday, March 18, 2013 10:08 AM Subject: Re: [R] Counting confidence intervals thanks arun!! On Mon, Mar 18, 2013 at 10:06 AM, arun smartpink

Re: [R] Counting confidence intervals

2013-03-18 Thread Jorge I Velez
Silverton jim.silver...@gmail.com To: arun smartpink...@yahoo.com Sent: Monday, March 18, 2013 10:08 AM Subject: Re: [R] Counting confidence intervals thanks arun!! On Mon, Mar 18, 2013 at 10:06 AM, arun smartpink...@yahoo.com wrote: Hi, Try this: set.seed(25) mat1- matrix(cbind

Re: [R] Counting confidence intervals

2013-03-18 Thread S Ellison
I want to cont how many times a number say 12 lies in the interval. Can anyone assist? Has anyone else ever wished there was a moderately general 'inside' or 'within' function in R for this problem? For example, something that behaves more or less like within - function(x, interval=NULL,

Re: [R] Counting confidence intervals

2013-03-18 Thread Rui Barradas
Hello, There _is_ a function ?within. Maybe your function can be named 'between' Rui Barradas Em 18-03-2013 16:16, S Ellison escreveu: I want to cont how many times a number say 12 lies in the interval. Can anyone assist? Has anyone else ever wished there was a moderately general 'inside'

[R] Counting the numbers of items in vector according to their size

2012-11-09 Thread rlcorp
I am new to R and learned to program 10 years ago in C++. I am currently working a project that looks at the distribution of randomly generated beta values. I take 20 random beta values find their sum, repeat 10 times. Here is my code that it took me 4 hours to get s=numeric(length=10)

Re: [R] Counting the numbers of items in vector according to their size

2012-11-09 Thread Rui Barradas
Hello, As you know R better it will take you less and less time to get it right, and almost surely less and less lines of code to do the same thing. Here's a one liner: set.seed(1510) s=numeric(length=10) for(i in 1:10){ pop=(rbeta(n=20,shape1=2,shape2=1)) s[i]=sum(pop) }

[R] Counting duplicates in a dataframe

2012-10-22 Thread asafwe
Hello, I am looking at a two-way ANOVA dataset, and would like to count the rows in the dataframe with the same level of the first factor (Gender) and the second factor (Dosage). In other words, I am interested in the number of observations per each cell in a (not necessarily balanced) two-way

Re: [R] Counting duplicates in a dataframe

2012-10-22 Thread PIKAL Petr
Hi -Original Message- From: r-help-boun...@r-project.org [mailto:r-help-bounces@r- project.org] On Behalf Of asafwe Sent: Monday, October 22, 2012 4:02 AM To: r-help@r-project.org Subject: [R] Counting duplicates in a dataframe Hello, I am looking at a two-way ANOVA dataset

Re: [R] Counting duplicates in a dataframe

2012-10-22 Thread arun
as...@wharton.upenn.edu To: r-help@r-project.org Cc: Sent: Sunday, October 21, 2012 10:02 PM Subject: [R] Counting duplicates in a dataframe Hello, I am looking at a two-way ANOVA dataset, and would like to count the rows in the dataframe with the same level of the first factor (Gender) and the second factor

Re: [R] Counting duplicates in a dataframe

2012-10-22 Thread arun
To: r-help@r-project.org Cc: Sent: Sunday, October 21, 2012 10:02 PM Subject: [R] Counting duplicates in a dataframe Hello, I am looking at a two-way ANOVA dataset, and would like to count the rows in the dataframe with the same level of the first factor (Gender) and the second factor (Dosage

Re: [R] Counting duplicates in a dataframe

2012-10-22 Thread David Winsemius
is that different than: table(dat1$Gender, dat1$Dosage) -- David. A.K. - Original Message - From: asafwe as...@wharton.upenn.edu To: r-help@r-project.org Cc: Sent: Sunday, October 21, 2012 10:02 PM Subject: [R] Counting duplicates in a dataframe Hello, I am looking

Re: [R] Counting duplicates in a dataframe

2012-10-22 Thread asafwe
Thank you all; David -- this is, in fact, exactly what I need! Asaf -- View this message in context: http://r.789695.n4.nabble.com/Counting-duplicates-in-a-dataframe-tp4646954p4647075.html Sent from the R help mailing list archive at Nabble.com. __

Re: [R] Counting duplicates in a dataframe

2012-10-22 Thread arun
Cc: asafwe as...@wharton.upenn.edu; R help r-help@r-project.org Sent: Monday, October 22, 2012 5:26 PM Subject: Re: [R] Counting duplicates in a dataframe On Oct 22, 2012, at 7:48 AM, arun wrote: HI, Another way: dat1-read.table(text= Observation Gender Dosage Alertness 1            1      m

[R] Counting frequency within each range

2012-07-26 Thread Chintanu
Hi, This is a simple problem, but for the life of me I cannot find the answer. How to determine frequency within given ranges ? I know that table() gives frequency, for example a - table(numbers) a numbers 4 5 23 34 43 54 56 65 67 324 435 453 456 567 657 2 1 2 2 1 1

Re: [R] Counting frequency within each range

2012-07-26 Thread R. Michael Weylandt michael.weyla...@gmail.com
Combine cut() and table() Michael On Jul 26, 2012, at 8:22 PM, Chintanu chint...@gmail.com wrote: Hi, This is a simple problem, but for the life of me I cannot find the answer. How to determine frequency within given ranges ? I know that table() gives frequency, for example a -

Re: [R] Counting frequency within each range

2012-07-26 Thread David L Carlson
-bounces@r- project.org] On Behalf Of Chintanu Sent: Thursday, July 26, 2012 8:23 PM To: r-help@r-project.org Subject: [R] Counting frequency within each range Hi, This is a simple problem, but for the life of me I cannot find the answer. How to determine frequency within given ranges

Re: [R] Counting frequency within each range

2012-07-26 Thread arun
. - Original Message - From: Chintanu chint...@gmail.com To: r-help@r-project.org Cc: Sent: Thursday, July 26, 2012 9:22 PM Subject: [R] Counting frequency within each range Hi, This is a simple problem, but for the life of me I cannot find the answer. How to determine frequency within given

Re: [R] Counting frequency within each range

2012-07-26 Thread Chintanu
: Thursday, July 26, 2012 9:22 PM Subject: [R] Counting frequency within each range Hi, This is a simple problem, but for the life of me I cannot find the answer. How to determine frequency within given ranges ? I know that table() gives frequency, for example a - table(numbers) a numbers 4

[R] counting the data in different groups for each row

2012-05-31 Thread ramakanth reddy
Dear R, I have data like this I I D I D D D D D I D I D I D I D I D D D I D D I I I I I I I I D I D I D I I I D I I I D I D I D I D I 0 0 I I I I I I I I I D I D I D I D I I I D I I I D I D I D I D I I I D I I I I I Now for each row i want to make count in groups 2 in each group for all

Re: [R] Counting cases within present ranges

2012-05-04 Thread Rui Barradas
Hello, I have a vector wherein the cases are either uniform or mixed-strings (so AAA vs ABABABABA). Different parts of the vector apply to different users, so [1:29] is one guy, [30:50] is another, and [51:70] is another. There are about 100,000 users, and I have an object that

[R] Counting

2012-02-21 Thread Valerie Moore
Hi, Is there a short way of doing this? I have the following table in R: 12.0        0.5       0.6      0.2  0  0 12.3    1.2   0.8   0    0      0 13.1 0 1.2       0    0      0 10.1         0    0   0   1.3 0 10.2    1.3 

Re: [R] Counting

2012-02-21 Thread Sarah Goslee
There's almost always a better way than a loop (although sometimes it isn't worth the effort to figure it out). This time it's straightforward: apply(c5[, 2:4], 1, function(x)sum(x 0)) [1] 3 2 1 0 3 Sarah On Tue, Feb 21, 2012 at 6:04 PM, Valerie Moore vmoore2...@yahoo.com wrote: Hi, Is

Re: [R] Counting

2012-02-21 Thread Jorge I Velez
Valerie, In additio to Sarah's suggestion, you could also use rowSums(c5[, 2:4] 0) HTH, Jorge.- On Tue, Feb 21, 2012 at 7:45 PM, Sarah Goslee wrote: There's almost always a better way than a loop (although sometimes it isn't worth the effort to figure it out). This time it's

[R] counting characters starting point

2012-02-20 Thread Juliet Ndukum
I have three character strings represented below as seq1, seq2, and seq3. Each string has a reference character different from the other. Thus, for seq1, the reference character is U, seq2, S (3rd S from left where A is leftmost character) and for seq3 Y. seq1 = PQRTUWXYseq2 = AQSDSSDHRSseq3 =

Re: [R] counting characters starting point

2012-02-20 Thread Rui Barradas
Hello, Try seq1 - 'PQRTUWXY' seq2 - 'AQSDSSDHRS' seq3 - 'EEZYJKFFBHO' ref1 - 'U' ref2 - 'S' ref3 - 'Y' fun - function(seq, chr){ f - function(x, seq, chr){ pos - regexpr(x, seq) if(pos 0) 99 else

Re: [R] Counting value changes

2012-02-19 Thread peter dalgaard
On Feb 19, 2012, at 04:25 , jim holtman wrote: For completeness, if you want to count all possible four transitions: x - c(0,1,0,1,0,0,0,1,1,1,0,0,0,1) # lets keep count of the 4 different transitions that can happen indx - cbind(head(x, -1), tail(x, -1)) %*% c(2, 1) table(indx) # 0=0-0,

Re: [R] Counting value changes

2012-02-18 Thread Pete Brecknock
maris478 wrote Good afternoon, I've encountered a little bit of a problem, would appreciate any help here. I made a small vector consisting of ones and zeros. Something like this x - c(0,1,0,1,0,0,1,0), and all I need is to count how many times 0 becomes 1. Tried various, of what I

Re: [R] Counting value changes

2012-02-18 Thread Petr Savicky
On Sat, Feb 18, 2012 at 11:51:39AM -0800, Pete Brecknock wrote: maris478 wrote Good afternoon, I've encountered a little bit of a problem, would appreciate any help here. I made a small vector consisting of ones and zeros. Something like this x - c(0,1,0,1,0,0,1,0), and all I

Re: [R] Counting value changes

2012-02-18 Thread William Dunlap
tibco.com -Original Message- From: r-help-boun...@r-project.org [mailto:r-help-boun...@r-project.org] On Behalf Of Pete Brecknock Sent: Saturday, February 18, 2012 11:52 AM To: r-help@r-project.org Subject: Re: [R] Counting value changes maris478 wrote Good afternoon, I've

Re: [R] Counting value changes

2012-02-18 Thread jim holtman
try this: x - c(0,1,0,1,0,0,0,0) sum(diff(x) == 1) [1] 2 On Sat, Feb 18, 2012 at 2:51 PM, Pete Brecknock peter.breckn...@bp.com wrote: maris478 wrote Good afternoon, I've encountered a little bit of a problem, would appreciate any help here. I made a small vector consisting of ones

[R] Counting value changes

2012-02-18 Thread maris478
Good afternoon, I've encountered a little bit of a problem, would appreciate any help here. I made a small vector consisting of ones and zeros. Something like this x - c(0,1,0,1,0,0,1,0), and all I need is to count how many times 0 becomes 1. Tried various, of what I thought, methods with

Re: [R] Counting value changes

2012-02-18 Thread Sarah Goslee
Just for clarity, I changed your x a bit - in your version, the 0-1 and 1-0 change occurred the same number of times. If all your values are 0 and 1, this will work: x - c(0,1,0,1,0,0,0,1,1,1) table(diff(x)) -1 0 1 2 4 3 sum(diff(x) == 1) [1] 3 If other values can occur, it would need

Re: [R] Counting value changes

2012-02-18 Thread jim holtman
For completeness, if you want to count all possible four transitions: x - c(0,1,0,1,0,0,0,1,1,1,0,0,0,1) # lets keep count of the 4 different transitions that can happen indx - cbind(head(x, -1), tail(x, -1)) %*% c(2, 1) table(indx) # 0=0-0, 1=0-1, 2=1-0, 3=1-1 indx 0 1 2 3 4 4 3 2 On Sat,

Re: [R] Counting the loop-round of a for-loop

2012-02-13 Thread 538280
Consider using sapply instead of a for loop, if the code in the sapply call returns a vector, and every vector is the same length, then sapply will automatically form it into a matrix for you. On Sun, Feb 12, 2012 at 12:30 PM, jolo999 jonas.lor...@ebs.de wrote: It seems to work. Simple and

Re: [R] Counting occurences of variables in a dataframe

2012-02-12 Thread Kai Mx
Amazing. Thanks everybody for the help. I have about 12,000 rows of data with up to 50 reccurrences, but it seems to work like a charm. Best, Kai On Sun, Feb 12, 2012 at 8:11 AM, Petr Savicky savi...@cs.cas.cz wrote: On Sat, Feb 11, 2012 at 04:05:25PM -0500, David Winsemius wrote: On Feb

[R] Counting the loop-round of a for-loop

2012-02-12 Thread jolo999
Dear all, i have daily stock prices for more than 10 years and want to compute annual volatilities for certain dates during this period. Since i have found no easy way to work with time data, the data presents itself in the structure TIme Index - Stock Price 1 - 15,6 2 - 17 ... ... 2010 - 28

Re: [R] Counting the loop-round of a for-loop

2012-02-12 Thread Ista Zahn
Hi, You can initialize a counter and update it in the loop. An silly example (unrelated to yours because it was not reproducible) of this technique is: x - matrix( , ncol = 2, nrow = 26) n - 0 for(i in letters) { n - n+1 x[n,] - c(i, n) } Best, Ista On Sunday, February 12, 2012

Re: [R] Counting the loop-round of a for-loop

2012-02-12 Thread jolo999
It seems to work. Simple and effective! Thanks! -- View this message in context: http://r.789695.n4.nabble.com/Counting-the-loop-round-of-a-for-loop-tp4381319p4381780.html Sent from the R help mailing list archive at Nabble.com. __

[R] Counting occurences of variables in a dataframe

2012-02-11 Thread Kai Mx
Hi everybody, I have a large dataframe similar to this one: knames -c('ab', 'aa', 'ac', 'ad', 'ab', 'ac', 'aa', 'ad','ae', 'af') kdate - as.Date( c('20111001', '2002', '20101001', '20100315', '20101201', '20110105', '20101001', '20110504', '20110603', '20110201'), format=%Y%m%d) kdata -

Re: [R] Counting occurences of variables in a dataframe

2012-02-11 Thread Tal Galili
Hello Kai This looks like a fun question. Here is my solution, I'd be curious to see solutions by other people here. It can also be tweaked in various ways, and easily put into a function (actually, if you do it - please put it back online :) ) The only thing that might require some work is the

Re: [R] Counting occurences of variables in a dataframe

2012-02-11 Thread Petr Savicky
On Sat, Feb 11, 2012 at 07:17:54PM +0100, Kai Mx wrote: Hi everybody, I have a large dataframe similar to this one: knames -c('ab', 'aa', 'ac', 'ad', 'ab', 'ac', 'aa', 'ad','ae', 'af') kdate - as.Date( c('20111001', '2002', '20101001', '20100315', '20101201', '20110105', '20101001',

Re: [R] Counting occurences of variables in a dataframe

2012-02-11 Thread David Winsemius
On Feb 11, 2012, at 1:17 PM, Kai Mx wrote: Hi everybody, I have a large dataframe similar to this one: knames -c('ab', 'aa', 'ac', 'ad', 'ab', 'ac', 'aa', 'ad','ae', 'af') kdate - as.Date( c('20111001', '2002', '20101001', '20100315', '20101201', '20110105', '20101001', '20110504',

Re: [R] Counting occurences of variables in a dataframe

2012-02-11 Thread Petr Savicky
On Sat, Feb 11, 2012 at 04:05:25PM -0500, David Winsemius wrote: On Feb 11, 2012, at 1:17 PM, Kai Mx wrote: Hi everybody, I have a large dataframe similar to this one: knames -c('ab', 'aa', 'ac', 'ad', 'ab', 'ac', 'aa', 'ad','ae', 'af') kdate - as.Date( c('20111001', '2002',

Re: [R] Counting the occurences of a charater within a string

2011-12-03 Thread Hadley Wickham
On Thu, Dec 1, 2011 at 10:32 AM, Douglas Esneault douglas.esnea...@mecglobal.com wrote: I am new to R but am experienced SAS user and I was hoping to get some help on counting the occurrences of a character within a string at a row level. My dataframe, x,  is structured as below: Col1

[R] Counting the occurences of a charater within a string

2011-12-01 Thread Douglas Esneault
I am new to R but am experienced SAS user and I was hoping to get some help on counting the occurrences of a character within a string at a row level. My dataframe, x, is structured as below: Col1 abc/def ghi/jkl/mno I found this code on the board but it counts all occurrences of / in the

Re: [R] Counting the occurences of a charater within a string

2011-12-01 Thread Bert Gunter
## It's not a data frame -- it's just a vector. x [1] abc/def ghi/jkl/mno gsub([^/],,x) [1] / // nchar(gsub([^/],,x)) [1] 1 2 ?gsub ?nchar -- Bert On Thu, Dec 1, 2011 at 8:32 AM, Douglas Esneault douglas.esnea...@mecglobal.com wrote: I am new to R but am experienced SAS user and I

Re: [R] Counting the occurences of a charater within a string

2011-12-01 Thread Florent D.
I used within and vapply: x - data.frame(Col1 = c(abc/def, ghi/jkl/mno), stringsAsFactors = FALSE) count.slashes - function(string)sum(unlist(strsplit(string, NULL)) == /)within(x, Col2 - vapply(Col1, count.slashes, 1))          Col1 Col21     abc/def    12 ghi/jkl/mno    2 On Thu, Dec 1, 2011

Re: [R] Counting the occurences of a charater within a string

2011-12-01 Thread Florent D.
Resending my code, not sure why the linebreaks got eaten: x - data.frame(Col1 = c(abc/def, ghi/jkl/mno), stringsAsFactors = FALSE) count.slashes - function(string)sum(unlist(strsplit(string, NULL)) == /) within(x, Col2 - vapply(Col1, count.slashes, 1)) Col1 Col2 1 abc/def1 2

Re: [R] Counting the occurences of a charater within a string

2011-12-01 Thread Bert Gunter
strsplit is certainly an alternative, but your approach is unnecessarily complicated and inefficient. Do this, instead: sapply(strsplit(x,/),length)-1 Cheers, Bert On Thu, Dec 1, 2011 at 7:44 PM, Florent D. flo...@gmail.com wrote: Resending my code, not sure why the linebreaks got eaten: x -

Re: [R] Counting the occurences of a charater within a string

2011-12-01 Thread Florent D.
Inefficient, maybe, but what you suggest does not work if a string starts or ends with a slash. On Thu, Dec 1, 2011 at 11:11 PM, Bert Gunter gunter.ber...@gene.com wrote: strsplit is certainly an alternative, but your approach is unnecessarily complicated and inefficient. Do this, instead:

Re: [R] Counting the occurences of a charater within a string

2011-12-01 Thread David Winsemius
On Dec 1, 2011, at 11:11 PM, Bert Gunter wrote: strsplit is certainly an alternative, but your approach is unnecessarily complicated and inefficient. Do this, instead: sapply(strsplit(x,/),length)-1 Definitely more compact that the regex alternates I came up with, but one of these still

[R] counting values with some conditions in a simulation

2011-11-25 Thread Sl K
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

Re: [R] counting values with some conditions in a simulation

2011-11-25 Thread jim holtman
How are you computing the sum? Does FAQ 7.31 apply? Showing at least a sample of your code would help. On Friday, November 25, 2011, Sl K s.ka...@gmail.com wrote: 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

Re: [R] counting values with some conditions in a simulation

2011-11-25 Thread Jeff Newmiller
You need to read the posting guide. Provide a reproducible code sample, simplified, with self-contained data. You might find the ave function useful if you are working with vectorized simulations. --- Jeff Newmiller

Re: [R] counting values with some conditions in a simulation

2011-11-25 Thread Jeff Newmiller
A) you need to reply-all to keep the discussion on the mailing list. B) you need to post in plain text. C) this has the arbitrary smell of homework. This is not a homework help line. D) You are overwriting your accumulation variable sumt after each test. Since you are not handling this

[R] counting columns that match criteria

2011-11-10 Thread JL Villanueva
Hi, I am a little new in R but I'm finding it extremely useful :) Here's my tiny question: I've got a table with a lot of columns. What I am interested now is to evaluate how many of 4 columns have a value greater than 1. I think it can be done with subset() but it will take a very long

Re: [R] counting columns that match criteria

2011-11-10 Thread jim holtman
try this: x Col1 Col2 Col3 Col4 11111 22111 34141 43333 apply(x, 1, function(a) sum(a 1)) [1] 0 1 2 4 x$count - apply(x, 1, function(a) sum(a 1)) x Col1 Col2 Col3 Col4 count 11111 0 22111

Re: [R] counting columns that match criteria

2011-11-10 Thread Jorge I Velez
Hi JL, How about the following? rowSums(d 1) # d is your data Best, Jorge.- On Thu, Nov 10, 2011 at 10:24 AM, JL Villanueva wrote: Hi, I am a little new in R but I'm finding it extremely useful :) Here's my tiny question: I've got a table with a lot of columns. What I am interested

Re: [R] counting columns that match criteria

2011-11-10 Thread Dennis Murphy
Hi: Here's a toy example: # Default var names are V1-V20: u - as.data.frame(matrix(rpois(100, 3), ncol = 20)) u - transform(u, ngt1 = apply(u[, c('V1', 'V4', 'V9', 'V15')], 1, function(x) sum(x 1)) ) u HTH, Dennis On Thu, Nov 10, 2011 at 7:24 AM, JL Villanueva jlpost...@gmail.com wrote:

[R] Counting number of common elements between the rows of two different matrices

2011-11-04 Thread Parodi, Pietro
Hello I'm trying to solve this problem without using a for loop but I have so far failed to find a solution. I have two matrices of K columns each, e.g. (K=5), and with numbers of row N_A and N_B respectively A = (1 5 3 8 15; 2 7 20 11 13; 12 19 20 21 43) B = (2 6

Re: [R] Counting number of common elements between the rows of two different matrices

2011-11-04 Thread jim holtman
Try this: # create dummy data a - matrix(sample(20, 50, TRUE), ncol = 5) b - matrix(sample(20, 50, TRUE), ncol = 5) # create combinations to test x - expand.grid(seq(nrow(a)), seq(nrow(b))) # test result - mapply(function(m1, m2) any(a[m1, ] %in% b[m2, ]) , x[, 1] , x[, 2]

Re: [R] Counting number of common elements between the rows of two different matrices

2011-11-04 Thread Parodi, Pietro
Jim I tried that and it works. Thank you very much for your help! Regards Pietro -Original Message- From: jim holtman [mailto:jholt...@gmail.com] Sent: 04 November 2011 13:38 To: Parodi, Pietro Cc: r-help@r-project.org Subject: Re: [R] Counting number of common elements between

[R] Counting entries to create a new table

2011-11-01 Thread Empty Empty
Hi, I am an R novice and I am trying to do something that it seems should be fairly simple, but I can't quite figure it out and I must not be using the right words when I search for answers. I have a dataset with a number of individuals and observations for each day (7 possible codes plus

Re: [R] Counting entries to create a new table

2011-11-01 Thread Dennis Murphy
Hi: After cleaning up your data, here's one way using the plyr and reshape packages: d - read.csv(textConnection( Individual, A, B, C, D Day1, 1,1,1,1 Day2, 1,3,4,2 Day3, 3,,6,4), header = TRUE) closeAllConnections() d library('plyr') library('reshape') # Stack the variables dm - melt(d, id =

Re: [R] Counting the number of marginals

2011-10-26 Thread Jim Silverton
Dear all, I have two matrices lets call them A and B. Each of which is a 100 x 3 matrix. What I do is take the corresponding row from each matrix and form 100 2 x 3 tables. If we call the column sums for each 2 x 3 n1, n2 and n3, I would like to compute the following probability: Basically the

Re: [R] Counting the number of integers at one swoop

2011-10-14 Thread Carl Witthoft
You guys are working too hard. Rgames y - c(0,1,1,3,3,3,5,5,6) Rgames rle(sort(y)) Run Length Encoding lengths: int [1:5] 1 2 3 2 1 values : num [1:5] 0 1 3 5 6 -- - Sent from my Cray XK6 __ R-help@r-project.org mailing list

[R] Counting the number of integers at one swoop

2011-10-13 Thread Kathie
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

Re: [R] Counting the number of integers at one swoop

2011-10-13 Thread Daniel Malter
I think there must be an easier solution, but this works: y - c(0,1,1,3,3,3,5,5,6) x-matrix(0:6,ncol=1) apply(x,1,function(x){length(y[y==x])}) HTH, Daniel Kathie wrote: Dear R users, I'd like to count the number of integers in a vector y. Here is an example. y -

Re: [R] Counting the number of integers at one swoop

2011-10-13 Thread R. Michael Weylandt
Table() or more generally tabulate() Though, as a general warning, you may need to be a little careful depending on the source of your data. Once you get into floating point business, the definition of an integer becomes a little less cut and dry. If your data are all integer, the data type, then

Re: [R] Counting the number of integers at one swoop

2011-10-13 Thread R. Michael Weylandt
Slight addendum, tabulate() ignores zeros so you'll need to do tabulate(y+1). Table will handle zeros but won't look for values that never appear (in your example 2 4). Michael On Thu, Oct 13, 2011 at 8:51 AM, R. Michael Weylandt michael.weyla...@gmail.com wrote: Table() or more generally

Re: [R] Counting the number of integers at one swoop

2011-10-13 Thread jim holtman
try this: y - c(0,1,1,3,3,3,5,5,6) x - tabulate(y+1) names(x) - seq(from = 0, by = 1, length = length(x)) x 0 1 2 3 4 5 6 1 2 0 3 0 2 1 On Thu, Oct 13, 2011 at 7:33 AM, Kathie kathryn.lord2...@gmail.com wrote: Dear R users, I'd like to count the number of integers in a vector y. Here

Re: [R] Counting the number of integers at one swoop

2011-10-13 Thread Jean V Adams
Kathie wrote on 10/13/2011 06:33:59 AM: 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

[R] Counting similar rows

2011-09-27 Thread Metronome123
Startsituation: structure(c(1, 1, 0, 1, 0, 1, 0, 0, 1, 0, 1, 1, 0, 0, 1, 0, 1, 0, 1, 1), .Dim = 4:5, .Dimnames = structure(list(subject = c(s1, s2, s3, s4), class = c(c1, c2, c3, c4, c5)), .Names = c(subject, class)), class = c(xtabs, table), call = xtabs(formula = ~subject + class, data

Re: [R] Counting similar rows

2011-09-27 Thread Jean V Adams
Metronome123 wrote on 09/27/2011 07:24:50 AM: Startsituation: structure(c(1, 1, 0, 1, 0, 1, 0, 0, 1, 0, 1, 1, 0, 0, 1, 0, 1, 0, 1, 1), .Dim = 4:5, .Dimnames = structure(list(subject = c(s1, s2, s3, s4), class = c(c1, c2, c3, c4, c5)), .Names = c(subject, class)), class = c(xtabs,

Re: [R] Counting similar rows

2011-09-27 Thread Metronome123
Jean: Thanks! Works great! Lars Op 27 sep. 2011 (w39), om 17:22 heeft Jean V Adams [via R] het volgende geschreven: df - as.data.frame(unclass(xt)) dfu - unique(df) class_cnt - apply(dfu, 1, sum) subject_cnt - tabulate(match(apply(df, 1, paste, collapse=-), apply(dfu, 1, paste,

Re: [R] counting the duplicates in an object of list

2011-09-07 Thread zhenjiang xu
, August 31, 2011 9:25 AM To: r-help Subject: [R] counting the duplicates in an object of list Hi all, I have a list x: x=list(a=c('1','2'),b=c('2','3'),c=c('1','2'),d=c('2','3')) I can get the unique elements with unique(), but how can I get the number of duplicates for each

Re: [R] counting the duplicates in an object of list

2011-09-07 Thread zhenjiang xu
with the data. Bill Dunlap Spotfire, TIBCO Software wdunlap tibco.com -Original Message- From: r-help-boun...@r-project.org [mailto:r-help-boun...@r-project.org] On Behalf Of zhenjiang xu Sent: Wednesday, August 31, 2011 9:25 AM To: r-help Subject: [R] counting

Re: [R] counting the duplicates in an object of list

2011-09-07 Thread William Dunlap
Dunlap Cc: r-help Subject: Re: [R] counting the duplicates in an object of list Now I nailed down the problem, but I am still confused why match() takes the 1st two components and the last two the same. match(a,a) [1] 1 2 3 1 2 a [[1]] [1] YARCTy1-1 YAR009C YBLWTy1-1 YBL005W-B YBRWTy1-2

Re: [R] counting the duplicates in an object of list

2011-09-07 Thread zhenjiang xu
:* Wednesday, September 07, 2011 7:25 PM *To:* William Dunlap *Cc:* r-help *Subject:* Re: [R] counting the duplicates in an object of list ** ** Now I nailed down the problem, but I am still confused why match() takes the 1st two components and the last two the same. ** ** match

Re: [R] counting the duplicates in an object of list

2011-09-07 Thread William Dunlap
Spotfire, TIBCO Software wdunlap tibco.com From: zhenjiang xu [mailto:zhenjiang...@gmail.com] Sent: Wednesday, September 07, 2011 8:04 PM To: William Dunlap Cc: r-help Subject: Re: [R] counting the duplicates in an object of list I tried converting the elements to strings before, but due to the large

Re: [R] counting the duplicates in an object of list

2011-09-07 Thread zhenjiang xu
...@gmail.com] *Sent:* Wednesday, September 07, 2011 8:04 PM *To:* William Dunlap *Cc:* r-help *Subject:* Re: [R] counting the duplicates in an object of list ** ** I tried converting the elements to strings before, but due to the large data size it took forever to finish with paste

[R] counting the duplicates in an object of list

2011-08-31 Thread zhenjiang xu
Hi all, I have a list x:   x=list(a=c('1','2'),b=c('2','3'),c=c('1','2'),d=c('2','3')) I can get the unique elements with unique(), but how can I get the number of duplicates for each unique elements? unique(x) [[1]] [1] 1 2 [[2]] [1] 2 3 Thanks -- Best, Zhenjiang

Re: [R] counting the duplicates in an object of list

2011-08-31 Thread William Dunlap
Of zhenjiang xu Sent: Wednesday, August 31, 2011 9:25 AM To: r-help Subject: [R] counting the duplicates in an object of list Hi all, I have a list x:   x=list(a=c('1','2'),b=c('2','3'),c=c('1','2'),d=c('2','3')) I can get the unique elements with unique(), but how can I get the number

[R] Counting non-missing values XXXX

2011-08-27 Thread Dan Abner
Hello everyone, What is the most elegant and efficient way to count non-missing values of a vector? Thanks! Dan [[alternative HTML version deleted]] __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do

Re: [R] Counting non-missing values XXXX

2011-08-27 Thread R. Michael Weylandt michael.weyla...@gmail.com
sum(!is.na(x)) Michael On Aug 27, 2011, at 4:39 PM, Dan Abner dan.abne...@gmail.com wrote: Hello everyone, What is the most elegant and efficient way to count non-missing values of a vector? Thanks! Dan [[alternative HTML version deleted]]

Re: [R] Counting Elements Conditionally

2011-08-23 Thread Jean V Adams
) ? Jean Edward Patzelt patze...@umn.edu wrote on 08/22/2011 03:58:38 PM: [image removed] Re: [R] Counting Elements Conditionally Edward Patzelt to: Jean V Adams 08/22/2011 03:58 PM Cc: r-help Awesome, this is close, couple changes

[R] Counting Elements Conditionally

2011-08-22 Thread Edward Patzelt
R - I have 3 variables with data below. Variable Rev is a vector that changes from 1 to 2, 2 to 3, etc Variable FF is a binary variable with 1's and 0's. Variable bin is a different binary variable with 1's and 0's. I want to calculate the number of elements: 1. Starting with the first

Re: [R] Counting Elements Conditionally

2011-08-22 Thread Jean V Adams
[R] Counting Elements Conditionally Edward Patzelt to: r-help 08/22/2011 02:33 PM R - I have 3 variables with data below. Variable Rev is a vector that changes from 1 to 2, 2 to 3, etc Variable FF is a binary variable with 1's and 0's. Variable bin is a different binary

Re: [R] Counting Elements Conditionally

2011-08-22 Thread Jean V Adams
Re: [R] Counting Elements Conditionally Jean V Adams to: Edward Patzelt 08/22/2011 03:53 PM [R] Counting Elements Conditionally Edward Patzelt to: r-help 08/22/2011 02:33 PM R - I have 3 variables with data below. Variable Rev is a vector that changes from 1 to 2

Re: [R] Counting Elements Conditionally

2011-08-22 Thread Edward Patzelt
)), .Names = c(Rev, FF, bin), row.names = c(NA, -125L), class = data.frame) On Mon, Aug 22, 2011 at 3:57 PM, Jean V Adams jvad...@usgs.gov wrote: Re: [R] Counting Elements Conditionally Jean V Adams to: Edward Patzelt 08/22/2011 03:53 PM [R] Counting Elements Conditionally Edward

Re: [R] Counting Elements Conditionally

2011-08-22 Thread Edward Patzelt
= data.frame) On Mon, Aug 22, 2011 at 3:57 PM, Jean V Adams jvad...@usgs.gov wrote: Re: [R] Counting Elements Conditionally Jean V Adams to: Edward Patzelt 08/22/2011 03:53 PM [R] Counting Elements Conditionally Edward Patzelt to: r-help 08/22/2011 02:33 PM R

Re: [R] Counting Elements Conditionally

2011-08-22 Thread Jean V Adams
So, using the full data set, what should the result look like? c(NA, NA, NA, 3, NA,NA, NA, 2) ? Jean Edward Patzelt patze...@umn.edu wrote on 08/22/2011 03:58:38 PM: [image removed] Re: [R] Counting Elements Conditionally Edward Patzelt to: Jean V Adams 08/22/2011

Re: [R] Counting Elements Conditionally

2011-08-22 Thread Edward Patzelt
, NA, 3, NA,NA, NA, 2) ? Jean Edward Patzelt patze...@umn.edu wrote on 08/22/2011 03:58:38 PM: [image removed] Re: [R] Counting Elements Conditionally Edward Patzelt to: Jean V Adams 08/22/2011 03:58 PM Cc: r-help Awesome, this is close, couple

[R] Counting rows given conditional

2011-08-04 Thread a217
Hello, I have an input file that contains multiple columns, but the column I'm concerned about looks like: TR 5 0 4 1 0 2 0 To count all of the rows in the column I know how to do NROW(x$TR) which gives 7. However, I would also like to count only the number of rows with values =1 (i.e. not 0).

[R] counting columns that fulfill specific criteria

2011-06-24 Thread pguilha
Hi, I have a matrix (pwdiff in the example below) with ~48 rows and 780 columns. For each row, I want to get the percentage of columns that have an absolute value above a certain threshold t. I then want to allocate that percentage to matrix 'perc' in the corresponding row. Below is my

<    1   2   3   4   5   >