similar to: Putting a loop in a function

Displaying 20 results from an estimated 20000 matches similar to: "Putting a loop in a function"

2006 Nov 09
1
invert argument in grep
Hello, What about an `invert` argument in grep, to return elements that are *not* matching a regular expression : R> grep("pink", colors(), invert = TRUE, value = TRUE) would essentially return the same as : R> colors() [ - grep("pink", colors()) ] I'm attaching the files that I modified (against today's tarball) for that purpose. Cheers, Romain --
2004 Nov 01
3
Reading word by word in a dataset
Hello All, I'd like to read first words in lines into a new file. If I have a data file the following, how can I get the first words: apple, banana, strawberry? i1-apple 10$ New_York i2-banana 5$ London i3-strawberry 7$ Japan Is there any similar question already posted to the list? I am a bit new to R, having a few months of experience now. Cheers, John
2006 Jan 27
4
regular expressions, sub
Hi, I am trying to use sub, regexpr on expressions like log(D) ~ log(N)+I(log(N)^2)+log(t) being a model specification. The aim is to produce: "ln D ~ ln N + ln^2 N + ln t" The variable names N, t may change, the number of terms too. I succeded only partially, help on regular expressions is hard to understand for me, examples on my case are rare. The help page on R-help
2011 Sep 27
1
array extraction
hello everyone. Look at the following R idiom: a <- array(1:30,c(3,5,2)) M <- (matrix(1:15,c(3,5)) %% 4) < 2 a[M,] <- 0 Now, I think that "a[M,]" has an unambiguous meaning (to a human). However, the last line doesn't work as desired, but I expected it to...and it recently took me an indecent amount of time to debug an analogous case. Just to be explicit, I would
2009 Feb 12
3
get top 50 correlated item from a correlation matrix for each item
Hi, I have a correlation matrix of about 3000 items, i.e., a 3000*3000 matrix. For each of the 3000 items, I want to get the top 50 items that have the highest correlation with it (excluding itself) and generate a data frame with 3 columns like ("ID", "ID2", "cor"), where ID is those 3000 items each repeat 50 times, and ID2 is the top 50 correlated items with ID,
2010 Dec 31
4
Repeated Indexing / Sequence Operation
Hi Everyone, quick question before the end of the year. I have soem indices to select data from a bigger sample. I want to select n days before each index and n days after the index. Any clever way to do it. A for loop would do but I wanted to know if there is a moreR-friendly way to approach this Example # InitialIndices i2 = (90, 190, 290) # Indices I want to end up with i3 = c(85, 86, 87,
2012 Apr 27
2
question of iSCSI pool on the same iSCSI target
An HTML attachment was scrubbed... URL: <http://listman.redhat.com/archives/libvirt-users/attachments/20120427/287fd756/attachment.htm>
2010 Sep 13
2
value returned by by()
Hi, I noticed that by() returns an object of class 'by', regardless of what its argument 'simplify' is. ?by says that it always returns a list if simplify=FALSE, yet by.data.frame shows: ---<--------------------cut here---------------start------------------->--- function (data, INDICES, FUN, ..., simplify = TRUE) { if (!is.list(INDICES)) { IND <-
2004 Oct 09
2
which() and value replacement in a matrix
Hi, I cannot go through the archives with which() as key-word... so common. Though I am sure to have seen something about this subject in the past could somebody put me on the track. I have a matrix (actually a data.frame) in which I would replace the non-null values by 1. I tried the following: indices<-which(myforetbin > 0,arr.ind=T) myforetbin[indices[,1],indices[,2]]<-1 and get
2005 Aug 18
2
matrix indexing
Dear R-users, I was wondering for the following: Let 'x' be a matrix and 'ind' and indicator matrix, i.e., x <- array(1:20, dim = c(4, 5)) ind <- array(c(1:3, 3:1), dim = c(3, 2)) I'd like to get (as a vector) the elements of 'x' which are not indexed by 'ind'. Since negative indices are not allowed in index matrices I thought of using something like:
2008 Apr 15
1
by inconsistently strips class - with fix
summary: The function 'by' inconsistently strips class from the data to which it is applied. quick reason: tapply strips class when simplify is set to TRUE (the default) due to the class stripping behaviour of unlist. quick answer: This can be fixed by invoking tapply with simplify=FALSE, or changing tapply to use do.call(c instead of unlist executable example:
2009 Sep 19
1
matrix operations on grobs and grid units
Dear list, As a minimal test of a more complex grid layout, I'm trying to find a clean and efficient way to arrange text grobs in a rectangular layout. The labels may be expressions, or text with a fontsize different of the default, which means that the cell sizes should probably be calculated using grobWidth() and grobHeight() as opposed to simpler stringWidth() and stringHeight().
2006 Sep 23
2
Create a vector of indices from a matrix of start and end points
I have a very large dataframe and wish to extract a subset of rows. I have a two column matrix listing the starting and ending indices of one subset on each row. My idea is to create a vector of indices that could be applied to the dataframe and I have a solution using a for loop (below). But surely there is some more elegant way to do this! I looked thorough the archives without
2009 Feb 23
1
Slow indexing access for Matrix
Consider the following little "benchmark" > require(Matrix) > tmp <- Matrix(c(rep(1,1000),rep(0,9000)),ncol=1) > ind <- sample(1:10000,10000) > system.time(tmp[ind,]) user system elapsed 0.004 0.001 0.005 > ind <- sample(1:1000,10000,replace=TRUE) > system.time(tmp[ind,]) user system elapsed 0.654 0.006 0.703 >
2006 Sep 18
2
Exc CB Search very little Question
Hi, Jean-Marc Valin wrote: > Not sure I understand your question. Change the order of what within what? In cb_search, we iterate nb_subvect times over a codebook, finding nb_subvect codebook entries to quantize the excitation signal. After finding these nb_subvect codebook entries, they're written into the stream: /*save indices*/ for (i=0;i<nb_subvect;i++) {
2007 Dec 10
2
bug in by.data.frame, R-2.6.1 (PR#10506)
by() fails for 1-column matrices and dataframes: X <- data.frame(a=1:10) g <- gl(2,5) by(X, g, colMeans) Suggested fix: --- by-old.R 2007-12-10 15:26:22.501086600 +0100 +++ by.R 2007-12-10 15:25:58.390477200 +0100 @@ -26,7 +26,7 @@ IND[[1]] <- INDICES names(IND) <- deparse(substitute(INDICES))[1] } else IND <- INDICES - FUNx <-
2003 Aug 13
2
putting NAs at the end
I have a matrix for which each row has 12 elements that represent the xyz coordinates of 4 points. So each row of M is (x1,y1,z1,x2,y2,z2,x3,y3,z3,x4,y4,z4). Some points have NA as z values. I want another matrix to be the same as M but with the coordinates of those points with z=NA placed last. For ezample if z1=NA then the new matrix row should be (x2,y2,z2,x3,y3,z3,x4,y4,z4,x1,y1,z1)
2012 Nov 16
1
Split data frame and create a new column
I need to split a data frame into 3 columns. The column I want to split contains indices of lag (prefix L1 or L2 and suffix 01, 03, 04), station name (shown in the sample data as capitalized G, P and S) and pollutant name. Names with no ?L? prefix or 01/04 suffix are lag 0. Lag 01 is average of lag 0 and 1, and 04 is average of 0 to 4 days. How can one do that in R? I will ignore the other
2013 Jan 28
1
Using loop for a random vector (Montecarlo method)
Hi, I would like to replicate a sort of Montecarlo experiment: I have to generate a random variable N(0,1) with 100 observations but I have to contaminate this values at certain point in order to obtain different vectors with different samples: tab<-function(N,n,E,L){ for(i in 1:100){ X1<-rnorm(N*(1-a),0,1) X2<-rnorm(N*(a),E,L) X_tab<-sample(c(X1,X2),n,replace=T) } return(X_tab)}
2007 Sep 20
1
Identify and plotting symbols. [SEC=UNCLASSIFIED]
Rolf turner wrote: >I have been trying, unsuccessfully, to use identify() to (simply) >return a list of the indices of points clicked on and overplot (with >say a solid dot) each clicked-on point so that I can see where I've >been. I.e. I don't want to see the indices printed on the screen; I just want the points I've already selected to be highlighted. > >I