search for: seq_len

Displaying 20 results from an estimated 553 matches for "seq_len".

2018 Aug 04
3
Is this a bug in `[`?
...derstanding how negative indexing works but >> >> 1) This is right. >> >> (1:10)[-1] >> #[1] 2 3 4 5 6 7 8 9 10 >> >> 2) Are these right? They are at least surprising to me. >> >> (1:10)[-0] >> #integer(0) >> >> (1:10)[-seq_len(0)] >> #integer(0) >> >> >> It was the last example that made me ask, seq_len(0) whould avoid an >> if/else or something similar. > > I think it's ok, because there is no negative zero integer, so -0 is 0. Ok, this makes sense, I should have thought about t...
2018 Aug 05
2
Is this a bug in `[`?
Thanks. This is exactly the doubt I had. Rui Barradas ?s 05:26 de 05/08/2018, Kenny Bell escreveu: > This should more clearly illustrate the issue: > > c(1, 2, 3, 4)[-seq_len(4)] > #> numeric(0) > c(1, 2, 3, 4)[-seq_len(3)] > #> [1] 4 > c(1, 2, 3, 4)[-seq_len(2)] > #> [1] 3 4 > c(1, 2, 3, 4)[-seq_len(1)] > #> [1] 2 3 4 > c(1, 2, 3, 4)[-seq_len(0)] > #> numeric(0) > Created on 2018-08-05 by the reprex package (v0.2.0.9000). &g...
2018 Aug 05
2
Is this a bug in `[`?
El dom., 5 ago. 2018 a las 6:27, Kenny Bell (<kmbell56 at gmail.com>) escribi?: > > This should more clearly illustrate the issue: > > c(1, 2, 3, 4)[-seq_len(4)] > #> numeric(0) > c(1, 2, 3, 4)[-seq_len(3)] > #> [1] 4 > c(1, 2, 3, 4)[-seq_len(2)] > #> [1] 3 4 > c(1, 2, 3, 4)[-seq_len(1)] > #> [1] 2 3 4 > c(1, 2, 3, 4)[-seq_len(0)] > #> numeric(0) > Created on 2018-08-05 by the reprex package (v0.2.0.9000). I...
2010 Feb 12
1
Using seq_len() vs 1:n]
Pat Burns makes a good point. -Peter -------- Original Message -------- Subject: Re: [R] Using seq_len() vs 1:n Date: Fri, 12 Feb 2010 09:01:20 +0000 From: Patrick Burns <pburns at pburns.seanet.com> To: Peter Ehlers <ehlers at ucalgary.ca> References: <4B746AEF.10900 at ucalgary.ca> If you want your code to be compatible with S+, then 'seq_len' isn't going to work. O...
2007 Dec 08
1
seq_len
In a post on R-devel, Prof Ripley add the following comment | > BTW, 1:dim(names)[1] is dangerous: it could be 1:0. That was the | > motivation for seq_len. I use the dim(names)[1] and dim(x)[2] along with length(x) with varying levels of frustration depending on the object which I am trying to get the dimensions. I found the reference to seq_len interesting since it is a function that I have never seen (probably just missed it reading the docs)...
2010 Feb 11
2
Using seq_len() vs 1:n
R-people, Duncan Murdoch's response in https://stat.ethz.ch/pipermail/r-help/2010-February/227869.html reminded me of something I had been meaning to ask. A while ago I started using for(i in seq_len(v)) {....} in preference to for(i in 1:n) {....} Duncan's post shows that if n can be zero, there is an advantage to using seq_len. Is there ever a *dis*advantage? Peter Ehlers University of Calgary
2013 Sep 02
3
Product of certain rows in a matrix
...quot;,sep="",header=FALSE)),ncol=3,byrow=FALSE,dimnames=NULL) library(matrixStats) ?res1<-t(sapply(split(as.data.frame(A),as.numeric(gl(nrow(A),2,6))),colProds)) ?res1 #? [,1] [,2] [,3] #1??? 4?? 10?? 18 #2?? 63?? 64?? 63 #3?? 18?? 10??? 4 ?res2<-t(sapply(split(as.data.frame(A),((seq_len(nrow(A))-1)%/%2)+1),colProds)) ?identical(res1,res2) #[1] TRUE #or ?t(sapply(split(as.data.frame(A),as.numeric(gl(nrow(A),2,6))),function(x) apply(x,2,prod))) #or library(plyr) ?as.matrix(ddply(as.data.frame(A),.(as.numeric(gl(nrow(A),2,6))),colProds)[,-1]) #???? V1 V2 V3 #[1,]? 4 10 18 #[2,] 63...
2011 Mar 26
1
bwplot [lattice]: how to get different y-axis scales for each row?
...give the same y-axis scales within each row (see the fourth row). Further, it "separates" the panels. Cheers, Marius ## minimal example: library(lattice) ## build example data set dim <- c(100, 6, 2, 3) # n, groups, methods, attributes dimnames <- list(n=paste("n=", seq_len(100), sep=""), groups=paste("group=", seq_len(6), sep=""), methods=paste("method=", seq_len(2), sep=""), attr=paste("attribute=", seq_len(3), sep="")) set.seed(1) data <- rexp(prod(dim)) arr <...
2018 Aug 04
2
Is this a bug in `[`?
Hello, Maybe I am not understanding how negative indexing works but 1) This is right. (1:10)[-1] #[1] 2 3 4 5 6 7 8 9 10 2) Are these right? They are at least surprising to me. (1:10)[-0] #integer(0) (1:10)[-seq_len(0)] #integer(0) It was the last example that made me ask, seq_len(0) whould avoid an if/else or something similar. Thanks in advance, Rui Barradas
2018 Aug 05
0
Is this a bug in `[`?
This should more clearly illustrate the issue: c(1, 2, 3, 4)[-seq_len(4)] #> numeric(0) c(1, 2, 3, 4)[-seq_len(3)] #> [1] 4 c(1, 2, 3, 4)[-seq_len(2)] #> [1] 3 4 c(1, 2, 3, 4)[-seq_len(1)] #> [1] 2 3 4 c(1, 2, 3, 4)[-seq_len(0)] #> numeric(0) Created on 2018-08-05 by the reprex package (v0.2.0.9000). On Sun, Aug 5, 2018 at 3:58 AM Rui Barradas <rui...
2018 Aug 05
0
Is this a bug in `[`?
...is Circle 8..1.13 of the R Inferno. On 05/08/2018 06:57, Rui Barradas wrote: > Thanks. > This is exactly the doubt I had. > > Rui Barradas > > ?s 05:26 de 05/08/2018, Kenny Bell escreveu: >> This should more clearly illustrate the issue: >> >> c(1, 2, 3, 4)[-seq_len(4)] >> #> numeric(0) >> c(1, 2, 3, 4)[-seq_len(3)] >> #> [1] 4 >> c(1, 2, 3, 4)[-seq_len(2)] >> #> [1] 3 4 >> c(1, 2, 3, 4)[-seq_len(1)] >> #> [1] 2 3 4 >> c(1, 2, 3, 4)[-seq_len(0)] >> #> numeric(0) >> Created on 2018-08-05...
2018 Aug 29
0
Is this a bug in `[`?
...matrixStats. /Henrik On Sun, Aug 5, 2018 at 3:42 AM I?aki ?car <i.ucar86 at gmail.com> wrote: > > El dom., 5 ago. 2018 a las 6:27, Kenny Bell (<kmbell56 at gmail.com>) escribi?: > > > > This should more clearly illustrate the issue: > > > > c(1, 2, 3, 4)[-seq_len(4)] > > #> numeric(0) > > c(1, 2, 3, 4)[-seq_len(3)] > > #> [1] 4 > > c(1, 2, 3, 4)[-seq_len(2)] > > #> [1] 3 4 > > c(1, 2, 3, 4)[-seq_len(1)] > > #> [1] 2 3 4 > > c(1, 2, 3, 4)[-seq_len(0)] > > #> numeric(0) > > Created on...
2012 Jun 29
5
assign object with loop (translation from SAS to R)
I have a dataset named DM with p1, p2, ...., p9 (9 columns, numerical values) I would like to calculate to multify each pair of columns (p1p2, p1p3,... p1p9, p2p3, p2p4.... p8p9) and assign them in p1p2, p1p3,... p1p9, p2p3, p2p4.... p8p9 In SAS, l=0; p_int_sum=0; do i=1 to 8; do j=(i+1) to 9; l=l+1; p{i}p{j}=p{i}*p{j}; end; end; I would like to know how to assign them in R I tried for
2008 Mar 10
2
write.table with row.names=FALSE unnecessarily slow?
...s) && !is.na(col.names) && + col.names==TRUE if(is.matrix(x)) { ## fix up dimnames as as.data.frame would p <- ncol(x) d <- dimnames(x) if(is.null(d)) d <- list(NULL, NULL) - if(is.null(d[[1]])) d[[1]] <- seq_len(nrow(x)) - if(is.null(d[[2]]) && p > 0) d[[2]] <- paste("V", 1:p, sep="") + if (is.null(d[[1]]) && makeRownames) d[[1]] <- seq_len(nrow(x)) + if(is.null(d[[2]]) && p > 0 && makeColnames) + d[[2]] <-...
2010 Nov 24
1
segfault interest?
in a long program, I ran into ?*** caught segfault *** address 0xdc3f9b48, cause 'memory not mapped' Traceback: ?1: rep.int(seq_len(nx), rep.int(rep.fac, nx)) ?2: rep.int(rep.int(seq_len(nx), rep.int(rep.fac, nx)), orep) ?3: expand.grid(seq_len(nx), seq_len(ny)) ?4: merge.data.frame(d, ss) ?5: merge(d, ss) ?6: valid.range(opt) ?7: eval.with.vis(expr, envir, enclos) ?8: eval.with.vis(ei, envir) ?9: source("fut-into-opts.R&q...
2007 Jul 27
3
(PR#9811) sequence(c(2, 0, 3)) produces surprising results,
...been around in R for a long time. It is used in packages eRm, extRemes, hydrosanity, klaR, seas. Who knows what people have in private code, so I don't see any compelling case to change it. If people want a different version, it would only take a minute to write (see below). We could make seq_len take a vector argument, but as you point out in a followup that makes it slower in the common case. It also changes its meaning if a length > 1 vector is supplied, and would speed matter in the long-vector case? What does sequence0 <- function (nvec) { s <- integer(0) for (...
2013 Apr 24
1
Floating point precision causing undesireable behaviour when printing as.POSIXlt times with microseconds?
...I not expect to be able to print 1.999999 seconds? This seems to be caused by the following code fragment in format.POSIXlt: np <- getOption("digits.secs") if (is.null(np)) np <- 0L else np <- min(6L, np) if (np >= 1L) for (i in seq_len(np) - 1L) if (all(abs(secs - round(secs, i)) < 1e-06)) { np <- i break } Specifically for (i in seq_len(np) - 1L) if (all(abs(secs - round(secs, i)) < 1e-06)) Which in the case of 1.999999 seconds will...
2010 Sep 03
1
'seq' help page: seq_length -> seq_len?
In the Value section of the 'seq' help page it says 'seq_along' and 'seq_length' always return an integer vector. I believe it should be 'seq_along' and 'seq_len' always return an integer vector. as there are no seq_length function? Best, Niels -- Niels Richard Hansen Web: www.math.ku.dk/~richard Associate Professor...
2012 Jan 06
1
seq_along and rep_along
Hi all, A couple of ideas for improving seq_along: * It would be really useful to have a second argument dim: seq_along(mtcars, 1) seq_along(mtcars, 2) # equivalent to seq_len(dim(mtcars)[1]) seq_len(dim(mtcars)[2]) I often find myself wanting to iterate over the rows or column of a data frame, and there isn't a particularly nice idiom if you want to avoid problems with zeros - you have to use seq_len(nrow(df)) etc * To me, it would seem be very natural to ha...
2012 Feb 25
5
which is the fastest way to make data.frame out of a three-dimensional array?
foo <- rnorm(30*34*12) dim(foo) <- c(30, 34, 12) I want to make a data.frame out of this three-dimensional array. Each dimension will be a variabel (column) in the data.frame. I know how this can be done in a very slow way using for loops, like this: x <- rep(seq(from = 1, to = 30), 34) y <- as.vector(sapply(1:34, function(x) {rep(x, 30)})) month <- as.vector(sapply(1:12,