Hi,
May be
library(Biostrings) from Bioconductor helps you.
source("http://bioconductor.org/biocLite.R";) biocLite("Biostrings")
?matchPattern()
?letterFrequency()
vec1<- "ababbbassdaa"
alphabetFrequency(DNAString(vec1))
#A C G T M R W S Y K V H D B N - +
#5 0 0 0 0 0 0 2 0 0 0 0 1 4 0 0 0
l
Thanks a lot, it works very well!
Inti
2012/8/21 Rui Barradas
> Hello,
>
> Try the following
>
>
> d <- read.table(text="
>
> id VI
> 1 -10
> 2 -4
> 3 5
> 4 -2
> 5 -5
> 6 -3
> 7 -2
> 8 -1
> 9 4
> 10 8
> ", header = TRUE)
>
>
> fun <- function(n, thres){
> r <- rle(!d$VI < thres)
> in
Rui:
It's much simpler than you propose, which is why I left it to the OP.
Just use the results of rle to create a logical vector to index id.
For example, the solution for the OP's example becomes : (d is the
data frame containing id and VI)
> with(d,{
+ z <- rle(VI < 1)
+ vals <- with(z,values
Hello,
Try the following
d <- read.table(text="
id VI
1 -10
2 -4
3 5
4 -2
5 -5
6 -3
7 -2
8 -1
9 4
10 8
", header = TRUE)
fun <- function(n, thres){
r <- rle(!d$VI < thres)
inx <- which(!r$values & r$lengths >= n)
csum <- cumsum(r$lengths)
from <- ifelse(inx == 1, 1, csum[in
z <- rle(VI<1)
gets you most of the way there. ?rle will tell you what z is so that
you can then use it to go the rest of the way.
-- Bert
On Tue, Aug 21, 2012 at 10:54 AM, inti luna wrote:
> Hello,
>
> I have 2 variable: one is an "id" sequence from 1:1000 and the other is
> variable with real
Searching: time series forecasting
on the R website gives quite a few potentially useful options.
hth, Ingmar
On Wed, Nov 16, 2011 at 1:55 PM, Aher wrote:
> I have a data with the sequence of events with millions records and more
> than
> 24 time stamped variables.
>
> sample data:
> 1 2
Hi
as far as I understand your question it seems to me that
round(5*(1.4^(0:10)))
gives you your sequence
and
cumsum(round(5*(1.4^(0:10
gives you summary sequence.
Regards
Petr
>
> I definitely used too much lines s of code because I still don't know
how to
> do some staff.
> but it
Two general R tips:
1) Don't name variables seq or var. These are two really important R
functions and you can get all sorts of unexpected craziness if you overload
them. Going forward, also watch out for t,c, T, F as well.
2) As others have noted, it's very possible to implement this without an
I definitely used too much lines s of code because I still don't know how to
do some staff.
but it works:
seq=5 #starting value
var=5# starting value
long= 1:10 # length of the vector
for (x in long){
var=var+((var/100)*40)
seq=append(seq,var)
}
seq=round(seq)
seq=cums
On Aug 22, 2011, at 9:53 PM, Claudio Zanettini wrote:
> Thanks guys,
> I did not know the fun cumsum
> I will work on that.
A very compact method would be:
cumsum( round(1.4^(0:20)*rep(5, 21)) )
(And I was wrong about it increasing more rapidly if it had been in
hte mamer I imagined.)
--
D
Thanks guys,
I did not know the fun cumsum
I will work on that.
HVZ
2011/8/22 David Winsemius
>
> On Aug 22, 2011, at 8:36 PM, Claudio Zanettini wrote:
>
> Hello everyone,
>> I would like to generate a sequence
>> such as, starting from 5, every value is
>> 40% of the value before+ all the pr
On Aug 22, 2011, at 8:36 PM, Claudio Zanettini wrote:
Hello everyone,
I would like to generate a sequence
such as, starting from 5, every value is
40% of the value before+ all the preceeding values.
es:
this is the seq of all the value+40% of the preceding value:
5 7101
?cumsum
cumsum(yoursequence)
HTH,
Jorge
On Mon, Aug 22, 2011 at 8:36 PM, Claudio Zanettini <> wrote:
> Hello everyone,
> I would like to generate a sequence
> such as, starting from 5, every value is
> 40% of the value before+ all the preceeding values.
> es:
> this is the seq of all the valu
d to keep my
problem
> short in oder not to consume your valuable time.
>
> Regards
>
> Vince Pyne
>
>
>
> --- On Thu, 12/9/10, Petr PIKAL wrote:
>
> From: Petr PIKAL
> Subject: Re: [R] Sequence generation in a table
> To: "Vincy Pyne"
> Cc
wever if there are number of
> bonds (say 1000) in the portfolio, my method of converting the days
> individually is not practical.
>
> I am extremely sorry for the inconvenience caused. I tried to keep my
> problem short in oder not to consume your valuable time.
>
> Regards
&
On Thu, Dec 9, 2010 at 1:24 PM, Vincy Pyne wrote:
> yy <- lapply(c(257, 520, 110), seq, to=0, by=-100)
>
> yy/360, I get following error.
>
> Error in yy/360 : non-numeric argument to binary operator
>
> On the other hand,
>
> yy[[1]]/365 fetches me
>
> [1] 0.7138889 0.436 0.158
>
, Petr PIKAL wrote:
From: Petr PIKAL
Subject: Re: [R] Sequence generation in a table
To: "Vincy Pyne"
Cc: r-help@r-project.org
Received: Thursday, December 9, 2010, 12:03 PM
Hi
r-help-boun...@r-project.org napsal dne 09.12.2010 12:41:47:
> Dear Sir,
>
> Sorry to bother y
y of me defining individually. So is there any way that I can have all
the
> sequence numbers generated can be accommodated in a single dataframe. I
> sincerely apologize for disturbing you Sir and hope I am able to put up
my
> problem in a proper manner.
>
> Regards
>
> Vin
On Thu, Dec 9, 2010 at 12:41 PM, Vincy Pyne wrote:
> The biggest constraint for me is here as an example I have taken only three
> cases i.e. c(257, 520, 110), however in reality I will be dealing with no of
> cases and that number is unknown. But your code will certainly generate me
> the requ
rbing you Sir and hope I am able to put up my
problem in a proper manner.
Regards
Vincy Pyne
--- On Thu, 12/9/10, Jan van der Laan wrote:
From: Jan van der Laan
Subject: Re: [R] Sequence generation in a table
To: r-help@r-project.org, vincy_p...@yahoo.ca
Received: Thursday, December 9, 2010,
Vincy,
I suppose the following does what you want. yy is now a list which
allows for differing lengths of the vectors.
> yy <- lapply(c(257, 520, 110), seq, to=0, by=-100)
> yy[[1]]
[1] 257 157 57
> yy[[2]]
[1] 520 420 320 220 120 20
Regards,
Jan
On 9-12-2010 11:40, Vincy Pyne wrote:
c(
Try this:
id <- 1:20
grade <- c(4,4,4,5,5,7,7,7,7,8,8,8,9,9,9,9,9,10,10,10)
sequence <- ave( id, grade, FUN=seq )
# if grade is not sorted
grade2 <- sample(grade)
sequence2 <- ave( id, grade2, FUN=seq )
cbind( grade2, sequence2 )
--
Gregory (Greg) L. Snow Ph.D.
Statistical Data Center
Intermo
Luana -
It's probably not the most efficient way, but here's
a solution that's not dependent on the grades being sorted:
grade <- c(4,4,4,5,5,7,7,7,7,8,8,8,9,9,9,9,9,10,10,10)
unlist(sapply(rle(grade)$lengths,function(x)seq(1,x)))
[1] 1 2 3 1 2 1 2 3 4 1 2 3 1 2 3 4 5 1 2 3
Hi Luana,
Try this:
ID <- 1:20
grade <- c(4, 4, 4, 5, 5, 7, 7, 7, 7, 8, 8, 8, 9, 9, 9, 9, 9, 10, 10, 10)
d <- data.frame(ID, grade)
d$Sequence <- do.call(c, sapply(rle(grade)$lengths, seq))
d
HTH,
Jorge
On Wed, Dec 1, 2010 at 11:08 AM, Luana Marotta <> wrote:
> Hello fellows,
>
> I would like
Try this:
> ord <- order(grade)
> ID <- Id[ord]
> grade <- grade[ord]
> sequence <- unlist(sapply(table(grade), FUN = function(x) 1:x),
use.names = F)
And as a general tip, it is much easier to work with related values like
ID and grade if they are in a data frame. Such as:
> dat <- data.frame
enum.list <- function(x,y) {
mylist <- NULL
for(i in 1:length(x)) {
mylist[[i]] <- x[i]:y[i]
}
xx <- unlist(mylist)
}
a <- c(1,2,3)
b <- a+2
(harry <- enum.list(a,b) )
--- On Mon, 7/19/10, Suphajak Ngamlak wrote:
> From: Suphajak Ngamlak
> Subject: [R] Sequence from 2 Vectors
> To: r-help@r
Hi:
Josh's solution is much simpler (and more practical, no doubt) than the one
below, but I wanted to experiment with creating sequences using a vector of
start indices and a corresponding vector of end indices:
b <- 1:3 # vector of start indices
e <- 3:5 # vector of end indices
The
Hi Suphajak,
There are probably cleaner ways, but you can try this:
a <- c(1,2,3)
c <- unlist(lapply(a, function(x) {seq(from = x, to = x+2)}))
c
[1] 1 2 3 2 3 4 3 4 5
HTH,
Josh
On Mon, Jul 19, 2010 at 8:25 PM, Suphajak Ngamlak
wrote:
> I would like to create a vector that is a sequence from
Hi Bogdan --
On 04/14/2010 08:19 PM, Bogdan Tanasa wrote:
> Dear all,
>
> please could you suggest any R functions or packages (or external
> programs), that
likely you'll have more luck on the Bioconductor mailing list,
http://bioconductor.org/docs/mailList.html
but...
> a. take as input a la
On Apr 14, 2010, at 11:19 PM, Bogdan Tanasa wrote:
Dear all,
please could you suggest any R functions or packages (or external
programs),
that
a. take as input a large number (> 10 000) of short 20-30 nt
sequences, and
do
sequence assembly, to reconstruct larger (extended) 30-50 sequenc
Here is one way of doing it:
> df<-data.frame(id=c("b","b","a","a","a"),ord=c(2,1,1,3,2))
> dates<-as.Date(c("02/27/92", "02/27/92", "01/14/92", "02/28/92",
+ "02/01/92"),"%m/%d/%y")
> df$dates<-dates
> df$seq <- ave(as.numeric(df$dates), df$id, FUN=order)
> df
id ord dates seq
1 b 2 199
One can also use
formatC()
with the flag option.
-Don
At 10:47 AM -0200 1/25/10, Henrique Dallazuanna wrote:
Try sprintf:
sprintf("%03d", Sequence)
sprintf("file%03d.dat", Sequence)
On Mon, Jan 25, 2010 at 10:39 AM, Îroutík wrote:
Dear R-users,
I'd like to create filenames in a mask
Try sprintf:
sprintf("%03d", Sequence)
sprintf("file%03d.dat", Sequence)
On Mon, Jan 25, 2010 at 10:39 AM, Žroutík wrote:
> Dear R-users,
>
> I'd like to create filenames in a mask "file000.dat" numbered from 1 to e.g.
> 123. The last problem I'm dealing with is creating the sequence of numbe
Manuel Jesús López Rodríguez wrote:
Dear all,
I would like to know how could I execute a sequence or orders with just a
function, i.e, that just typing the function name, R gives me all the
parameters I want (for instance, if I want to see the summary, the standard
deviation, the number of val
On 11/30/2009 07:17 AM, Manuel Jesús López Rodríguez wrote:
Dear all,
I would like to know how could I execute a sequence or orders with just a
function, i.e, that just typing the function name, R gives me all the
parameters I want (for instance, if I want to see the summary, the standard
devi
You don't see the standard deviations because
only the final result (the output of summary() in
your case) is output by the function, not the
intermediate results (the results of the apply()
function in your case).
Try this:
resumen<-function(x) {
print( apply(x,2,sd,na.rm=TRUE))
> -Original Message-
> From: r-help-boun...@r-project.org [mailto:r-help-boun...@r-project.org]
> On Behalf Of Manuel Jesús López Rodríguez
> Sent: Sunday, November 29, 2009 12:17 PM
> To: r-help@r-project.org
> Subject: [R] sequence of commands in R
>
> Dear all,
> I would like to know
Hi
r-help-boun...@r-project.org napsal dne 29.08.2009 21:49:54:
> On Sat, Aug 29, 2009 at 8:14 PM, njhuang86 wrote:
> >
> > Hey guys,
> >
> > I was wondering how to create this sequence: 1, 2, 3, 1, 2, 3, 1, 2,
3, 1,
> > 2, 3... with the '1, 2, 3' repeated over 10 times.
>
> rep(1:3,10) # rep
Of Barry Rowlingson
> Sent: Saturday, August 29, 2009 1:50 PM
> To: njhuang86
> Cc: r-help@r-project.org
> Subject: Re: [R] Sequence generation
>
> On Sat, Aug 29, 2009 at 8:14 PM, njhuang86 wrote:
> >
> > Hey guys,
> >
> > I was wondering how to create this s
On Sat, Aug 29, 2009 at 8:14 PM, njhuang86 wrote:
>
> Hey guys,
>
> I was wondering how to create this sequence: 1, 2, 3, 1, 2, 3, 1, 2, 3, 1,
> 2, 3... with the '1, 2, 3' repeated over 10 times.
rep(1:3,10) # rep repeats its first argument according to the number
in its second argument
> Also,
On Aug 29, 2009, at 3:14 PM, njhuang86 wrote:
Hey guys,
I was wondering how to create this sequence: 1, 2, 3, 1, 2, 3, 1, 2,
3, 1,
2, 3... with the '1, 2, 3' repeated over 10 times.
As noted earlier
rep(1:3, 10)
Also, is there a simple method to generate 1, 1, 1, 2, 2, 2, 3, 3, 3?
I think should work
rep(c(1,2,3),10)
Alfredo
On Sat Aug 29 15:14:15 EDT 2009, njhuang86
wrote:
Hey guys,
I was wondering how to create this sequence: 1, 2, 3, 1, 2, 3, 1,
2, 3, 1,
2, 3... with the '1, 2, 3' repeated over 10 times.
Also, is there a simple method to generate 1, 1, 1,
> -Original Message-
> From: r-help-boun...@r-project.org
> [mailto:r-help-boun...@r-project.org] On Behalf Of David Freedman
> Sent: Friday, May 01, 2009 11:52 AM
> To: r-help@r-project.org
> Subject: [R] sequence number for 'long format'
>
>
> Dear R-help list,
>
> I've got a data se
Try this:
ds$seq <- ave(ds$id, ds$id, FUN = seq_along)
On Fri, May 1, 2009 at 2:52 PM, David Freedman <3.14da...@gmail.com> wrote:
>
> Dear R-help list,
>
> I've got a data set in long format - each subject can have several (varying
> in number) measurements, with each record representing one me
one way is the following:
5 - abs(-4:4)
I hope it helps.
Best,
Dimitris
Monte Milanuk wrote:
I hit a minor sticking point working one of the problems in 'Using R'
(Verzani). I'm having difficulty with generating a sequence that goes
1, 2, 3, 4, 5, 4, 3, 2, 1. I can make one that counts up
And somewhat faster still (YMMV):
unlist(mapply(":", start, stop))
HTH,
Ray Brownrigg
Victoria University of Wellington
Christos Hatzis wrote:
Try:
unlist(mapply(seq, c(1,20,50), c(7,25,53)))
[1] 1 2 3 4 5 6 7 20 21 22 23 24 25 50 51 52 53
-Christos
-Original Message-
Fr
On Tue, 26 Aug 2008, Chris Oldmeadow wrote:
Hi,
I have a vector of start positions, and another vector of stop positions,
eg start<-c(1,20,50)
stop<-c(7,25,53)
Is there a quick way to create a sequence from these vectors?
new<-c(1,2,3,4,5,6,7,20,21,22,23,24,25,50,51,52,53)
Vectorize t
Try:
> unlist(mapply(seq, c(1,20,50), c(7,25,53)))
[1] 1 2 3 4 5 6 7 20 21 22 23 24 25 50 51 52 53
-Christos
> -Original Message-
> From: [EMAIL PROTECTED]
> [mailto:[EMAIL PROTECTED] On Behalf Of Chris Oldmeadow
> Sent: Tuesday, August 26, 2008 12:42 AM
> To: r-help@r-project.
There's a kind of way, but it may be more 'elegant' than fast for large
sequences
> start <- c(1,20,50)
> stop <- c(7,25,53)
> unlist(mapply(Vectorize(seq), start, stop))
[1] 1 2 3 4 5 6 7 20 21 22 23 24 25 50 51 52 53
Bill Venables
http://www.cmis.csiro.au/bill.venables/
-Original
Well, this is a natural thing to program up using 3 nested 'for',
loops. Alternatively, one could use something like:
> combn <- function( ..., l=list(...) )
+ {
+ lens <- sapply( args, length)
+ ncomb <- prod(lens)
+ retval <- matrix(ncol=length(args), nrow=ncomb)
+ for(i in 1:leng
expand.grid() is what you are looking for.
expand.grid(x1, x2, x3)
HTH,
Thierry
ir. Thierry Onkelinx
Instituut voor natuur- en bosonderzoek / Research Institute for Nature
and Forest
Cel biometrie, methodologie en kw
try:
expand.grid(x1, x2, x3)
Best,
Dimitris
Dimitris Rizopoulos
Ph.D. Student
Biostatistical Centre
School of Public Health
Catholic University of Leuven
Address: Kapucijnenvoer 35, Leuven, Belgium
Tel: +32/(0)16/336899
Fax: +32/(0)16/337015
Web: http://med.kuleuven.be/biostat/
http:
?expand.grid should do what you want.
--- Marc Bernard <[EMAIL PROTECTED]> wrote:
> Dear All,
>
> I wonder if there is any R function to generate a
> sequence of vectors from existing ones. For example:
> x 1<- c(1,2,3)
> x2 <- c(4,5)
> x3 <- c(6,7,8)
>
> The desired output is
53 matches
Mail list logo