Re: [R] Counting two factors at the same time

2010-01-22 Thread Henrique Dallazuanna
Try this; f - c( 'A', 'B', 'A', 'C', 'B', 'D', 'B') n - c('1', '2', '2', '3', '2', '2', '3') table(paste(f, n)) On Fri, Jan 22, 2010 at 4:51 PM, Fabrice DELENTE fdele...@mail.cpod.fr wrote: Hello. I'm trying to count string data that correspond to a given condition in two factors of the

Re: [R] Counting two factors at the same time

2010-01-22 Thread Fabrice DELENTE
Try this; f - c( 'A', 'B', 'A', 'C', 'B', 'D', 'B') n - c('1', '2', '2', '3', '2', '2', '3') table(paste(f, n)) Thanks for the incredibly fast answer! I'll give this a shot! -- Fabrice DELENTE __ R-help@r-project.org mailing list

Re: [R] Counting two factors at the same time

2010-01-22 Thread David Winsemius
On Jan 22, 2010, at 1:58 PM, Fabrice DELENTE wrote: Try this; f - c( 'A', 'B', 'A', 'C', 'B', 'D', 'B') n - c('1', '2', '2', '3', '2', '2', '3') table(paste(f, n)) Thanks for the incredibly fast answer! I'll give this a shot! Here's another R-way: lets-factor(c( 'A', 'B', 'A', 'C',

Re: [R] Counting two factors at the same time

2010-01-22 Thread Fabrice DELENTE
Here's another R-way: lets-factor(c( 'A', 'B', 'A', 'C', 'B', 'D', 'B')) # you did say they were factors, right? nums - factor(c('1', '2', '2', '3', '2', '2', '3')) lets==B [1] FALSE TRUE FALSE FALSE TRUE FALSE TRUE sum(lets==B nums==2) [1] 2 Thanks very much, it will save me

Re: [R] Counting two factors at the same time

2010-01-22 Thread David Winsemius
On Jan 22, 2010, at 2:07 PM, Fabrice DELENTE wrote: Here's another R-way: lets-factor(c( 'A', 'B', 'A', 'C', 'B', 'D', 'B')) # you did say they were factors, right? nums - factor(c('1', '2', '2', '3', '2', '2', '3')) lets==B [1] FALSE TRUE FALSE FALSE TRUE FALSE TRUE sum(lets==B

[R] counting the number of times a string appears

2010-01-13 Thread Jesse Sinclair
Hi all, I have a vector of strings and need to count the number of times a string appears in the vector. eg: [1] spp6 spp10 spp6 spp6 spp4 spp2 spp9 spp10 spp5 spp2 spp2 spp3 [13] spp4 spp3 spp6 spp10 spp6 spp4 spp9 spp3 spp6 spp1 spp10 spp8 [25] spp2 spp10 spp9 spp7

Re: [R] counting the number of times a string appears

2010-01-13 Thread Greg Hirson
Jesse, see ?table and try table(stringVector) Greg On 1/13/10 2:12 PM, Jesse Sinclair wrote: Hi all, I have a vector of strings and need to count the number of times a string appears in the vector. eg: [1] spp6 spp10 spp6 spp6 spp4 spp2 spp9 spp10 spp5 spp2 spp2 spp3 [13]

Re: [R] counting the number of times a string appears

2010-01-13 Thread Rolf Turner
?table On 14/01/2010, at 11:12 AM, Jesse Sinclair wrote: Hi all, I have a vector of strings and need to count the number of times a string appears in the vector. eg: [1] spp6 spp10 spp6 spp6 spp4 spp2 spp9 spp10 spp5 spp2 spp2 spp3 [13] spp4 spp3 spp6 spp10 spp6 spp4

Re: [R] counting the number of times a string appears

2010-01-13 Thread Adrian Dusa
Hi Jesse, If your vector is called aa, then how about: table(aa) aa spp1 spp10 spp2 spp3 spp4 spp5 spp6 spp7 spp8 spp9 7 216 815 9 910 915 Hope this helps, Adrian On Thursday 14 January 2010, Jesse Sinclair wrote: Hi all, I have a vector

Re: [R] counting the number of times a string appears

2010-01-13 Thread Jesse Sinclair
This is great all. It works perfectly. Thank-you. Cheers, Jesse On Wed, Jan 13, 2010 at 14:27, Adrian Dusa dusa.adr...@gmail.com wrote: Hi Jesse, If your vector is called aa, then how about: table(aa) aa spp1 spp10 spp2 spp3 spp4 spp5 spp6 spp7 spp8 spp9 7 216

[R] Counting in Matrix

2009-12-15 Thread Tom Pitt
Hi All, Is there an easy way to count TRUEs for each row? Thanks, Tom x1x2x3x4 1 TRUE TRUE TRUE TRUE 2 FALSE TRUE TRUE TRUE 3 TRUE FALSE TRUE TRUE 4 FALSE FALSE TRUE TRUE 5 TRUE TRUE FALSE TRUE 6 FALSE TRUE FALSE TRUE 7 TRUE FALSE FALSE TRUE 8

Re: [R] Counting in Matrix

2009-12-15 Thread Erik Iverson
?rowSums -Original Message- From: r-help-boun...@r-project.org [mailto:r-help-boun...@r-project.org] On Behalf Of Tom Pitt Sent: Tuesday, December 15, 2009 2:57 PM To: r-help@r-project.org Subject: [R] Counting in Matrix Hi All, Is there an easy way to count TRUEs for each

[R] Counting Frequencies

2009-12-09 Thread BIGBEEF
Hi - I'm having difficulty with frequencies in R. I have a table with a variable (column) called difference 600 observations (rows). I would like to know how many values are -0.5 as well as how many are 0.5. The rest are obviously in the middle. In SAS I could this immediately but am unable to

Re: [R] Counting Frequencies

2009-12-09 Thread Wensui Liu
x - runif(10, 0, 1) x2 - x 0.5 x2 [1] TRUE TRUE FALSE FALSE FALSE TRUE TRUE FALSE TRUE FALSE table(x2) x2 FALSE TRUE 5 5 On Wed, Dec 9, 2009 at 6:36 PM, BIGBEEF martin.beze...@gmail.com wrote: Hi - I'm having difficulty with frequencies in R. I have a table with a

Re: [R] Counting Frequencies

2009-12-09 Thread Jim Lemon
On 12/10/2009 10:36 AM, BIGBEEF wrote: Hi - I'm having difficulty with frequencies in R. I have a table with a variable (column) called difference 600 observations (rows). I would like to know how many values are -0.5 as well as how many are 0.5. The rest are obviously in the middle. In SAS I

[R] Counting non-empty levels of a factor

2009-11-08 Thread sylvain willart
Hi everyone, I'm struggling with a little problem for a while, and I'm wondering if anyone could help... I have a dataset (from retailing industry) that indicates which brands are present in a panel of 500 stores, store , brand 1 , B1 1 , B2 1 , B3 2 , B1 2 , B3 3 , B2 3 , B3 3 , B4 I would

Re: [R] Counting non-empty levels of a factor

2009-11-08 Thread David Winsemius
On Nov 8, 2009, at 8:38 AM, sylvain willart wrote: Hi everyone, I'm struggling with a little problem for a while, and I'm wondering if anyone could help... I have a dataset (from retailing industry) that indicates which brands are present in a panel of 500 stores, store , brand 1 , B1 1 ,

Re: [R] Counting non-empty levels of a factor

2009-11-08 Thread David Winsemius
On Nov 8, 2009, at 9:11 AM, David Winsemius wrote: On Nov 8, 2009, at 8:38 AM, sylvain willart wrote: Hi everyone, I'm struggling with a little problem for a while, and I'm wondering if anyone could help... I have a dataset (from retailing industry) that indicates which brands are

Re: [R] Counting non-empty levels of a factor

2009-11-08 Thread sylvain willart
Thanks a lot for those solutions, Both are working great, and they do slightly different (but both very interesting) things, Moreover, I learned about the length() function ... one more to add to my personal cheat sheet King Regards 2009/11/8 David Winsemius dwinsem...@comcast.net: On Nov 8,

Re: [R] Counting non-empty levels of a factor

2009-11-08 Thread John Kane
: [R] Counting non-empty levels of a factor To: r-help@r-project.org Received: Sunday, November 8, 2009, 8:38 AM Hi everyone, I'm struggling with a little problem for a while, and I'm wondering if anyone could help... I have a dataset (from retailing industry) that indicates which brands

[R] counting frequencies across two columns

2009-11-01 Thread Jason Priem
I've got a data frame describing comments on an electronic journal, wherein each row is a unique comment, like so: commentID author articleID 1 1 smith 2 2 2 jones 3 3 3 andrews 2 4 4 jones 1 5 5 johnson 3 6

Re: [R] counting frequencies across two columns

2009-11-01 Thread milton ruser
Hi Jason, As your example is not reproducible, may be something like: myFreq-data.frame(table(articleID, author)) if you want to know only those articles with 1 author, you can try subset(myFreq, Freq==1) or something like. bests milton On Sun, Nov 1, 2009 at 2:20 AM, Jason Priem

Re: [R] counting frequencies across two columns

2009-11-01 Thread Patrick Connolly
On Sun, 01-Nov-2009 at 01:20AM -0500, Jason Priem wrote: I've got a data frame describing comments on an electronic journal, wherein each row is a unique comment, like so: commentID author articleID 1 1 smith 2 2 2 jones 3 3 3 andrews

Re: [R] counting frequencies across two columns

2009-11-01 Thread David Winsemius
On Nov 1, 2009, at 1:59 AM, Patrick Connolly wrote: On Sun, 01-Nov-2009 at 01:20AM -0500, Jason Priem wrote: I've got a data frame describing comments on an electronic journal, wherein each row is a unique comment, like so: commentID author articleID 1 1 smith 2 2

Re: [R] counting frequencies across two columns

2009-11-01 Thread Jorge Ivan Velez
Hi Jason, If I understand correctly, you are looking for something along the lines of with(X, tapply(author, articleID, function(x) length(unique(x # 1 2 3 # 1 2 2 with X your data frame. HTH, Jorge On Sun, Nov 1, 2009 at 1:20 AM, Jason Priem wrote: I've got a data frame describing

[R] Counting

2009-10-20 Thread Ashta
Hi All, Assume that I have the following data set  with two variables and I want count the number of observation with identical values  and number of time each factor changed from x1 to x2. x1  x2  1    1  1    0  0    1  0    1  0    0  1    1 0    1 The output should be x1  changed

Re: [R] Counting

2009-10-20 Thread Jorge Ivan Velez
Hi Ashta, Take a look at ?rle, e.g. rle(x1) Run Length Encoding lengths: int [1:4] 2 3 1 1 values : num [1:4] 1 0 1 0 rle(x1)$lengths [1] 2 3 1 1 rle(x1)$values [1] 1 0 1 0 HTH, Jorge On Tue, Oct 20, 2009 at 10:10 AM, Ashta wrote: Hi All, Assume that I have the following data set

Re: [R] Counting

2009-10-20 Thread Peter Ehlers
How about unch - aggregate(x2==x1, by = list(x1=x1), FUN = sum) chgd - aggregate(x2!=x1, by = list(x1=x1), FUN = sum) -Peter Ehlers Ashta wrote: Hi All, Assume that I have the following data set with two variables and I want count the number of observation with identical values and

Re: [R] Counting

2009-10-20 Thread William Dunlap
From: r-help-boun...@r-project.org [mailto:r-help-boun...@r-project.org] On Behalf Of Peter Ehlers Sent: Tuesday, October 20, 2009 8:48 AM To: Ashta Cc: R help Subject: Re: [R] Counting How about unch - aggregate(x2==x1, by = list(x1=x1), FUN = sum) chgd - aggregate(x2!=x1

Re: [R] Counting

2009-10-20 Thread Peter Ehlers
Nice solution, Bill. -Peter Ehlers William Dunlap wrote: From: r-help-boun...@r-project.org [mailto:r-help-boun...@r-project.org] On Behalf Of Peter Ehlers Sent: Tuesday, October 20, 2009 8:48 AM To: Ashta Cc: R help Subject: Re: [R] Counting How about unch - aggregate(x2==x1, by = list

Re: [R] Counting

2009-10-20 Thread Ashta
Hi Bill and all, On Tue, Oct 20, 2009 at 12:09 PM, William Dunlap wdun...@tibco.com wrote: From: r-help-boun...@r-project.org [mailto:r-help-boun...@r-project.org] On Behalf Of Peter Ehlers Sent: Tuesday, October 20, 2009 8:48 AM To: Ashta Cc: R help Subject: Re: [R] Counting How about

Re: [R] Counting

2009-10-20 Thread Peter Ehlers
Ashta wrote: Hi Bill and all, On Tue, Oct 20, 2009 at 12:09 PM, William Dunlap wdun...@tibco.com wrote: From: r-help-boun...@r-project.org [mailto:r-help-boun...@r-project.org] On Behalf Of Peter Ehlers Sent: Tuesday, October 20, 2009 8:48 AM To: Ashta Cc: R help Subject: Re: [R] Counting

[R] Counting

2009-10-13 Thread Ashta
*Hi all, * *Assume that I have the following data set with tow variables and I want count the number of observation with identical values * ** *x1 x2* * 1 1 * * 1 0 * * 0 1* * 0 1* * 0 0* * 1 1* * 0 1 * I want the following output ** * * *n1=3 # number of identical

Re: [R] Counting

2009-10-13 Thread Henrique Dallazuanna
Try this: table(Reduce(`==`, DF)) On Tue, Oct 13, 2009 at 9:20 AM, Ashta sewa...@gmail.com wrote: *Hi all, * *Assume that I have the following data set  with tow variables and I want count the number of observation with identical values * ** *x1 x2* * 1   1 * * 1   0 * * 0   1*

Re: [R] Counting

2009-10-13 Thread Julien Grassot
Technologies FRANCE -Message d'origine- De : r-help-boun...@r-project.org [mailto:r-help-boun...@r-project.org] De la part de Henrique Dallazuanna Envoyé : mardi 13 octobre 2009 14:41 À : Ashta Cc : R help Objet : Re: [R] Counting Try this: table(Reduce(`==`, DF)) On Tue, Oct 13

Re: [R] Counting

2009-10-13 Thread William Dunlap
-Original Message- From: r-help-boun...@r-project.org [mailto:r-help-boun...@r-project.org] On Behalf Of Ashta Sent: Tuesday, October 13, 2009 5:20 AM To: R help Subject: [R] Counting *Hi all, * *Assume that I have the following data set with tow variables and I want

[R] Counting observations of a combined factor

2009-09-19 Thread Sam Player
#I have a dataset with two factor. I want to combine those factors into a single factor and count the number of data values for each new factor. The following gives a comparable dataframe: a - rep(c(a, b), c(6,6)) b - rep(c(c, d), c(6,6)) df - data.frame(f1=a, f2=b, d=rnorm(12)) df # I use

Re: [R] Counting observations of a combined factor

2009-09-19 Thread Peter Ehlers
Sam, Depending on what your ultimate aim is, perhaps you just want to add the 'drop=TRUE' argument to your interaction call. Peter Sam Player wrote: #I have a dataset with two factor. I want to combine those factors into a single factor and count the number of data values for each new factor.

Re: [R] Counting observations of a combined factor

2009-09-19 Thread David Winsemius
On Sep 19, 2009, at 5:39 AM, Sam Player wrote: #I have a dataset with two factor. I want to combine those factors into a single factor and count the number of data values for each new factor. The following gives a comparable dataframe: a - rep(c(a, b), c(6,6)) b - rep(c(c, d), c(6,6)) df

[R] counting subgroup sums within a data frame

2009-08-26 Thread Shaun Grannis
Hi, I'm sure there's an easy approach to this issue, I'm just not seeing it. I have a data frame of the following form: Date classsubclass count 8/1/2009AX 1 8/1/2009BX 2 8/1/2009AY 9 8/1/2009BY 3

Re: [R] counting subgroup sums within a data frame

2009-08-26 Thread Henrique Dallazuanna
Try this: with(d, tapply(count, list(Date, class), sum)) On Wed, Aug 26, 2009 at 10:07 AM, Shaun Grannis sgran...@regenstrief.orgwrote: Hi, I'm sure there's an easy approach to this issue, I'm just not seeing it. I have a data frame of the following form: Date classsubclass

Re: [R] counting subgroup sums within a data frame

2009-08-26 Thread Shaun Grannis
Wow. That was fast -- and spot on! Thanks so much. Best Regards, Shaun On Aug 26, 2009, at 9:11 AM, Henrique Dallazuanna wrote: Try this: with(d, tapply(count, list(Date, class), sum)) On Wed, Aug 26, 2009 at 10:07 AM, Shaun Grannis sgran...@regenstrief.org wrote: Hi, I'm sure

Re: [R] counting subgroup sums within a data frame

2009-08-26 Thread ONKELINX, Thierry
that a reasonable answer can be extracted from a given body of data. ~ John Tukey -Oorspronkelijk bericht- Van: r-help-boun...@r-project.org [mailto:r-help-boun...@r-project.org] Namens Shaun Grannis Verzonden: woensdag 26 augustus 2009 15:07 Aan: r-help@r-project.org Onderwerp: [R] counting

Re: [R] Counting the number of non-NA values per day

2009-08-12 Thread Moshe Olshansky
Try tempFun - function(x) sum(!is.na(x)) nonZeros - aggregate(pollution[pol],format(pollution[date],%Y-%j), FUN = tempFun) --- On Wed, 12/8/09, Tim Chatterton tim.chatter...@uwe.ac.uk wrote: From: Tim Chatterton tim.chatter...@uwe.ac.uk Subject: [R] Counting the number of non-NA values per

[R] Counting the number of non-NA values per day

2009-08-11 Thread Tim Chatterton
I have a long dataframe (pollution) that contains a column of hourly date information (date) and a column of pollution measurements (pol) I have been happily calculating daily means and daily maximums using the aggregate function DMEANpollution = aggregate(pollution[pol],

Re: [R] Counting things

2009-08-05 Thread Gabor Grothendieck
Try this using built in data frame iris: length(subset(iris, Sepal.Length = 7, Sepal.Width)[[1]]) [1] 13 length(subset(iris, Sepal.Length = 7 Species == 'virginica', Sepal.Width)[[1]]) [1] 12 # or the following (note that dot in Sepal.Length is automatically # converted to _ because dot

Re: [R] Counting things

2009-08-05 Thread William Dunlap
-Original Message- From: r-help-boun...@r-project.org [mailto:r-help-boun...@r-project.org] On Behalf Of Noah Silverman Sent: Tuesday, August 04, 2009 8:40 PM To: r help Subject: [R] Counting things I've completed an experiment and want to summarize the results. There are two

[R] Counting things

2009-08-04 Thread Noah Silverman
I've completed an experiment and want to summarize the results. There are two things I like to create. 1) A simple count of things from the data.frame with predictions 1a) Number of predictions with probability greater than x 1b) Number of predictions with probability greater than x

[R] - counting factor occurrences within a group: tapply()

2009-07-29 Thread Ian Chidister
Dear List, I'm an [R] novice starting analysis of an ecological dataset containing the basal areas of different tree species in a number of research plots. Example data follow: Trees-data.frame(SppID=as.factor(c(rep('QUEELL',2), rep('QUEALB',3), 'CORAME', 'ACENEG', 'TILAME')), BA=c(907.9,

Re: [R] - counting factor occurrences within a group: tapply()

2009-07-29 Thread jim holtman
This is probably what you want; you need to count the number of unique instances: tapply(Trees$SppID, Trees$PlotID, function(x) length(unique(x))) BU3F10 BU3F11 BU3F12 1 2 4 On Wed, Jul 29, 2009 at 12:57 PM, Ian Chidisterian.chidis...@gmail.com wrote: Dear List, I'm an [R]

Re: [R] - counting factor occurrences within a group: tapply()

2009-07-29 Thread Daniel Malter
Auftrag von Ian Chidister Gesendet: Wednesday, July 29, 2009 12:57 PM An: r-help@r-project.org Betreff: [R] - counting factor occurrences within a group: tapply() Dear List, I'm an [R] novice starting analysis of an ecological dataset containing the basal areas of different tree species in a number

Re: [R] - counting factor occurrences within a group: tapply()

2009-07-29 Thread Ian Chidister
Hi All- Thanks for your quick responses. I was looking for unique instances, so Jim's and Daniel's suggestions got the job done. Using length alone didn't discriminate between multiple occurrences of the same species and multiple species. I do have one followup question- my full data set (not

Re: [R] - counting factor occurrences within a group: tapply()

2009-07-29 Thread jim holtman
One way is to exclude the NAs from consideration by creating a new object without NAs in that column: newTrees - Trees[!is.na(Trees$SppID),] tapply(newTrees$SppID, newTrees$PlotID, function(x) length(unique(x))) On Wed, Jul 29, 2009 at 2:13 PM, Ian Chidisterian.chidis...@gmail.com wrote: Hi

Re: [R] - counting factor occurrences within a group: tapply()

2009-07-29 Thread jim holtman
Or even easier: tapply(Trees$SppID, Trees$PlotID, function(x) length(unique(na.omit(x On Wed, Jul 29, 2009 at 2:13 PM, Ian Chidisterian.chidis...@gmail.com wrote: Hi All- Thanks for your quick responses.  I was looking for unique instances, so Jim's and Daniel's suggestions got the job

Re: [R] - counting factor occurrences within a group: tapply()

2009-07-29 Thread Ian Chidister
Jim- That did the trick- thanks so much for taking the time to help me out. Sincerely, Ian Chidister On Wed, Jul 29, 2009 at 11:57 AM, Ian Chidister ian.chidis...@gmail.comwrote: Dear List, I'm an [R] novice starting analysis of an ecological dataset containing the basal areas of

Re: [R] Counting the number of cycles in a temperature test

2009-07-10 Thread Arien Lam
of lower temperature followed by 30 minutes of upper temperature? --- On Mon, 6/7/09, Steller, Antje (GQL-LM) antje.stel...@volkswagen.de wrote: From: Steller, Antje (GQL-LM) antje.stel...@volkswagen.de Subject: [R] Counting the number of cycles in a temperature test To: r-help@r-project.org

Re: [R] Counting the number of cycles in a temperature test

2009-07-07 Thread Moshe Olshansky
? Can a cycle be 30 minutes of lower temperature followed by 30 minutes of upper temperature? --- On Mon, 6/7/09, Steller, Antje (GQL-LM) antje.stel...@volkswagen.de wrote: From: Steller, Antje (GQL-LM) antje.stel...@volkswagen.de Subject: [R] Counting the number of cycles in a temperature test

[R] Counting the number of cycles in a temperature test

2009-07-06 Thread Steller, Antje (GQL-LM)
Hello dear R-users, today I have a question that I completely do not know how to solve (R-newbie!). In a temperature chamber I have measured temperature over time. The result is shown in the attached eps-file (if attachments are shown): There are two temperature levels, 150°C and -40°C. A

Re: [R] Counting the number of cycles in a temperature test

2009-07-06 Thread jim holtman
You can count the number of times the values make a transition through some threshold and average over some short time period because you probably get multiple transitions in a short time as it is approaching the threshold. Once you have that, you can count then number of times it happens. On

[R] counting occurrence of text in a dataframe

2009-05-23 Thread Iain Gallagher
Hello list. I am hoping for some help with a relatively simple problem. I have a data frame arranged as below. I want to be able to count the occurrence of each gene (eg let-7e) by Experiment. In other words how many times does a given gene crop up in the dataframe. I tried table but couldn't

Re: [R] counting occurrence of text in a dataframe

2009-05-23 Thread Gabor Grothendieck
Try this: Lines - Tanaka Mitchell Wang Hunter Chen Chim miR-191* let-7e let-7b miR-126let-7a let-7g miR-198let-7f let-7c miR-146a let-7b let-7i miR-22 let-7g miR-1224 miR-16 let-7d miR-130b miR-223let-7i miR-124

Re: [R] counting occurrence of text in a dataframe

2009-05-23 Thread Stefan Grosse
On Sat, 23 May 2009 12:44:19 + (GMT) Iain Gallagher iaingallag...@btopenworld.com wrote: IG I am hoping for some help with a relatively simple problem. I have IG a data frame arranged as below. I want to be able to count the IG occurrence of each gene (eg let-7e) by Experiment. In other words

[R] counting strings in a column

2009-02-19 Thread Nattu
Dear All, I have a query : what is the command to count number of repeated words in a column. for ex: a = oranges oranges apples apples grape oranges apple pine the result should be oranges 3 apples 3 grape 1 pine 1 is there an easy way for this. Thanks, Nataraju GM R D Bangalore --

Re: [R] counting strings in a column

2009-02-19 Thread jim holtman
?table On Thu, Feb 19, 2009 at 11:48 AM, Nattu natar...@gmail.com wrote: Dear All, I have a query : what is the command to count number of repeated words in a column. for ex: a = oranges oranges apples apples grape oranges apple pine the result should be oranges 3 apples 3

[R] Counting/processing a character vector

2009-02-18 Thread Gavin Simpson
Dear List, I have a data set stored in the following format: head(dat, n = 10) id sppcode abundance 1 10307 1000 1 2 10307 16220602 2 3 10307 2000 5 4 10307 2011 2 5 10307 2400 1 6 10307 402183 7 10307 40210102

Re: [R] Counting/processing a character vector

2009-02-18 Thread Gavin Simpson
Apologies, Jim Holtman has pointed out a couple of problems/queries with my original email that I would like to make clear. Firstly, I introduced a typo when trying to be helpful. In my email below, I had incorrectly typed out one of the species codes I would count: 1000 16220602 2011

Re: [R] Counting/processing a character vector

2009-02-18 Thread Gavin Simpson
To answer my own post, and for the archives (hopefully not that anyone has to repeat what I had to do ;-), after much hair-pulling , frowning at the screen and general dumb headedness the following slab of R code achieves the results I wanted. It isn't elegant but does a job. msr - function(x) {

[R] Counting session days

2009-02-09 Thread stefan . petersson
hi, I have some session data in a dataframe, where each session is recorded with a start and a stop date. Like this: session_start session_stop === 2009-01-03 2009-01-04 2009-01-01 2009-01-05 2009-01-02 2009-01-09 A session is at least one day long. Now I want

Re: [R] Counting session days

2009-02-09 Thread Gabor Grothendieck
Try this: dateseq - function(i) seq(DF[i, 1], DF[i, 2], 1) table(as.Date(unlist(lapply(1:nrow(DF), dateseq)), origin = 1970-01-01)) 2009-01-01 2009-01-02 2009-01-03 2009-01-04 2009-01-05 2009-01-06 2009-01-07 1 2 3 3 2 1 1

Re: [R] Counting session days

2009-02-09 Thread Gustaf Rydevik
On Mon, Feb 9, 2009 at 4:57 PM, stefan.peters...@inizio.se wrote: hi, I have some session data in a dataframe, where each session is recorded with a start and a stop date. Like this: session_start session_stop === 2009-01-03 2009-01-04 2009-01-01 2009-01-05

[R] counting entries in vector

2009-02-04 Thread axionator
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

Re: [R] counting entries in vector

2009-02-04 Thread Dimitris Rizopoulos
try this: k - c(bb, bb, bb, aa, cc, cc) f - factor(k, levels = unique(k)) as.vector(table(f)) you can put it in one line but it's less readable. I hope it helps. Best, Dimitris axionator wrote: Hi all, I've a vector with entries, which are all of the same type, e.g. string: k - c(bb, bb,

Re: [R] counting entries in vector

2009-02-04 Thread Gabor Grothendieck
Its not clear whether c(bb, bb, aa, aa, bb) can occur or if it can how it should be handled but this gives the lengths of each run and so would give c(2, 2, 1) in that case (as opposed to c(3, 2)): rle(k)$lengths On Wed, Feb 4, 2009 at 10:19 AM, axionator axiona...@gmail.com wrote: Hi all,

Re: [R] counting entries in vector

2009-02-04 Thread Ben Bolker
axionator axionator at gmail.com writes: 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) table(k) Ben Bolker

Re: [R] counting entries in vector

2009-02-04 Thread Stavros Macrakis
Take a look at the run-length encoding function rle. I believe rle(k)$lengths gives you exactly what you want. -s On Wed, Feb 4, 2009 at 10:19 AM, axionator axiona...@gmail.com wrote: Hi all, I've a vector with entries, which are all of the same type, e.g. string: k - c(bb, bb,

Re: [R] counting entries in vector

2009-02-04 Thread Ian Fiske
Try: table(k)[rank(unique(k))] -ian Armin Meier wrote: 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)

Re: [R] counting entries in vector

2009-02-04 Thread Henrique Dallazuanna
Try: table(k) On Wed, Feb 4, 2009 at 1:19 PM, axionator axiona...@gmail.com wrote: 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

Re: [R] counting entries in vector

2009-02-04 Thread axionator
rle(k)$lengths is perfectly suitable for my purposes. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal,

Re: [R] counting the number of elements in a column

2008-11-18 Thread Jorge Ivan Velez
Dear kayj, Here is one way: # Data set.seed(123) x=runif(100) # Cuts as.data.frame.table(table(cut(x,seq(0,1,by=0.1 #Var1 Freq #1(0,0.1]7 #2 (0.1,0.2] 12 #3 (0.2,0.3] 11 #4 (0.3,0.4]9 #5 (0.4,0.5] 14 #6 (0.5,0.6]7 #7 (0.6,0.7] 11 #8 (0.7,0.8] 11 #9

[R] counting the number of elements in a column

2008-11-17 Thread kayj
Hi All, I have a column that contains values between 0 and 1. I would like to make a table that consists of the number of elements in each category. For example , how many elements have values between 0 and 0.1, 0.1 to 0.2, 0.2 to 0.3,etc……..0.9 to 1. Is there an easy way to do this? Thanks

Re: [R] counting the number of elements in a column

2008-11-17 Thread David Winsemius
On Nov 18, 2008, at 12:50 AM, kayj wrote: Hi All, I have a column that contains values between 0 and 1. I would like to make a table that consists of the number of elements in each category. For example , how many elements have values between 0 and 0.1, 0.1 to 0.2, 0.2 to

[R] counting run lengths

2008-10-27 Thread Mario Lavezzi
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

Re: [R] counting run lengths

2008-10-27 Thread Dimitris Rizopoulos
it's not totally clear to me what exactly do you need in this case, but have a look at the following: Atr - cbind(rep(1:0, each = 4), 1, c(1, rep(0, 7)), 1) unSpells - colSums(Atr == 0) unSpells[unSpells == 0] - 1 unSpells I hope it helps. Best, Dimitris Mario Lavezzi wrote: Hello, I have

Re: [R] counting run lengths

2008-10-27 Thread Domenico Vistocco
Try this: unSpells[tail(Atr,1)==0] - apply(Atr,2,function(x)sum(x==0))[tail(Atr,1)==0] Or (if you don't have to preserve the value in the unSpells vector): unSpells - apply(Atr,2,function(x)sum(x==0)) But in this case you have 0 instead of 1 in the second and fourth position. Ciao, domenico

Re: [R] counting run lengths

2008-10-27 Thread Mario Lavezzi
Hi Dimitris, thank you very much. Actually, I have not specified the following: i want to consider only the most recent sequence of zeros, that is the last part of the time series. That is, If I have: [,1] [,2] [,3] [,4] [1,]0101 [2,]1111 [3,]11

Re: [R] counting run lengths

2008-10-27 Thread Dimitris Rizopoulos
then try the following: Atr - cbind(rep(1:0, each = 4), 1, c(1, rep(0, 7)), 1) Atr - rbind(c(0, 1, 0, 1), Atr) apply(Atr, 2, function (x) { rr - rle(x) if (tail(rr$values, 1) == 0) tail(rr$length, 1) else 0 }) I hope this what you're looking for. Best, Dimitris Mario Lavezzi wrote:

Re: [R] counting run lengths

2008-10-27 Thread Richard . Cotton
It works, but the for (i in ...) loop slows down the simulation a lot. Any suggestion on how to avoid this loop? (or in general, to speed up this part of the simulation) Actually, I have not specified the following: i want to consider only the most recent sequence of zeros, that is

Re: [R] counting run lengths

2008-10-27 Thread Martin Morgan
Hi Mario -- This function f - function(m) { ## next 2 lines due to Bill Dunlap ## http://tolstoy.newcastle.edu.au/R/e4/devel/08/04/1206.html csum - cumsum(!m) crun - csum - cummax(m * csum) matrix(ifelse(crun 0, (crun-1) %% nrow(m) + 1, 0), nrow=nrow(m)) }

Re: [R] counting run lengths

2008-10-27 Thread Mario Lavezzi
Dear Richard, Martin, Dimitris and Domenico thank you very much for your help. I must say that the fastest procedure appears to be the one suggested by Richard This runs pretty quickly: unSpells - nrow(Atr) - apply(Atr,2,function(x) max(which(x==1))) #c(4,0,7,0) If I may abuse of your

[R] counting the frequencies of a vector

2008-10-16 Thread Jörg Groß
Hi, Is there a function which counts the frequencies of the occurence of a number within an interval? for example I have this vector: x - c(1, 3, 1.2, 5, 5.9) and I want a vector that gives me the frequencies within an interval of 2, beginning at 0 (so the intervals are 0-2, 2-4, 4-6

Re: [R] counting the frequencies of a vector

2008-10-16 Thread Barry Rowlingson
2008/10/16 Jörg Groß [EMAIL PROTECTED]: Hi, Is there a function which counts the frequencies of the occurence of a number within an interval? for example I have this vector: x - c(1, 3, 1.2, 5, 5.9) and I want a vector that gives me the frequencies within an interval of 2, beginning at

Re: [R] counting the frequencies of a vector

2008-10-16 Thread David Winsemius
On Oct 16, 2008, at 12:55 PM, Jorge Ivan Velez wrote: Dear Jörg, See ?cut and ?table. Is this what you want? x - c(1, 3, 1.2, 5, 5.9) table(cut(x,breaks=c(0,2,4,6))) (0,2] (2,4] (4,6] 2 1 2 Perhaps even greater future efficiency could be had by also adding ?seq table(cut(x,

Re: [R] Counting character occurrences in data frame

2008-09-24 Thread Hutchinson,David [PYR]
Thanks Charles, ftable() works perfectly. -Original Message- From: Charles C. Berry [mailto:[EMAIL PROTECTED] Sent: Tuesday, September 23, 2008 5:06 PM To: Hutchinson,David [PYR] Cc: r-help@r-project.org Subject: Re: [R] Counting character occurrences in data frame See

[R] Counting character occurrences in data frame

2008-09-23 Thread Hutchinson,David [PYR]
Hi R-Users, I have a data frame containing year, month, day, and code columns. The code column is a unique character of set ('E','A','B') - I am trying to determine an efficient way of summarizing the count of each of these codes by month and year without having to use for...loops and subsets.

Re: [R] Counting character occurrences in data frame

2008-09-23 Thread Henrique Dallazuanna
Try this: with(DF, tapply(code, list(year, month, code), length)) On Tue, Sep 23, 2008 at 8:10 PM, Hutchinson,David [PYR] [EMAIL PROTECTED] wrote: Hi R-Users, I have a data frame containing year, month, day, and code columns. The code column is a unique character of set ('E','A','B') - I am

Re: [R] Counting character occurrences in data frame

2008-09-23 Thread Charles C. Berry
See ?ftable ?as.data.frame ?xtabs e.g. ftable( xtabs( ~code+year+month, your.df ), col.vars=1 ) as.data.frame( xtabs(~code+year+month, your.df ) ) HTH, Chuck On Tue, 23 Sep 2008, Hutchinson,David [PYR] wrote: Hi R-Users, I have a data frame

[R] counting number of G in TCGGGGGACAATCGGTAACCCGTCT

2008-07-15 Thread Daren Tan
Any better solution than this ? sum(strsplit(TCGACAATCGGTAACCCGTCT, )[[1]] == G) _ [[alternative HTML version deleted]] __ R-help@r-project.org mailing list

Re: [R] counting number of G in TCGGGGGACAATCGGTAACCCGTCT

2008-07-15 Thread Ken Knoblauch
Daren Tan daren76 at hotmail.com writes: Any better solution than this ? sum(strsplit(TCGACAATCGGTAACCCGTCT, )[[1]] == G) Try table(strsplit(TCGACAATCGGTAACCCGTCT, )) A C G T 5 7 8 5 and get all 4 at once. HTH -- Ken Knoblauch Inserm U846 Institut Cellule Souche et Cerveau

Re: [R] counting number of G in TCGGGGGACAATCGGTAACCCGTCT

2008-07-15 Thread Henrik Bengtsson
Seems like you can do: library(matchprobes) # on Bioconductor countbases(TCGACAATCGGTAACCCGTCT)[,G] The catch is that it only counts A, C, G, and T:s and no other symbols. /Henrik On Tue, Jul 15, 2008 at 8:27 AM, Daren Tan [EMAIL PROTECTED] wrote: Any better solution than this ?

Re: [R] counting number of G in TCGGGGGACAATCGGTAACCCGTCT

2008-07-15 Thread Wolfgang Huber
Hi, And the Bioconductor package Biostrings is the place to go for any serious work with sequences. -- Best wishes Wolfgang -- Wolfgang Huber EBI/EMBL Cambridge UK http://www.ebi.ac.uk/huber 15/07/2008 16:43 Henrik Bengtsson

<    1   2   3   4   5   >