similar to: Extract values based on indexes without looping?

Displaying 20 results from an estimated 30000 matches similar to: "Extract values based on indexes without looping?"

2008 Mar 13
3
fast way to compare two matrices of combinations
I have a list (length 750), each element containing a vector of unique strings (unique gene ids), with length up to ~40 (median 15). I want to compile a matrix of all possible triplets and their frequency within gene elements. Using combn and a lot of looping, I am accomplishing this but it is VERY slow. I've tried to figure out a way to vectorize this, using "match" and
2009 Jan 15
1
misalignment of x-axis when overlaying two plots using latticeExtra
Dear R-helpers: I am an entry-level R user and have a question related to overlaying a barchart and and a xyplot using latticeExtra. My problem is that when I overlay them I fail to align their x-axes. I show my problem below through an example. #the example data frame is provided below vec <-c(1,5.056656,0.5977967,0.06126587,0.08557778, 2,4.601049,0.5995989,0.05002188,0.11410027,
2008 Dec 27
2
Object name vectcor as function input argument?
Dear R-helpers: I am new to R and ran into the following question and would appreicate your advice very much. My question: How to use a character vector that records object names as function input argument? I asked this question very recently and was advised to use get(). get() works when passing one single object name. but it does not work when passing multiple object names. For example, I
2009 Aug 24
4
Is there a fast way to do several hundred thousand ANOVA tests?
Dear R users, I have a matrix a and a classification vector b such that > str(a) num [1:50, 1:800000] and > str(b) Factor w/ 3 levels "cond1","cond2","cond3" I'd like to do an anova on all 800000 columns and record the F statistic for each test; I currently do this using f.stat.vec <- numeric(length(a[1,]) for (i in 1:length(a[1,]) { f.test.frame
2009 Apr 29
1
R Macro Question
Dear all, I am a new R user, and I have a question about R macro. Here is the situation, I want to do item option analysis (options include: A , B, C, D), below is the codes for option A analyses. #option A analyses optiona<-mat.or.vec(nrow(responsedata2), ncol(responsedata2)) # create A matrix by recoding for (i in 1:ncol(responsedata2)){    
2011 Feb 07
1
how to efficiently extract elements of a list?
Dear R helper, I wonder whether there is a quick way to extract some elements for a list. for a vector we can do the following vec <- seq(3) names(vec) <- LETTERS[1:3] vec[c(1,3)] vec[c('A','C')] But for a list, test.l <- list(c(1,3),array(NA,c(1,2)),array(0,c(2,3))) names(test.l)<-LETTERS[1:3] The following does not work. is there some command (I was thinking of
2008 Oct 31
1
gregexpr slow and increases exponentially with string length --> how to speed it up?
Dear All, I have a long string and need to search for regular expressions in there. However it becomes horribly slow as the string length increases. Below is an example: when "i" increases by 5, the time spent increases by more! (my string is 11,000,000 letters long!) I also noticed that - the search time increases dramatically with the number of matches found. - the perl=T option
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]
2007 Apr 11
2
Looping through series of names
Hi I am very new to R and have not able to find the answer to my question in the manual or any other post. I have a dataset that has various different sites names with data relating to each site. The data is in one dataset. I want to loop through the different site names and perform my test on each site. The sites are named not numbers for example "YYC". How do I do this. I hope I
2008 Dec 23
1
quotation problem/dataframe names as function input argument.
Dear R friends: Can someone help me with the following problem? Many thanks in advance. # Problem Description: # I want to write functions which take a (character) vector of dataframe names as input argument. # For example, I want to extract the number of observations from a number of dataframes. # I tried the following: nobs.fun <- function (dframe.vec) { nobs.vec <-
2008 Apr 29
7
How do you test for "consecutivity"?
I need to use R to model a large number of experiments (say, 1000). Each experiment involves the random selection of 5 numbers (without replacement) from a pool of numbers ranging between 1 and 30. What I need to know is what *proportion* of those experiments contains two or more numbers that are consecutive. So, for instance, an experiment that yielded the numbers 2, 28, 31, 4, 27 would be
2010 Jan 02
2
help with for loop
Dear useRs, I want to write a function that generates all the possible combinations of diff(). Example: If my vector has length 5, I need the diff() until lag=4 -> c(diff(my.vec), diff(my.vec, lag=2), diff(my.vec, lag=3), diff(my.vec, lag=4)) If it has length 4, I need until lag=3 -> c(diff(my.vec), diff(my.vec, lag=2), diff(my.vec, lag=3)) So, it must be until lag=(length(my.vec)-1).
2008 Jun 13
1
Looping, Control Flow & Conditional Statements
Dear R Group: I have little experience using R and even less experience with control flow type questions. See the following code: a1 = c(0, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 0, 0) for(i in 1:1){ sx <- paste("a",i,sep="") s <- eval(parse(text = paste("a",i,sep=""))) {g = numeric(length(s)) k =
2011 Oct 13
3
Create order of numbers based on a given vector
Hello! If I have a vector vec <- c(FALSE, FALSE, TRUE, FALSE, TRUE, TRUE, FALSE FALSE) I can I create the following order of numbers based on vector vec: 1, 2, 2, 3, 3, 3, 4, 5 Whenever there is a FALSE I increase the number (starting with 1). Whenever there is a TRUE I set the same number as the previous FALSE has been assigned to. I would be happy for any input Cheers, Syrvn -- View
2006 Jul 31
2
[LLVMdev] Auto-vectorization in GCC 4.0
Hi, I am trying to turn on the new GCC auto-vectorization feature within llvmgcc4. Below is the command I used, but nothing was vectorized. Does it mean that llvmgcc4 has disabled this optimization and all I can do is to embed SSE intrinsics in the source code by hand? Thanks! ./llvm-gcc4-x86/bin/llvm-gcc -c -O2 -ftree-vectorize -msse -ftree-vectorizer-verbose=5 -emit-llvm vec.c -o vec.bc
2009 Nov 25
1
R: Re: R: Re: chol( neg.def.matrix ) WAS: Re: Choleski and Choleski with pivoting of matrix fails
Dear Peter, thank you very much for your answer. My problem is that I need to calculate the following quantity: solve(chol(A)%*%Y) Y is a 3*3 diagonal matrix and A is a 3*3 matrix. Unfortunately one eigenvalue of A is negative. I can anyway take the square root of A but when I multiply it by Y, the imaginary part of the square root of A is dropped, and I do not get the right answer. I tried
2012 Jan 26
2
extracting from data.frames for survival analysis
Hi, I have a data frame: > class(B27.vec) [1] "data.frame" > head(B27.vec) AGE Gend B27 AgeOn DD uveitis psoriasis IBD CD UC InI BASDAI BASFI Smok UV 1 57 1 1 19 38 2 1 1 1 1 1 5.40 8.08 NA 1 2 35 1 1 33 2 2 1 1 1 1 1 1.69 2.28 NA 1 3 49 2 1 40 9 1 1 1 1 1 1 8.30 9.40 NA
2007 Jul 27
4
Looping through all possible combinations of cases
Hello! I have a regular data frame (DATA) with 10 people and 1 column ('variable'). Its cases are people with names ('a', 'b', 'c', 'd', 'e', 'f', etc.). I would like to write a function that would sum up the values on 'variable' of all possible combinations of people, i.e. 1. I would like to write a loop - in such a way that it
2004 Jan 15
3
Extracting multiple elements from a list
For a long time I've wanted a way to conveniently extract multiple elements from a list, which [[ doesn't allow. Can anyone suggest an efficient function to do this? Wouldn't it be a sensible addition to R? For example, alist <- list() alist[[1]] <- list() alist[[1]]$name <- "first" alist[[1]]$vec <- 1:4 alist[[2]] <- list() alist[[2]]$name <-
2007 Aug 13
1
Q: how to extract coefisients from one glm and implement them in to an other glm?
Een ingesloten tekst met niet-gespecificeerde tekenset is van het bericht gescrubt ... Naam: niet beschikbaar Url: https://stat.ethz.ch/pipermail/r-help/attachments/20070813/fc375520/attachment.pl