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
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
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',
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
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
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
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]
?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
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
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
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
?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
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
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
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
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
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 ,
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
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,
: [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
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
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
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
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
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
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
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
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
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
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
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
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
*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
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*
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
-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
#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
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.
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
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
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
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
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
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
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],
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
-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
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
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,
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]
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
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
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
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
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
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
?
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
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
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
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
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
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
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
--
?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
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
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
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) {
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
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
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
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
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,
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,
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
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,
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)
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
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,
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
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
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
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
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
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
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
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:
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
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))
}
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
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
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
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,
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
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.
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
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
Any better solution than this ?
sum(strsplit(TCGACAATCGGTAACCCGTCT, )[[1]] == G)
_
[[alternative HTML version deleted]]
__
R-help@r-project.org mailing list
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
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 ?
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
301 - 400 of 429 matches
Mail list logo