Re: [R] counting duplicate items that occur in multiple groups

2020-11-18 Thread Tom Woolman
Thanks, everyone! Quoting Jim Lemon : Oops, I sent this to Tom earlier today and forgot to copy to the list: VendorID=rep(paste0("V",1:10),each=5) AcctID=paste0("A",sample(1:5,50,TRUE)) Data<-data.frame(VendorID,AcctID) table(Data) # get multiple vendors for each account dupAcctID<-colSums(t

Re: [R] counting duplicate items that occur in multiple groups

2020-11-18 Thread Jim Lemon
Oops, I sent this to Tom earlier today and forgot to copy to the list: VendorID=rep(paste0("V",1:10),each=5) AcctID=paste0("A",sample(1:5,50,TRUE)) Data<-data.frame(VendorID,AcctID) table(Data) # get multiple vendors for each account dupAcctID<-colSums(table(Data)>0) Data$dupAcct<-NA # fill in the

Re: [R] counting duplicate items that occur in multiple groups

2020-11-18 Thread Deepayan Sarkar
On Wed, Nov 18, 2020 at 5:40 AM Bert Gunter wrote: > > z <- with(Data2, tapply(Vendor,Account, I)) > n <- vapply(z,length,1) > data.frame (Vendor = unlist(z), >Account = rep(names(z),n), >NumVen = rep(n,n) > ) > > ## which gives: > >Vendor Account NumVen > A1 V1 A1 1 > A

Re: [R] counting duplicate items that occur in multiple groups

2020-11-17 Thread Bert Gunter
z <- with(Data2, tapply(Vendor,Account, I)) n <- vapply(z,length,1) data.frame (Vendor = unlist(z), Account = rep(names(z),n), NumVen = rep(n,n) ) ## which gives: Vendor Account NumVen A1 V1 A1 1 A21 V2 A2 3 A22 V3 A2 3 A23 V1 A2 3

Re: [R] counting duplicate items that occur in multiple groups

2020-11-17 Thread Avi Gross via R-help
. -Original Message- From: R-help On Behalf Of Tom Woolman Sent: Tuesday, November 17, 2020 6:30 PM To: Bill Dunlap Cc: r-help@r-project.org Subject: Re: [R] counting duplicate items that occur in multiple groups Hi Bill. Sorry to be so obtuse with the example data, I was trying (too hard) not

Re: [R] counting duplicate items that occur in multiple groups

2020-11-17 Thread Bert Gunter
Why 0's in the data frame? Shouldn't that be 1 (vendor with that account)? Bert Bert Gunter "The trouble with having an open mind is that people keep coming along and sticking things into it." -- Opus (aka Berkeley Breathed in his "Bloom County" comic strip ) On Tue, Nov 17, 2020 at 3:29 PM Tom

Re: [R] counting duplicate items that occur in multiple groups

2020-11-17 Thread Tom Woolman
Yes, good catch. Thanks Quoting Bert Gunter : Why 0's in the data frame? Shouldn't that be 1 (vendor with that account)? Bert Bert Gunter "The trouble with having an open mind is that people keep coming along and sticking things into it." -- Opus (aka Berkeley Breathed in his "Bloom County"

Re: [R] counting duplicate items that occur in multiple groups

2020-11-17 Thread Tom Woolman
Hi Bill. Sorry to be so obtuse with the example data, I was trying (too hard) not to share any actual values so I just created randomized values for my example; of course I should have specified that the random values would not provide the expected problem pattern. I should have just used s

Re: [R] counting duplicate items that occur in multiple groups

2020-11-17 Thread Bill Dunlap
What should the result be for Data1 <- data.frame(Vendor=c("V1","V2","V3","V4"), Account=c("A1","A2","A2","A2")) ? Must each vendor have only one account? If not, what should the result be for Data2 <- data.frame(Vendor=c("V1","V2","V3","V1","V4","V2"), Account=c("A1","A2","A2","A2","A3","A4

Re: [R] counting duplicate items that occur in multiple groups

2020-11-17 Thread Bert Gunter
Inline. Bert Gunter "The trouble with having an open mind is that people keep coming along and sticking things into it." -- Opus (aka Berkeley Breathed in his "Bloom County" comic strip ) On Tue, Nov 17, 2020 at 1:20 PM Tom Woolman wrote: > Hi everyone. I have a dataframe that is a collectio

[R] counting duplicate items that occur in multiple groups

2020-11-17 Thread Tom Woolman
Hi everyone. I have a dataframe that is a collection of Vendor IDs plus a bank account number for each vendor. I'm trying to find a way to count the number of duplicate bank accounts that occur in more than one unique Vendor_ID, and then assign the count value for each row in the dataframe

Re: [R] counting unique values (summary stats)

2019-03-22 Thread David L Carlson
emius Sent: Thursday, March 21, 2019 5:55 PM To: reichm...@sbcglobal.net; 'r-help mailing list' Subject: Re: [R] counting unique values (summary stats) On 3/21/19 3:31 PM, reichm...@sbcglobal.net wrote: > r-help > > I have the following little scrip to create a df of summary stats. I&

Re: [R] counting unique values (summary stats)

2019-03-21 Thread David Winsemius
On 3/21/19 3:31 PM, reichm...@sbcglobal.net wrote: r-help I have the following little scrip to create a df of summary stats. I'm having problems obtaining the # of unique values unique=sapply(myData, function (x) length(unique(x), replace = TRUE)) I just looked up

[R] counting unique values (summary stats)

2019-03-21 Thread reichmanj
r-help I have the following little scrip to create a df of summary stats. I'm having problems obtaining the # of unique values unique=sapply(myData, function (x) length(unique(x), replace = TRUE)) Can I do that, or am I using the wrong R function? summary.stats <- data

[R] Counting nuber of sentences by qdap package

2017-10-29 Thread Elahe chalabi via R-help
Hi all, I have a data frame with a variable Description containing text of speeches and I would like to count number of sentences in each speech, > str(data) 'data.frame': 255 obs. of 3 variables: $ Group : Factor w/ 255 levels "AlzheimerGroup1","AlzheimerGroup10",..: 1 112 179 190

Re: [R] Counting with multiple criteria using data table

2017-06-21 Thread Jeff Newmiller
To be fair, the OP did provide brief snippets of data.table usage below the data dump indicating some level of effort, but posted it all in HTML (what you see we do not see), did not make the example reproducible (dput is great, and library calls really clear things up [1][2][3]), and this looks

Re: [R] Counting with multiple criteria using data table

2017-06-21 Thread David Winsemius
> On Jun 21, 2017, at 2:50 PM, Ek Esawi wrote: > > I have a data.table which is shown below. I want to count combinations of > columns on i and count on j with by. A few examples are given below the > table. > > > > I want to: > > all months to show on the output including those that they ha

Re: [R] Counting with multiple criteria using data table

2017-06-21 Thread Bert Gunter
Have you gone through any R tutorials? If not, why not? If so, maybe you need to spend some more time with them. It looks like you want us to do your work for you. We don't do this. See (and follow) the posting guide below for what we might do (we're volunteers, so no guarantees). Cheers, Bert

[R] Counting with multiple criteria using data table

2017-06-21 Thread Ek Esawi
I have a data.table which is shown below. I want to count combinations of columns on i and count on j with by. A few examples are given below the table. I want to: all months to show on the output including those that they have zero value I want the three statements combined in on if possible

Re: [R] Counting enumerated items in each element of a character vector

2017-04-26 Thread Boris Steipe
Let's be a bit careful. You'll probably need a regular expression. But maybe a regex can't work in principle, so one can't just gloss over the details. You said: "blah blah blah" can contain ANY text. If this is true, "blah blah blah" could contain the delimiters. If that is the case, a regex i

Re: [R] Counting enumerated items in each element of a character vector

2017-04-26 Thread Boris Steipe
What's the expected output for this sample? How do _you_ define what should be counted? > On Apr 26, 2017, at 8:33 AM, Dan Abner wrote: > > Hi all, > > I was not clearly enough in my example code. Please see below where "blah > blah blah" can be ANY text or numbers: No predictable pattern

Re: [R] Counting enumerated items in each element of a character vector

2017-04-26 Thread Dan Abner
Hi all, I was not clearly enough in my example code. Please see below where "blah blah blah" can be ANY text or numbers: No predictable pattern at all to what may or may not be written in place of "blah blah blah". text1<-c("blah blah blah. blah blah blah 1) blah blah blah 1 2) blah blah blah 10)

Re: [R] Counting enumerated items in each element of a character vector

2017-04-25 Thread Michael Hannon
Thanks, Ista. I thought there might be a "tidy" way to do this, but I hadn't use stringr. -- Mike On Tue, Apr 25, 2017 at 8:47 PM, Ista Zahn wrote: > stringr::str_count (and stringi::stri_count that it wraps) interpret > the pattern argument as a regular expression by default. > > Best, > Ista

Re: [R] Counting enumerated items in each element of a character vector

2017-04-25 Thread Ista Zahn
stringr::str_count (and stringi::stri_count that it wraps) interpret the pattern argument as a regular expression by default. Best, Ista On Tue, Apr 25, 2017 at 11:40 PM, Michael Hannon wrote: > I like Boris's "Hadley" solution. For the record, I've appended a > version that uses regular expres

Re: [R] Counting enumerated items in each element of a character vector

2017-04-25 Thread Michael Hannon
I like Boris's "Hadley" solution. For the record, I've appended a version that uses regular expressions, the only benefit of which is that it could be generalized to find more-complicated patterns. -- Mike counts <- sapply(text1, function(next_string) { loc_example <- length(gregexpr("Exampl

Re: [R] Counting enumerated items in each element of a character vector

2017-04-25 Thread Boris Steipe
I should add: there's a str_count() function in the stringr package. library(stringr) str_count(text1, "Example") # [1] 5 5 5 5 I guess that would be the neater solution. B. > On Apr 25, 2017, at 8:23 PM, Boris Steipe wrote: > > How about: > > unlist(lapply(strsplit(text1, "Example"), func

Re: [R] Counting enumerated items in each element of a character vector

2017-04-25 Thread Boris Steipe
How about: unlist(lapply(strsplit(text1, "Example"), function(x) { length(x) - 1 } )) Splitting your string on the five "Examples" in each gives six elements. length(x) - 1 is the number of matches. You can use any regex instead of "example" if you need to tweak what you are looking for. B.

[R] Counting enumerated items in each element of a character vector

2017-04-25 Thread Dan Abner
Hi all, I am looking for a streamlined way of counting the number of enumerated items are each element of a character vector. For example: text1<-c("This is an example. List 1 1) Example 1 2) Example 2 10) Example 10 List 2 1) Example 1 2) Example 2 These have been examples.","This is another ex

Re: [R] Counting number of rain

2015-10-02 Thread Rolf Turner
On 03/10/15 04:42, David Winsemius wrote: On Oct 2, 2015, at 2:33 AM, Duncan Murdoch wrote: The zoo package replaces as.Date.numeric() with a function that assumes an origin of "1970-01-01". There may be other packages that also make a replacement like this. David appears to have one of t

Re: [R] Counting number of rain

2015-10-02 Thread David Winsemius
On Oct 2, 2015, at 2:33 AM, Duncan Murdoch wrote: > On 01/10/2015 11:29 PM, Rolf Turner wrote: >> On 02/10/15 15:47, David Winsemius wrote: >> >> >> >>> On Oct 1, 2015, at 6:22 PM, Rolf Turner wrote: P.S. I have been unable to find a corresponding vector of the names of the day

Re: [R] Counting number of rain

2015-10-02 Thread Duncan Murdoch
On 01/10/2015 11:29 PM, Rolf Turner wrote: > On 02/10/15 15:47, David Winsemius wrote: > > > >> On Oct 1, 2015, at 6:22 PM, Rolf Turner wrote: >>> >>> P.S. I have been unable to find a corresponding vector of the names >>> of the days of the week, although I have a very vague recollection >>> of

Re: [R] Counting number of rain

2015-10-01 Thread David Winsemius
On Oct 1, 2015, at 8:29 PM, Rolf Turner wrote: > On 02/10/15 15:47, David Winsemius wrote: > > > >> On Oct 1, 2015, at 6:22 PM, Rolf Turner wrote: >>> >>> P.S. I have been unable to find a corresponding vector of the names >>> of the days of the week, although I have a very vague recollection

Re: [R] Counting number of rain

2015-10-01 Thread Rolf Turner
On 02/10/15 15:47, David Winsemius wrote: On Oct 1, 2015, at 6:22 PM, Rolf Turner wrote: P.S. I have been unable to find a corresponding vector of the names of the days of the week, although I have a very vague recollection of the existence of such a vector. Does it exist, and if so what is

Re: [R] Counting number of rain

2015-10-01 Thread David Winsemius
On Oct 1, 2015, at 6:22 PM, Rolf Turner wrote: > On 02/10/15 10:54, peter dalgaard wrote: > >>> On 01 Oct 2015, at 23:04 , Rolf Turner >>> wrote: >>> >>> On 02/10/15 03:45, David L Carlson wrote: >>> >>> >>> If you want the month names: > mnt <- c("Jan", "Feb", "Mar", "Apr",

Re: [R] Counting number of rain

2015-10-01 Thread Rolf Turner
On 02/10/15 10:54, peter dalgaard wrote: On 01 Oct 2015, at 23:04 , Rolf Turner wrote: On 02/10/15 03:45, David L Carlson wrote: If you want the month names: mnt <- c("Jan", "Feb", "Mar", "Apr", "May", "Jun", + "July", "Aug", "Sep", "Oct", "Nov", "Dec") dimnames(tbl)$Month <- mnt U

Re: [R] Counting number of rain

2015-10-01 Thread peter dalgaard
> On 01 Oct 2015, at 23:04 , Rolf Turner wrote: > > On 02/10/15 03:45, David L Carlson wrote: > > > >> If you want the month names: >> >>> mnt <- c("Jan", "Feb", "Mar", "Apr", "May", "Jun", >> + "July", "Aug", "Sep", "Oct", "Nov", "Dec") >>> dimnames(tbl)$Month <- mnt > > > > Unnecessary

Re: [R] Counting number of rain

2015-10-01 Thread Rolf Turner
On 02/10/15 03:45, David L Carlson wrote: If you want the month names: mnt <- c("Jan", "Feb", "Mar", "Apr", "May", "Jun", + "July", "Aug", "Sep", "Oct", "Nov", "Dec") dimnames(tbl)$Month <- mnt Unnecessary typing; there is a built-in data set "month.abb" (in the "base" package) that is

Re: [R] Counting number of rain

2015-10-01 Thread David L Carlson
31 - David L Carlson Department of Anthropology Texas A&M University College Station, TX 77840-4352 From: smart hendsome [mailto:putra_autum...@yahoo.com] Sent: Wednesday, September 30, 2015 9:24 PM To: David L Carlson Subject: Re: [R] Counting number of rain

Re: [R] Counting occurrences of a set of values

2015-09-10 Thread Frank Schwidom
df <- data.frame( V1= 1, V2= c( 2, 3, 2, 1), V3= c( 1, 2, 1, 1)) dfO <- df[ do.call( order, df), ] dfOD <- duplicated( dfO) dfODTrigger <- ! c( dfOD[-1], FALSE) dfOCounts <- diff( c( 0, which( dfODTrigger))) cbind( dfO[ dfODTrigger, ], dfOCounts) V1 V2 V3 dfOCounts 4 1 1 1 1 3 1 2

Re: [R] Counting occurrences of a set of values

2015-09-10 Thread Thierry Onkelinx
Have a look at the dplyr package library(dplyr) n <- 1000 data_frame( V1 = sample(0:1, n, replace = TRUE), V2 = sample(0:1, n, replace = TRUE), V3 = sample(0:1, n, replace = TRUE) ) %>% group_by(V1, V2, V3) %>% mutate( Freq = n() ) ir. Thierry Onkelinx Instituut voor natuur- en b

Re: [R] Counting occurrences of a set of values

2015-09-10 Thread Fox, John
10, 2015 9:11 AM > To: r-help@r-project.org > Subject: [R] Counting occurrences of a set of values > > Can anyone suggest a way of counting how frequently sets of values occurs in a > data frame? Like table() only with sets. > > So for a dataset: > > V1, V2, V3 > 1, 2

Re: [R] Counting occurrences of a set of values

2015-09-10 Thread Duncan Murdoch
On 10/09/2015 9:11 AM, Thomas Chesney wrote: > Can anyone suggest a way of counting how frequently sets of values occurs in > a data frame? Like table() only with sets. Do you want 1,2,1 to be the same as 1,1,2, or different? What about 1,2,2? For sets, those are all the same, but for most purp

[R] Counting occurrences of a set of values

2015-09-10 Thread Thomas Chesney
Can anyone suggest a way of counting how frequently sets of values occurs in a data frame? Like table() only with sets. So for a dataset: V1, V2, V3 1, 2, 1 1, 3, 2 1, 2, 1 1, 1, 1 The output would be something like: 1,2,1: 2 1,3,2: 1 1,1,1: 1 Thank you, Thomas Chesney This message and an

Re: [R] Counting number of rain

2015-09-08 Thread John Kane
age- > From: r-help@r-project.org > Sent: Tue, 8 Sep 2015 06:58:58 + (UTC) > To: r-help@r-project.org > Subject: [R] Counting number of rain > > Hello R-users, > I want to ask how to count the number of daily rain data.  My data as > below: > Year Month Day Amoun

Re: [R] Counting number of rain

2015-09-08 Thread Dan D
Try the following: ## step 1: write raw data to an array junk<-scan('clipboard') # entering the numbers (not the 'year' etc. labels) into R as a vector after junk<-t(array(junk,dim=c(4,length(junk)/4))) # convert the vector into a 2-d array with 4 columns (year, month, day, amount) ## step 2:

[R] Counting number of rain

2015-09-08 Thread smart hendsome via R-help
Hello R-users, I want to ask how to count the number of daily rain data.  My data as below: Year Month Day Amount 1901 1 1 0 1901 1 2 3 1901 1 3 0 1901 1 4 0.5 1901 1 5 0 1901 1 6 0 1901 1 7 0.3 1901 1 8 0 1901 1 9 0 1901 1 10 0 1901 1 11 0.5 1901 1 12 1.8 1901 1 13 0 1901 1 14 0 1901 1 15 2.5

Re: [R] counting similar strings in data.frame

2015-06-26 Thread PIKAL Petr
to:r...@knut-krueger.de] > Sent: Friday, June 26, 2015 12:50 PM > To: PIKAL Petr; r-h...@stat.math.ethz.ch > Subject: Re: [R] counting similar strings in data.frame > > Am 26.06.2015 um 10:38 schrieb PIKAL Petr: > > Hi > > > > I am little bit lost in your logic. Why tripl

Re: [R] counting similar strings in data.frame

2015-06-26 Thread Knut Krueger
Am 26.06.2015 um 10:38 schrieb PIKAL Petr: Hi I am little bit lost in your logic. Why triple in your fourth line is one. I expected it will be four? Petr Sorry yes you are right ... type mismatch Knut __ R-help@r-project.org mailing list -- To UNS

Re: [R] counting similar strings in data.frame

2015-06-26 Thread Knut Krueger
Sorry last count was wrong ... test =data.frame("first"=c("seven","two","five","four"), "second"=c("three","one","three","one"), "third"=c("four","two","three","four"), "fourth"=c("four","one","one","four")) count =data.frame("dobule1"=c("four",

Re: [R] counting similar strings in data.frame

2015-06-26 Thread PIKAL Petr
at.math.ethz.ch > Subject: [R] counting similar strings in data.frame > > Dear Members, > > is there a better solution to count the amounts of occurrence in a row > with string data than with loops to get the count data.frame? > > test =data.frame("first"=c("seven

[R] counting similar strings in data.frame

2015-06-26 Thread Knut Krueger
Dear Members, is there a better solution to count the amounts of occurrence in a row with string data than with loops to get the count data.frame? test =data.frame("first"=c("seven","two","five","four"), "second"=c("three","one","three","one"), "third"=c("four

Re: [R] Counting consecutive events in R

2015-05-14 Thread Johannes Huesing
I normally use rle() for these problems, see ?rle. for instance, k <- rbinom(999, 1, .5) series <- function(run) {

Re: [R] Counting consecutive events in R

2015-05-14 Thread Sarah Goslee
Assuming I understand the problem correctly, you want to check for runs of at least length five where both Score and Test_desc assume particular values. You don't care where they are or what other data are associated, you just want to know if at least one such run exists in your data frame. Here's

[R] Counting consecutive events in R

2015-05-14 Thread Abhinaba Roy
Hi, I have the following dataframe structure(list(Type = c("QRS", "QRS", "QRS", "QRS", "QRS", "QRS", "QRS", "QRS", "QRS", "QRS", "QRS", "QRS", "RR", "RR", "RR", "PP", "PP", "PP", "PP", "PP", "PP", "PP", "PP", "PP", "QTc", "QTc", "QTc", "QTc", "QTc", "QTc", "QTc", "QTc", "QTc", "QTc", "QTc", "QTc"

Re: [R] Counting Words

2015-01-22 Thread bgnumis bgnum
That' s perfect. Many thanks forma your appreciated help. El 22/01/2015 19:50, "Chel Hee Lee" escribió: > > x <- c("hola mundo mundo"); > > table(unlist(strsplit(x, " "))) > > hola mundo > 1 2 > > > > Is this what you are looking for? I hope this helps. > > Chel Hee Lee > > On 1/22/2015

Re: [R] Counting Words

2015-01-22 Thread MacQueen, Don
In addition to the other suggestions, which are fine for your simple example, I would take a trip to the CRAN Task View "Natural Language Processing", and see if there's anything there. -Don -- Don MacQueen Lawrence Livermore National Laboratory 7000 East Ave., L-627 Livermore, CA 94550 925-423

Re: [R] Counting Words

2015-01-22 Thread Ista Zahn
table(strsplit("hola mundo mundo", " ")[[1]]) On Thu, Jan 22, 2015 at 9:25 AM, bgnumis bgnum wrote: > Hi all, > > I want to cout the different words in a text. > > You see if the text is: "hola mundo mundo" the program will count: > > hola 1 > mundo 2 > > Is posible that Cran r have a similar fun

Re: [R] Counting Words

2015-01-22 Thread Chel Hee Lee
> x <- c("hola mundo mundo"); > table(unlist(strsplit(x, " "))) hola mundo 1 2 > Is this what you are looking for? I hope this helps. Chel Hee Lee On 1/22/2015 8:25 AM, bgnumis bgnum wrote: Hi all, I want to cout the different words in a text. You see if the text is: "hola mundo m

[R] Counting Words

2015-01-22 Thread bgnumis bgnum
Hi all, I want to cout the different words in a text. You see if the text is: "hola mundo mundo" the program will count: hola 1 mundo 2 Is posible that Cran r have a similar function? [[alternative HTML version deleted]] __ R-help@r-project.

Re: [R] counting sets of consecutive integers in a vector

2015-01-04 Thread Mike Miller
ginal Message- From: R-help [mailto:r-help-boun...@r-project.org] On Behalf Of Mike Miller Sent: Monday, 5 January 2015 1:03 p.m. To: R-Help List Subject: [R] counting sets of consecutive integers in a vector I have a vector of sorted positive integer values (e.g., postive integers after ap

Re: [R] counting sets of consecutive integers in a vector

2015-01-04 Thread jim holtman
Here is a solution using data.table > require(data.table) > x <- data.table(v, diff = cumsum(c(1, diff(v)) != 1)) > x v diff 1: 10 2: 20 3: 51 4: 61 5: 71 6: 81 7: 252 8: 303 9: 313 10: 323 11: 333 > x[, list(value = v[1L], length = .

Re: [R] counting sets of consecutive integers in a vector

2015-01-04 Thread jim holtman
oject.org] On Behalf Of Mike > Miller > Sent: Monday, 5 January 2015 1:03 p.m. > To: R-Help List > Subject: [R] counting sets of consecutive integers in a vector > > I have a vector of sorted positive integer values (e.g., postive integers > after applying sort() and unique()). F

Re: [R] counting sets of consecutive integers in a vector

2015-01-04 Thread Peter Alspach
f Mike Miller Sent: Monday, 5 January 2015 1:03 p.m. To: R-Help List Subject: [R] counting sets of consecutive integers in a vector I have a vector of sorted positive integer values (e.g., postive integers after applying sort() and unique()). For example, this: c(1,2,5,6,7,8,25,30,31,32,33) I w

[R] counting sets of consecutive integers in a vector

2015-01-04 Thread Mike Miller
I have a vector of sorted positive integer values (e.g., postive integers after applying sort() and unique()). For example, this: c(1,2,5,6,7,8,25,30,31,32,33) I want to make a matrix from that vector that has two columns: (1) the first value in every run of consecutive integer values, and (2

Re: [R] Counting within groups / means by groups

2014-11-10 Thread David L Carlson
rk and how to adapt them: > ave(dfa$value, dfa$group, FUN=length) [1] 3 3 3 4 4 4 4 1 > ave(dfa$value, dfa$group) [1] 2 2 2 3 3 3 3 1 - David L Carlson Department of Anthropology Texas A&M University College Station, TX 77840-4352 -Original Messag

Re: [R] Counting within groups / means by groups

2014-11-10 Thread Jeff Newmiller
Help file ?ave should apply here. Please read the Posting Guide mentioned in the footer of every email on this list and on the list manager page for this mailing list. It warns you to read the archives before posting and to post in plain text format rather than HTML format.

[R] Counting within groups / means by groups

2014-11-10 Thread David Studer
Hi everyone! I have problems finding a solution to the following two problems: My sample-dataframe consists of two variables "group" and "value": group<-c("A", "A", "A", "B", "B", "B", "B", "C") value<-c(1,3,2,2,2,4,4,1) df<-as.data.frame(cbind(group, value)) Problem 1: ** Now I'd like

Re: [R] counting the number of rows that satisfy a certain criteria

2014-06-21 Thread arun
Hi, Try: set.seed(42)  X <- as.data.frame(matrix(sample(0:1, 4*50,replace=TRUE), ncol=4))  table(X[1:2])[4] #[1] 15 sum(rowSums(X[1:2])==2) #[1] 15 A.K. On Saturday, June 21, 2014 10:59 AM, Kate Ignatius wrote: I have 4 columns, and about 300K plus rows with 0s and 1s. I'm trying to count h

Re: [R] counting the number of rows that satisfy a certain criteria

2014-06-21 Thread Kate Ignatius
Thanks! On Sat, Jun 21, 2014 at 11:05 AM, Jorge I Velez wrote: > Hi Kate, > > You could try > > sum(X[, 1] == 1 & X[, 2] == 1) > > where X is your data set. > > HTH, > Jorge.- > > > > On Sun, Jun 22, 2014 at 12:57 AM, Kate Ignatius > wrote: >> >> I have 4 columns, and about 300K plus rows with

Re: [R] counting the number of rows that satisfy a certain criteria

2014-06-21 Thread Jorge I Velez
Hi Kate, You could try sum(X[, 1] == 1 & X[, 2] == 1) where X is your data set. HTH, Jorge.- On Sun, Jun 22, 2014 at 12:57 AM, Kate Ignatius wrote: > I have 4 columns, and about 300K plus rows with 0s and 1s. > > I'm trying to count how many rows satisfy a certain criteria... for > instan

[R] counting the number of rows that satisfy a certain criteria

2014-06-21 Thread Kate Ignatius
I have 4 columns, and about 300K plus rows with 0s and 1s. I'm trying to count how many rows satisfy a certain criteria... for instance, how many rows are there that have the first column == 1 as well as the second column == 1. I've tried using rowSums and colSums but it keeps giving me this type

[R] Counting number of days my program runs

2014-05-15 Thread Ashis Deb
Hi all , I have a package and i want to count the 1st execution day of the package till 30 days afterwards ? I hope I am clear with this question . Please reply if you have anything to share . Thanks ASHIS [[alternative HTML version deleted]]

Re: [R] counting words that are contained in a list

2014-02-15 Thread arun
Hi, May be this helps: vec1 <- c("victory","happiness","medal","war","service","ribbon", "dates") vec2 <- c("The World War II Victory Medal was first issued as a service ribbon referred to as the Victory Ribbon.", "By 1946, a full medal had been established which was referred to as the World W

Re: [R] counting matched elements in two vectors

2014-01-23 Thread Hervé Pagès
On 01/23/2014 04:49 PM, Hervé Pagès wrote: Hi Mintewab, With the IRanges packages (from Bioconductor): > library(IRanges) > countMatches(z, w) [1] 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 2 1 0 3 1 1 0 1 0 0 0 0 0 0 1 3 2 0 0 1 0 0 [39] 0 0 0 0 0 0 0 0 And if you don't want to depend on I

Re: [R] counting matched elements in two vectors

2014-01-23 Thread Peter Langfelder
Here's a solution: # This gives a vector of counts (if z is a data frame, first convert it to a matrix) res = sapply(as.vector(z), function(x) sum(w==x)) # This copies the dimensions of the variable 'z' to 'res': dim(res) = dim(z) Peter On Thu, Jan 23, 2014 at 7:43 AM, wrote: >Hi all, > I

Re: [R] counting matched elements in two vectors

2014-01-23 Thread Hervé Pagès
Hi Mintewab, With the IRanges packages (from Bioconductor): > library(IRanges) > countMatches(z, w) [1] 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 2 1 0 3 1 1 0 1 0 0 0 0 0 0 1 3 2 0 0 1 0 0 [39] 0 0 0 0 0 0 0 0 To install the IRanges package: source("http://bioconductor.org/biocLite.R";)

Re: [R] counting matched elements in two vectors

2014-01-23 Thread Jeff Newmiller
Thank you for the reproducible example, but your description is missing a clear definition of what you want. For example, if your desired output is result <- c(rep(0,16),2,1,0,3,1,1,0,1,0,0,0,0,0,0,1,3,2,0,0,1,rep(0,10)) then one answer might be as.vector(table(factor(w,levels=z))) --

Re: [R] counting matches in two vectors

2014-01-23 Thread M.Bezabih
Many thanks, Arun. Res 1 is exactly what I wanted. Mintewab -Original Message- From: r-help-boun...@r-project.org [mailto:r-help-boun...@r-project.org] On Behalf Of arun Sent: 23 January 2014 16:27 To: R help Subject: Re: [R] counting matches in two vectors Hi, May be this helps:  z1

Re: [R] counting matches in two vectors

2014-01-23 Thread arun
Also,  res3 <- table(z1[match(w,z1)])  identical(res3,res1) #[1] TRUE A.K. On Thursday, January 23, 2014 11:26 AM, arun wrote: Hi, May be this helps:  z1 <- factor(z) res1 <- table(z1[cut(w,breaks=c(-Inf,z,Inf),labels=F)]) res1 # #-5 -4 -3 -2 -1  0  1  2  3  4  5  6  7  8  9 10 11 12 13 14

Re: [R] counting matches in two vectors

2014-01-23 Thread arun
Hi, May be this helps:  z1 <- factor(z) res1 <- table(z1[cut(w,breaks=c(-Inf,z,Inf),labels=F)]) res1 # #-5 -4 -3 -2 -1  0  1  2  3  4  5  6  7  8  9 10 11 12 13 14 15 16 17 18 19 20 # 0  0  0  0  0  0  0  0  0  0  2  1  0  3  1  1  0  1  0  0  0  0  0  0  1  3 #21 22 23 24 25 26 27 28 29 30 31 32

[R] counting matched elements in two vectors

2014-01-23 Thread M.Bezabih
Hi all, I have the following reproducible example z<-c(-5:40) w<-c(11, 11, 12, 14, 14, 14, 15, 16, 18, 25, 26, 26, 26, 27, 27, 30) r<-z %in% w now r gives me the presence or absence of elements in z that are in w but I am interested in getting the number of times each element in z appears (o

Re: [R] Counting variables repeted in dataframe columns to create a presence-absence table

2013-11-28 Thread arun
Hi, Try: data_m <- read.table(text="Abortusovis07918 Agona08561 Anatum08125 Arizonae65S Braenderup08488 1  S5305B_IGR S5305B_IGR  S5305B_IGR  S5305B_IGR S5305B_IGR 2  S5305A_IGR S5300A_IGR  S5305A_IGR  S5300A_IGR S5300A_IGR 3  S5300A_IGR S5300B_IGR  S5300A_IGR  S5300B_IGR S5300B_IGR 4 

[R] Counting variables repeted in dataframe columns to create a presence-absence table

2013-11-28 Thread Gmail
Hi! I'm new in R and I'm writing you asking for some guidance. I had analyzed a comparative genomic microarray data of /56 Salmonella/ strains to identify absent genes in each of the serovars, and finally I got a matrix that looks like that: > data[1:5,1:5] Abortusovis07918 Agona08561 Anat

Re: [R] Counting numbers in R

2013-10-04 Thread Shane Carey
I got sorted, Thanks all On Fri, Oct 4, 2013 at 2:03 PM, S Ellison wrote: > > I have a set of data and I need to find out how many points are below a > > certain value but R will not calculate this properly for me. > R will. But you aren't. > > > Negative numbers seem to be causing the issue.

Re: [R] Counting numbers in R

2013-10-04 Thread S Ellison
> I have a set of data and I need to find out how many points are below a > certain value but R will not calculate this properly for me. R will. But you aren't. > Negative numbers seem to be causing the issue. You haven't got any negative numbers in your data set. In fact, you haven't got any nu

Re: [R] counting process in survival

2013-05-31 Thread Terry Therneau
It is hard to know exactly what you mean with such a generic question. If you mean "treat survival as a counting process", then the answer is yes. The survival package in S (which is the direct ancestor of the Splus package, which is the direct ancestor of the R package) was the very first to d

Re: [R] Counting number of consecutive occurrences per rows

2013-05-06 Thread PIKAL Petr
s it what you want? Petr From: zuzana zajkova [mailto:zuzu...@gmail.com] Sent: Friday, May 03, 2013 7:10 PM To: PIKAL Petr; jholt...@gmail.com Cc: r-help@r-project.org Subject: Re: [R] Counting number of consecutive occurrences per rows Hi, I'm sorry that it takes me so much time to respond,

Re: [R] Counting number of consecutive occurrences per rows

2013-05-03 Thread zuzana zajkova
limits, include.lowest=T))) > res <- rep(rrr$lengths, rrr$lengths) > res > } > > you can use split/lapply approach > > test$res2<-unlist(lapply(split(test$act, factor(test$day, levels=c(1,0))), > fff)) > > Beware of correct ordering of days in output. Without

Re: [R] Counting number of consecutive occurrences per rows

2013-04-29 Thread PIKAL Petr
[0,1] 4 2 14655 (1,199] 1 3 14655 (199,200] 2 Regards Petr > -Original Message- > From: r-help-boun...@r-project.org [mailto:r-help-bounces@r- > project.org] On Behalf Of zuzana zajkova > Sent: Monday, April 29, 2013 12:45 PM > To: r-help@r-project.org > Subject

Re: [R] Counting number of consecutive occurrences per rows

2013-04-29 Thread jim holtman
try this: > 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 = structure(c(1266258354, 1266258954, 1266259554, 1266260154, + 126626075

Re: [R] Counting number of consecutive occurrences per rows

2013-04-29 Thread jim holtman
Forgot the last part of the question: > 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 = structure(c(1266258354, 1266258954, 1266259554,

[R] Counting number of consecutive occurrences per rows

2013-04-29 Thread zuzana zajkova
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, 1

Re: [R] Counting various elemnts in a vactor

2013-03-26 Thread arun
AM Subject: [R] Counting various elemnts in a vactor Dear R forum I have a vector say as given below df = c("F", "C", "F", "B", "D", "A", "D", "D", "A", "F", "D", "F", "B"

Re: [R] Counting various elemnts in a vactor

2013-03-26 Thread Katherine Gobin
Dear Sir, Thanks a lot for your great help. I couldn't have figured it out. Thanks again. Regards Katherine --- On Tue, 26/3/13, D. Rizopoulos wrote: From: D. Rizopoulos Subject: Re: [R] Counting various elemnts in a vactor To: "Katherine Gobin" Cc: "r-help@r-project

Re: [R] Counting various elemnts in a vactor

2013-03-26 Thread D. Rizopoulos
try this: df <- c("F", "C", "F", "B", "D", "A", "D", "D", "A", "F", "D", "F", "B", "C") tab <- table(df) tab rep(names(tab), 100 * tab) I hope it helps. Best, Dimitris On 3/26/2013 9:12 AM, Katherine Gobin wrote: > Dear R forum > > I have a vector say as given below > > df = c("F", "C",

[R] Counting various elemnts in a vactor

2013-03-26 Thread Katherine Gobin
Dear R forum I have a vector say as given below df = c("F", "C", "F", "B", "D", "A", "D", "D", "A", "F", "D", "F", "B",    "C") I need to find (1) how many times each element occurs? e.g. in above vector F occurs 4 times, C occurs 2 times etc. (2) Depending on the number of occurrences, I ne

Re: [R] Counting confidence intervals

2013-03-20 Thread David Winsemius
You should look at findInterval. Used with as.numeric it could do what you request although it has a much wider range of uses. -- David Sent from my iPhone On Mar 20, 2013, at 5:15 PM, Greg Snow <538...@gmail.com> wrote: > The TeachingDemos package has %<% and %<=% functions that can be chain

Re: [R] Counting confidence intervals

2013-03-20 Thread Greg Snow
The TeachingDemos package has %<% and %<=% functions that can be chained simply, so you could do something like: sum( 5:1 %<=% 1:5 %<=% 10:14 ) and other similar approaches. The idea is that you can do comparisons as: lower %<% x %<% upper instead of lower < x & x < upper On Mon, Mar 18, 2

Re: [R] Counting confidence intervals

2013-03-19 Thread S Ellison
> There _is_ a function ?within. Drat! of course there is. I even use it, though not often. > Maybe your function can be > named 'between' Good thought - thanks Steve E *** This email and any attachments are confidential. Any u

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' or

  1   2   3   4   5   >