similar to: seq_along and rep_along

Displaying 20 results from an estimated 9000 matches similar to: "seq_along and rep_along"

2009 Jul 09
1
bug in seq_along
Using the IRanges package from Bioconductor and somewhat recent R-2.9.1. ov = IRanges(1:3, 4:6) length(ov) # 3 seq(along = ov) # 1 2 3 as wanted seq_along(ov) # 1! I had expected that the last line would yield 1:3. My guess is that somehow seq_along don't utilize that ov is an S4 class with a length method. The last line of the *Details* section of ?seq has a typeo. Currently it is
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
2010 Feb 25
3
behavior of seq_along
I'm trying to understand the behavior of seq_along in the following example: x <- 1:5; sum(x) y <- 6:10; sum(y) data <- c(x,y) S <- sum( data[seq_along(x)] ) S T <- sum( data[seq_along(y)] ) T Why is T != sum(y) ?
2007 Apr 03
1
Behavior of seq_along (was: Create a new var reflecting the order of subjects in existing var)
I am moving this from r-help to r-devel. Based on offline communications with Jim, suppose dat is defined as follows: set.seed(123) dat <- data.frame(ID= c(rep(1,2),rep(2,3), rep(3,3), rep(4,4), rep(5,5)), var1 =rnorm(17, 35,2), var2=runif(17,0,1)) # Then this ave call works as expected: ave(dat$ID, dat$ID, FUN = function(x) seq_along(x)) # but this apparently identical calculation
2017 Jun 23
1
R version 3.3.2, Windows 10: Applying a function to each possible pair of rows from two different data-frames
Hello, Another way would be n <- nrow(expand.grid(1:nrow(D1), 1:nrow(D2))) D5 <- data.frame(distance=integer(n),difference=integer(n)) D5[] <- do.call(rbind, lapply(seq_len(nrow(D1)), function(i) t(sapply(seq_len(nrow(D2)), function(j){ c(distance=sqrt(sum((D1[i,1:2]-D2[j,1:2])^2)),difference=(D1[i,3]-D2[j,3])^2) } )))) identical(D3, D5) In my first answer I forgot to say that
2012 Nov 05
2
averaging a list of matrices element wise
Dear all, I have a list of n matrices which all have the same dimension (r x s). What would be a fast/elegant way to calculate the element wise average? So result[1, 1] <- mean(c(raw[[1]][1, 1] , raw[[2]][1, 1], raw[[...]][1, 1], raw[[n]][1, 1])) Here is my attempt. #create a dummy dataset n <- 3 r <- 5 s <- 6 raw <- lapply(seq_len(n), function(i){ matrix(rnorm(r * s), ncol =
2016 Dec 20
2
colnames for data.frame could be greatly improved
Hello, colnames seems to be not optimized well for data.frame. It escapes processing for data.frame in if (is.data.frame(x) && do.NULL) return(names(x)) but only when do.NULL true. This makes huge difference when do.NULL false. Minimal edit to `colnames`: if (is.data.frame(x)) { nm <- names(x) if (do.NULL || !is.null(nm)) return(nm) else
2018 May 11
0
add one variable to a data frame
Sarah's solutions are good, and here's another, even more basic: tmp1 <- unique(dat1$B) tmp2 <- seq_along(tmp1) dat1$C <- tmp2[ match( dat1$B, tmp1) ] > dat1 N B C 1 1 29_log 1 2 2 29_log 1 3 3 29_log 1 4 4 27_cat 2 5 5 27_cat 2 6 6 1_log 3 7 7 1_log 3 8 8 1_log 3 9 9 1_log 3 10 10 1_log 3 11 11 3_cat 4 12 12 3_cat 4 As a single line
2019 Mar 02
1
stopifnot
A private reply by Martin made me realize that I was wrong about stopifnot(exprs=TRUE) . It actually works fine. I apologize. What I tried and was failed was stopifnot(exprs=T) . Error in exprs[[1]] : object of type 'symbol' is not subsettable The shortcut assert <- function(exprs) stopifnot(exprs = exprs) mentioned in "Warning" section of the documentation similarly fails
2017 Aug 07
1
Has For bucle be impooved in R
Dear Jesus, The difference is marginal when each code chunk does the same things. Your for loop does not yields the same output as the lapply. Here is the cleaned version of your code. n<-10000 set.seed(123) x<-rnorm(n) y<-x+rnorm(n) rand.data<-data.frame(x,y) k<-100 samples <- split(sample(n), rep(seq_len(k),length=n)) library(microbenchmark) microbenchmark( "for"
2018 May 26
1
Grouping by 3 variable and renaming groups
Hello, Sorry, but I think my first answer is wrong. You probably want something along the lines of sp <- split(priceStore_Grps, priceStore_Grps$StorePC) res <- lapply(seq_along(sp), function(i){ sp[[i]]$StoreID <- paste("Store", i, sep = "_") sp[[i]] }) res <- do.call(rbind, res) row.names(res) <- NULL Hope this helps, Rui Barradas On 5/26/2018
2013 Oct 11
3
matrix values linked to vector index
Hi, In the example you showed: m1<- matrix(0,length(vec),max(vec)) 1*!upper.tri(m1) #or ?m1[!upper.tri(m1)] <-? rep(rep(1,length(vec)),vec) #But, in a case like below, perhaps: vec1<- c(3,4,5) ?m2<- matrix(0,length(vec1),max(vec1)) ?indx <- cbind(rep(seq_along(vec1),vec1),unlist(tapply(vec1,list(vec1),FUN=seq),use.names=FALSE)) m2[indx]<- 1 ?m2 #???? [,1] [,2] [,3] [,4] [,5]
2009 Jun 03
4
Excel Export in a beauty way
Hallo all, I`ve read a lot of things in this forum about an Excel export via R. It is no problem to export my data frames via write.table or write.xls (xls or csv), but some things are not very convenient for me: I always have to adjust the column with to see all the numbers or the text and there is no frame between the cells. And I missing the possibility to make some headers bold or coloured.
2011 Jan 31
1
str() on raster objects fails for certain dimensions
Hi, str() on raster objects fails for certain dimensions. For example: > str(as.raster(0, nrow=1, ncol=100)) 'raster' chr [1, 1:100] "#000000" "#000000" "#000000" "#000000" ... > str(as.raster(0, nrow=1, ncol=101)) Error in `[.raster`(object, seq_len(max.len)) : subscript out of bounds This seems to do with how str() and
2017 May 11
1
R-3.3.3/R-3.4.0 change in sys.call(sys.parent())
Here is a case where the current scheme fails: > with(datasets::mtcars, xyplot(mpg~wt|gear)$call) xyplot(substitute(expr), data, enclos = parent.frame()) Bill Dunlap TIBCO Software wdunlap tibco.com On Thu, May 11, 2017 at 1:09 AM, Deepayan Sarkar <deepayan.sarkar at gmail.com> wrote: > On Wed, May 10, 2017 at 2:36 AM, William Dunlap via R-devel > <r-devel at
2018 May 11
3
add one variable to a data frame
Hi Sarah, Thank you so much!! I got your good ideas. Ding -----Original Message----- From: Sarah Goslee [mailto:sarah.goslee at gmail.com] Sent: Friday, May 11, 2018 11:40 AM To: Ding, Yuan Chun Cc: r-help mailing list Subject: Re: [R] add one variable to a data frame [Attention: This email came from an external source. Do not open attachments or click on links from unknown senders or
2017 May 09
3
R-3.3.3/R-3.4.0 change in sys.call(sys.parent())
Some formula methods for S3 generic functions use the idiom returnValue$call <- sys.call(sys.parent()) to show how to recreate the returned object or to use as a label on a plot. It is often followed by returnValue$call[[1]] <- quote(myName) E.g., I see it in packages "latticeExtra" and "leaps", and I suspect it used in "lattice" as well. This idiom
2007 Oct 01
4
how to plot a graph with different pch
I am trying to plot a graph but the points on the graph should be different symbols and colors. It should represent what is in the legend. I tried using the points command but this does not work. Is there another command in R that would allow me to use different symbols and colors for the points? Thank you kindly. data(mtcars) plot(mtcars$wt,mtcars$mpg,xlab= "Weight(lbs/1000)",
2011 Dec 13
1
How to add points to two plots parallelly ?
I am looking for ways to add points to three different plots in parallel. I generate three scatter plots and name them as s3d1, s3d2 and s3d3 s3d1<-scatterplot3d(mtcars[,3],mtcars[,4],mtcars[,5],main="common",pch=20) s3d2<-scatterplot3d(mtcars[,3],mtcars[,4],mtcars[,5],main="common",pch=20)
2012 Jan 15
0
patching ?merge to allow the user to keep the order of one of the two data.frame objects merged
Hello dear R-devel list members. Following an old (2002) thread from R-help (and having myself needing to solve the same question): https://stat.ethz.ch/pipermail/r-help/2002-October/026249.html I patched the {base} function "merge.data.frame" to have it work with a new parameter called "keep_order", and I hope you might consider including this patch (or some variation of it)