search for: findinterval

Displaying 20 results from an estimated 159 matches for "findinterval".

2016 Aug 04
1
findInterval(all.inside=TRUE) for degenerate 'vec' arguments
What should findInterval(x,vec,all.inside=TRUE) return when length(vec)<=1, so there are no inside intervals? R-3.3.0 gives a decreasing map of x->output when length(vec)==1 and -1's when length(vec)==0. Would '0' in all those cases be better? > findInterval(x=c(10, 11, 12), vec=11, all.inside=TRUE,...
2011 Dec 06
1
help wrapping findInterval into a function
...m creating a function. I am working with water-quality data sets that contain the concentration of many different elements in water samples. I need to assign quality-control flags to values that fall into various concentration ranges. Rather than a web of nested if statements, I am employing the findInterval function to identify values that need to be flagged and to assign the appropriate flag. The data consist of a sample identifier, the analysis, and corresponding value. The findInterval function works well; however, I would like to incorporate it into a function so that I can run multiple findInte...
2024 Sep 16
1
findInterval
Suppose we have `dat` shown below and we want to find the the `y` value corresponding to the last value in `x` equal to the corresponding component of `seek` and we wish to return an output the same length as `seek` using `findInterval` to perform the search. This returns the correct result: dat <- data.frame(x = c(2, 2, 3, 4, 4, 4), y = c(37, 12, 19, 30, 6, 15), seek = 1:6) zero2na <- function(x) replace(x, x == 0, NA) dat |> transform(dat, result = y[ zero2na(findInterval(seek, x)) ] ) |> _...
2024 Sep 17
1
findInterval
...Mon, 16 Sep 2024 11:21:55 -0400 writes: > Suppose we have `dat` shown below and we want to find the the `y` value > corresponding to the last value in `x` equal to the corresponding component > of `seek` and we wish to return an output the same length as `seek` using > `findInterval` to perform the search. This returns the correct result: > dat <- data.frame(x = c(2, 2, 3, 4, 4, 4), > y = c(37, 12, 19, 30, 6, 15), > seek = 1:6) > zero2na <- function(x) replace(x, x == 0, NA) > dat |> > transform(d...
2010 Jul 12
2
findInterval and data resolution
Hello Wise Ones... I need a clever way around a problem with findInterval. Consider: vec1 <- 1:10 vec2 <- seq(1, 10, by = 0.1) x1 <- c(2:3) a1 <- findInterval(x1, vec1); a1 # example 1 a2 <- findInterval(x1, vec2); a2 # example 2 In the problem I'm working on, vec* may be either integer or numeric, like vec1 and vec2. I need to remove one or mor...
2008 Sep 22
1
findInterval(), binary search, log(N) complexity
Dear R users, the help for findInterval(x,vec) suggests a logarithmic dependence on N (=length(vec)), which would imply a binary search type algorithm. However, when I "test" this hypothesis, in the following manner: set.seed(-3645); l <- vector(); N.seq <- c(5000, 500000, 1000000, 10000000, 50000000);k <- 1 for (N in...
2011 Apr 04
2
General binary search?
Is there a generic binary search routine in a standard library which a) works for character vectors b) runs in O(log(N)) time? I'm aware of findInterval(x,vec), but it is restricted to numeric vectors. I'm also aware of various hashing solutions (e.g. new.env(hash=TRUE) and fastmatch), but I need the greatest-lower-bound match in my application. findInterval is also slow for large N=length(vec) because of the O(N) checking it does, as Duncan...
2020 Mar 05
3
findInterval Documentation Suggestion
I've found over time that R documentation that comes off as terse at first blush is usually revealed to be precise, concise, and complete on close reading.? I'm sure this is also true of `?findInterval`, but for whatever reason my brain simply refuses to extract meaning from it. Part of the problem may be that we interact with the function via a compressed form of the bounds of the intervals (only specify left bounds for 2nd interval onwards), but the semantics are described mostly in terms of t...
2020 Mar 06
0
findInterval Documentation Suggestion
...>>>>> on Thu, 5 Mar 2020 22:18:33 +0000 (UTC) writes: > I've found over time that R documentation that comes off as terse at > first blush is usually revealed to be precise, concise, and complete > on close reading.? I'm sure this is also true of `?findInterval`, but > for whatever reason my brain simply refuses to extract meaning from it. > Part of the problem may be that we interact with the function via a > compressed form of the bounds of the intervals (only specify left bounds > for 2nd interval onwards), but the semantic...
2004 Sep 20
1
findInterval in compiled code.
Hi all, I am writing some C code where I want to use the findInterval function documented in "Writing R extensions/Utility functions". i.e. the C-version not the R version. It all compiles but the shared library is causing seg-faults and I'm obviously stuffing something up. Has anyone got any examples of calling this function they'd be will to sh...
2018 Apr 20
1
create multiple categorical variables in a data frame using a loop
..., na.rm =T)]<-2 >> cat.pfoa[pfas.pheno$log2pfoa >=quantile(pfas.pheno$log2pfoa,0.25, na.rm =T) >> &pfas.pheno$log2pfoa <=quantile(pfas.pheno$log2pfoa,0.75, na.rm =T)]<-1 >> } > > This would be somewhat more compact and easier to maintain if you used findInterval (untested in the absence of a data object, which is your responsibility): > > pfas.pheno <-within(pfas.pheno, { > cat.pfoa <- findInterval( log2pfoa , c(-Inf, quantile( log2pfoa,c(.25,.75), Inf), na.rm =T), Inf)]-1 } ) > > > `findInterval` numbers its intervals from 1, s...
2013 Sep 13
2
how to get values within a threshold
input: > values [1] 0.854400 1.648465 1.829830 1.874704 7.670915 7.673585 7.722619 > thresholds [1] 1 3 5 7 9 expected output: [1] 1 4 4 4 7 That is, need a vector of indexes of the maximum value below the threshold. e.g. First element is "1", because value[1] is the largest below threshold "1". Second element is "4", because value[4] is the
2018 Apr 19
0
create multiple categorical variables in a data frame using a loop
...pheno$log2pfoa,0.75, na.rm =T)]<-2 > cat.pfoa[pfas.pheno$log2pfoa >=quantile(pfas.pheno$log2pfoa,0.25, na.rm =T) > &pfas.pheno$log2pfoa <=quantile(pfas.pheno$log2pfoa,0.75, na.rm =T)]<-1 > } This would be somewhat more compact and easier to maintain if you used findInterval (untested in the absence of a data object, which is your responsibility): pfas.pheno <-within(pfas.pheno, { cat.pfoa <- findInterval( log2pfoa , c(-Inf, quantile( log2pfoa,c(.25,.75), Inf), na.rm =T), Inf)]-1 } ) `findInterval` numbers its intervals from 1, so to get a sequence starting...
2011 Feb 17
2
does range of values in array include a third value?
I'm using the range command to get the minimum and maximum values of an array as in x <- range(array_y) which gives me two values such as [1] -2 9 I need to be able to test if this range of values includes a third value. For example I'd like to query 1) does the range of -2 to 9 include 3, answer TRUE 2) does the range of -2 to 9 include -6, answer FALSE? All values could be
2009 Dec 10
0
Is there a variant of findInterval() such that v[i[j]] < x[j] <= v[i[j] + 1]?
In findInterval's help page, it says 'v[i[j]] <= x[j] < v[i[j] + 1]'. I'm wondering if there is a variant of it such that 'v[i[j]] < x[j] <= v[i[j] + 1]'.
2013 Mar 14
0
funciones (findInterval, which) y simulación discreta
Tengo 2 grandes inquietudes: Necesito aplicar la función findInterval a una lista donde su componentes son matrices(32x32), cuyos intervalos se conformaron de la siguiente manera: 1er paso. # a todas las matrices se las dividió en matrices superiores e inferiores d_sup <- lapply(Matriz,function(x){data.matrix(upper.tri(x)*x)}) d_inf <- lapply(Matriz,function(x...
2020 Mar 06
1
findInterval Documentation Suggestion
> On Friday, March 6, 2020, 8:56:54 AM EST, Martin Maechler <maechler at stat.math.ethz.ch> wrote: > Note that the? * -> LaTex -> PDF rendered version looks a bitnicer. Ah yes, that does indeed look quite a bit nicer. > I wrote the function and that help page originally. And thank you for doing so. It is a wonderful function. (0 sarcasm here). > For that reason,
2011 Jan 25
0
Map an Area to another
...6*6 matrix denotes an area and the contents of the cell denote the values the area gets inside that cell-zone (or sub-area). I would like to map this AREA into x,y function for x e[-1,1] ye[-1,1] I really didn't know how to implement that, so with help I got from a list member I tried to use FindInterval for the x,y plane. I am sure that it might be an easier way to do that so please do suggest it. If there is not then continue reading. In the picture below: http://img521.imageshack.us/f/maparea.gif/ You can see the matrix presented above placed inside the x e[-1,1] ye[-1,1] which from now on the...
2013 Jun 18
2
find closest value in a vector based on another vector values
Dear All, would you please provide your thoughts on the following: let us say I have: a <-c(1,5,8,15,32,69) b <-c(8.5,33) and I would like to extract from "a" the two values that are closest to the values in "b", where the length of this vectors may change but b will allways be shorter than "a". So at the end based on this example I should have the result
2009 May 22
5
Need a faster function to replace missing data
Dear List, I need some help in coming up with a function that will take two data sets, determine if a value is missing in one, find a value in the second that was taken at about the same time, and substitute the second value in for where the first should have been. My problem is from a fish tracking study. We put acoustic tags in fish and track them for several days. Location data is supposed