similar to: replacing a character string

Displaying 20 results from an estimated 10000 matches similar to: "replacing a character string"

2008 Jul 11
1
Suggestion: 20% speed up of which() with two-character mod
Hi, by replacing 'll' with 'wh' in the source code for base::which() one gets ~20% speed up for *named logical vectors*. CURRENT CODE: which <- function(x, arr.ind = FALSE) { if(!is.logical(x)) stop("argument to 'which' is not logical") wh <- seq_along(x)[ll <- x & !is.na(x)] m <- length(wh) dl <- dim(x) if (is.null(dl)
2017 Apr 11
0
Data Manager Position - CDC Atlanta - Immediate Need
SciMetrika is a population health consulting firm whose mission is to provide innovative scientific, technical, and logistical solutions that advance human health. We serve federal, state, and local agencies, commercial companies, educational institutions and private research organizations. We are currently seeking a Data Manager who will be based on-site at the Centers for Disease Control (CDC)
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) ?
2012 Oct 11
1
replacing ugly for loops
I have a couple of hundred American Community Survey Summary Files files containing rectangular arrays of data, mainly though not exclusively numeric. Each file is referred to as a sequence (henceforth "seq"). From these files I am trying to extract particular subsets (tables) consisting of a sets of columns. These tables are defined by three numbers (now in columns in a data frame):
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
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
2019 May 16
3
print.<strorageMode>() not called when autoprinting
In R-3.6.0 autoprinting was changed so that print methods for the storage modes are not called when there is no explicit class attribute. E.g., % R-3.6.0 --vanilla --quiet > print.function <- function(x, ...) { cat("Function with argument list "); cat(sep="\n ", head(deparse(args(x)), -1)); invisible(x) } > f <- function(x, ...) { sum( x * seq_along(x) ) }
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
2009 Nov 22
2
Help with indexing
Dear R Helpers, I am missing something very elementary here, and I don't seem to get it from the help pages of the ave, seq and seq_along functions, so I wonder if you could offer a quick help. To use an example from an earlier post on this list, I have a dataframe of this kind: dat = data.frame(name = rep(c("Mary", "Sam", "John"), c(3,2,4))) dat$freq =
2012 Nov 30
1
xts indexed with Date class
Hi I see a changed behaviour in xts indexed on class Date in the latest versions, versus 2. It seems to be related to changes to/from daylight savings time, happens those weekends. Is it not intended that class Date be used like this, or is this new behaviour incorrect? Giles Example: > a<-as.Date(15423:15426) > x<-xts(seq_along(a),a) > print(x) [,1] 2012-03-24
2012 Nov 20
2
correct function formation in R
Dear list! ? I have question of?'correct function formation'. Which function (fun1 or fun2; see below) is written more correctly? Using ''structure'' as output or creating empty ''data.frame'' and then transform it as output? (fun1 and fun1 is just for illustration). ? Thanks a lot, OV ? code: input <- data.frame(x1 = rnorm(20), x2 = rnorm(20), x3 =
2009 Aug 23
2
difficult "for"
Hi, My english isn't brilliant and my problem is very difficult to describe but I try ;) My first question is: May I write loop "for" like this or similar - for (i in sth : sth[length(sth)], k in sth_else : length(sth_else) ) - I'd like to have two independent conditions in the same loop "for". My secound question depend on program below. I'd like to write every
2010 Sep 21
2
lapply version with [ subseting - a suggestion
Dear R developers, Reviewing my code, I have realized that about 80% of the time in the lapply I need to access the names of the objects inside the loop. In such cases I iterate over indexes or names: lapply(names(x), ... [i]), lapply(seq_along(x), ... x[[i]] ... names(x)[i] ), or for(i in seq_along(x)) ... which is rather inconvenient. How about an argument to lapply which would specify the
2010 Aug 17
4
replacing values in a vector
Dear helpRs Does anyone have an elegant way of doing the following: For a given numeric vector, e.g. vec <- c(3,2,6,4,7) Create a series of vectors where all but 1 of the values are replaced by 0's, e.g. vec.a <- c(3,0,0,0,0) vec.b <- c(0,2,0,0,0) vec.c <- c(0,0,6,0,0) vec.d <- c(0,0,0,4,0) vec.e <- c(0,0,0,0,7) I have looked at `replace', but can't think of a
2019 May 21
2
print.<strorageMode>() not called when autoprinting
It also is a problem with storage.modes "integer" and "complex": 3.6.0> print.integer <- function(x,...) "integer vector" 3.6.0> 1:10 [1] 1 2 3 4 5 6 7 8 9 10 3.6.0> print(1:10) [1] "integer vector" 3.6.0> 3.6.0> print.complex <- function(x, ...) "complex vector" 3.6.0> 1+2i [1] 1+2i 3.6.0>
2019 Oct 31
2
head.matrix can return 1000s of columns -- limit to n or add new argument?
On 10/30/19 04:29, Martin Maechler wrote: >>>>>> Gabriel Becker >>>>>> on Tue, 29 Oct 2019 12:43:15 -0700 writes: > > > Hi all, > > So I've started working on this and I ran into something that I didn't > > know, namely that for x a multi-dimensional (2+) array, head(x) and tail(x) > > ignore dimension
2012 Dec 24
2
whats wrong in my codes???
Dear R family,i am trying to plot and save, simultaneously, about 1000. the name of each plot is contained in "names" file. when i run this loop, i get an error. "Error in plot.new() : Unable to open file 'C:/R/SAVEHERE/myplot_Tak.jpg' for writing". could you please correct the mistake in the loop? >names<-(names(sp)) >for(a in seq_along(names)){ >mypath
2007 Jun 19
4
How do I avoid a loop?
Hi, I start with an array of booleans: x <- c( TRUE, TRUE, TRUE, FALSE, FALSE, TRUE, TRUE, FALSE, TRUE ); I want to define an y <- f(x) such that: y <- c( 1, 2, 3, 0, 0, 1, 2, 0, 1 ); In other words, do a cumsum when I see a TRUE, but reset to 0 if I see a FALSE. I know I can do this with a very slow and ugly loop or maybe use apply, but I was hoping there are some R experts out
2012 Dec 23
1
correction needed in codes
Dear useRs,while trying to plot the yearly curves of 1000 stations and overlapping each set of curves with mean curve and then saving it automatically in a pdf file, i tried the following commands >Path = "C:\\R\\003.pdf">pdf(file=Path) for (i in seq(1:1000) >a<-lapply(seq_along(tcp), function(x) tcp[[x]][,-1]) >b<-lapply(seq_along(a), function(a)
2012 Dec 03
4
How to calculate the spatial correlation of several files?
dir1 <- list.files("C:\\Users\\aalyaari\\Desktop\\cor", "*.bin", full.names = TRUE) dir2 <- list.files("C:\\Users\\aalyaari\\Desktop\\cor2", "*.bin", full.names = TRUE) results <- list() for (.files in dir1){ # read in the 365 files as a vector of numbers for dir1 file1 <- do.call(rbind,(lapply(.files, readBin ,