similar to: Find number of elements less than some number: Elegant/fast solution needed

Displaying 20 results from an estimated 10000 matches similar to: "Find number of elements less than some number: Elegant/fast solution needed"

2011 Apr 15
1
[Rcpp-devel] Find number of elements less than some number: Elegant/fastsolution needed
On Thu, Apr 14, 2011 at 7:02 PM, <rcpp-devel-request at r-forge.wu-wien.ac.at> wrote: > I was able to write a very short C++ function using the Rcpp package > that provided about a 1000-fold increase in speed relative to the best > I could do in R. ?I don't have the script on this computer so I will > post it tomorrow when I am back on the computer at the office. > >
2011 Jan 05
4
Match numeric vector against rows in a matrix?
Two posts in one day is not a good day...and this question seems like it should have an obvious answer: I have a matrix where rows are unique combinations of 1's and 0's: > combs=as.matrix(expand.grid(c(0,1),c(0,1))) > combs Var1 Var2 [1,] 0 0 [2,] 1 0 [3,] 0 1 [4,] 1 1 I want a single function that will give the row index containing an exact match
2012 Jan 28
2
Need very fast application of 'diff' - ideas?
Hi everyone, Speed is the key here. I need to find the difference between a vector and its one-period lag (i.e. the difference between each value and the subsequent one in the vector). Let's say the vector contains 10 million random integers between 0 and 1,000. The solution vector will have 9,999,999 values, since their is no lag for the 1st observation. In R we have: #Set up input vector
2007 May 29
1
Modal Window Stealing Elements from Form. Need Elegant Solution.
I''m using Prototype.js with Control.modal to create a modal window on my IPB Forum which takes all the various topic posting/replying/ editing options and places them into a Modal window. The inherent nature of this action is to take the contents of whatever DIV I told Control.Modal to make a modal window out of and place the entire innerHTML of that DIV into a separate DIV outside the
2008 Jun 10
2
Fast method to compute average values of duplicated IDs
Hi, How do I collapse (average in the simplest case) the values of those duplicated ids (i.e., 2, 5, 6, 9) to give a table of unique ids ? t <- cbind(id=c(1:10, 2,5,6,9), value=rnorm(14)) _________________________________________________________________ [[alternative HTML version deleted]]
2011 Jan 05
3
How to 'explode' a matrix
Hi everyone, I'm looking for a way to 'explode' a matrix like this: > matrix(1:4,2,2) [,1] [,2] [1,] 1 3 [2,] 2 4 into a matrix like this: > matrix(c(1,1,2,2,1,1,2,2,3,3,4,4,3,3,4,4),4,4) [,1] [,2] [,3] [,4] [1,] 1 1 3 3 [2,] 1 1 3 3 [3,] 2 2 4 4 [4,] 2 2 4 4 My current kludge is this:
2009 Dec 12
1
Create sequence given start and end vector
How can I create the following without the 'for' loop? start=c(1,10,20) end=c(4,15,27) out=c() for (i in 1:length(start)) { out=c(out,start[i]:end[i]) } out [1] 1 2 3 4 10 11 12 13 14 15 20 21 22 23 24 25 26 27 I know there must be an easier (and, hopefully, faster) way. Many thanks in advance, Kevin Ummel Central European University Department of Environmental Science and
2010 Jul 29
2
Replace last element in a vector - elegant solution?
-----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1 Hi I have to replace the last element of a vector with 0, but the length of x is not known at coding time. So I do the following: x <- 1:10 x x[length(x)] <- 0 x it is working nicely, but I am wondering: is there a more elegant solution( like tail(x, 1) <- 0 , which does not work)? Thanks, Rainer - -- Rainer M. Krug, PhD (Conservation
2010 Nov 16
2
Pass character vector to function argument
A bit embarrassed to post this seemingly trivial question, but I can't find anything in the archive that's quite relevant: a1=1 a2=2 obs=objects(pattern=glob2rx("a?")) I want to utilize 'obs' as a function argument to produce something like: sum(a1,a2) Obviously, sum(obs) doesn't work, but I've tried variations of 'eval', 'parse',
2009 Sep 15
1
coefficients of aov results has less number of elements?
Hi, I run the following commands. 'A' has 3 levels and 'B' has 4 levels. Should there be totally 3+4 = 7 coefficients (A1, A2, A3, B1, B2, B3, B4)? > a=3 > b=4 > n=1000 > A = rep(sapply(1:a,function(x){rep(x,n)}),b) > B = as.vector(sapply(sapply(1:b, function(x){rep(x,n)}), function(x){rep(x,a)})) > Y = A + B + rnorm(a*b*n) > > fr =
2005 Jun 28
2
function for cumulative occurrence of elements
Hello, I have a data set with 9700 records, and 7 parameters. The data were collected for a survey of forest communities. Sample plots (1009) and species (139) are included in this data set. I need to determine how species are accumulated as new plots are considered. Basically, I want to develop a species area curve. I've included the first 20 records from the data set. Point
2010 Dec 02
1
Arrange elements on a matrix according to rowSums + short 'apply' Q
Greetings, My goal is to create a Markov transition matrix (probability of moving from one state to another) with the 'highest traffic' portion of the matrix occupying the top-left section. Consider the following sample: inputData <- c( c(5, 3, 1, 6, 7), c(9, 7, 3, 10, 11), c(1, 2, 3, 4, 5), c(2, 4, 6, 8, 10), c(9, 5, 2, 1, 1) ) MAT <- matrix(inputData,
2011 Aug 23
3
Bug or feature? sum(c(a, b, c)) != (a + b + c)
Greetings all, I'm porting an algorithm from MATLAB to R, and noticed some minor discrepancies in small decimal values using rowSums and colSums which are exacerbated after heavy iteration and log space transformation. This was rather perplexing as both programs claimed and appeared to use the IEEE 754 standard for floating point arithmetic (confirmed with manual basic operations).
2008 Aug 18
1
seq: specify *minimum* end value, more elegant solution
Hello, Using seq, I would like to specify a minumum end value, rather than a maximum end value. For example, rather than > seq(from=0, to=10, by=4) [1] 0 4 8 I would like to obtain [1] 0 4 8 12 I can do that with > by.value = 4 > seq(from=0,by=by.value,to=ceiling(10 / by.value)*by.value) [1] 0 4 8 12 That seems like a somewhat clunky solution, though, and requires an additional
2003 Apr 22
4
fisher exact vs. simulated chi-square
Dear All, I have a problem understanding the difference between the outcome of a fisher exact test and a chi-square test (with simulated p.value). For some sample data (see below), fisher reports p=.02337. The normal chi-square test complains about "approximation may be incorrect", because there is a column with cells with very small values. I therefore tried the chi-square with
2009 Jan 18
2
Deleting columns based on the number of non-blank observations
Hello, I have a dataset (named "x") with many (966) columns. What I would like to do is delete any columns that do not have at least 375 non-blank observations (i.e., the cells have some value in them besides NA). How can I do this? I have come up with the following code to _count_ the non-blank observations in each column, but how would I adapt this code to _delete_ columns from the
2006 Mar 14
3
Simple search on joined table
Looking for some guidance, I seem to be caught in the weeds. I want to do a search on fields in a master/detail relationship. E.g. manufacturer owns many parts. I want to search on the manufacturer name, part name and part number, then return the full set of results. I have tried to use the .find method and create my own model .find method using a SQL statement, but then the results do not
2013 Jan 27
2
Loops
Dear Contributors, I am asking help on the way how to solve a problem related to loops for that I always get confused with. I would like to perform the following procedure in a compact way. Consider that p is a matrix composed of 100 rows and three columns. I need to calculate the sum over some rows of each column separately, as follows: fa1<-(colSums(p[1:25,])) fa2<-(colSums(p[26:50,]))
2010 Mar 24
3
More elegant solution for "missing" has-many through ids?
I have LabGroup and LabDesc which have many through LabDescGroup. I''d like to identify LabDescs which don''t have a LabGroup. This works: x = [] LabDescGroup.find( :all, :select => ''DISTINCT lab_desc_id'' ).each{ |c| x << c.lab_desc_id } y = [] LabDesc.find( :all, :select => ''id'' ).each{ |c| y << c.id } notfound = x - y But
2006 Jan 15
6
Saving one-many associations (elegant solution please)
What is the most elegant way to save new one-many associations? order = Order.new(:name => "My Order") order.line_items << LineItem.new(:product_id => 1, :quantity => 2) order.line_items << LineItem.new(:product_id => 2, :quantity => 5) order.save The above - which is by far the most elegant way of putting it - doesn''t work for me - the line_items