similar to: x[0]: Can '0' be made an allowed index in R?

Displaying 20 results from an estimated 20000 matches similar to: "x[0]: Can '0' be made an allowed index in R?"

2024 Apr 21
1
x[0]: Can '0' be made an allowed index in R?
?s 08:55 de 21/04/2024, Hans W escreveu: > As we all know, in R indices for vectors start with 1, i.e, x[0] is not a > correct expression. Some algorithms, e.g. in graph theory or combinatorics, > are much easier to formulate and code if 0 is an allowed index pointing to > the first element of the vector. > > Some programming languages, for instance Julia (where the index for
2024 Apr 21
1
x[0]: Can '0' be made an allowed index in R?
https://cran.r-project.org/package=index0 On Sun, Apr 21, 2024, 3:56 AM Hans W <hwborchers at gmail.com> wrote: > As we all know, in R indices for vectors start with 1, i.e, x[0] is not a > correct expression. Some algorithms, e.g. in graph theory or combinatorics, > are much easier to formulate and code if 0 is an allowed index pointing to > the first element of the vector.
2024 Apr 21
1
x[0]: Can '0' be made an allowed index in R?
Also https://cran.r-project.org/package=Oarray (which is older and hence possibly more stable) On 2024-04-21 3:55 a.m., Hans W wrote: > As we all know, in R indices for vectors start with 1, i.e, x[0] is not a > correct expression. Some algorithms, e.g. in graph theory or combinatorics, > are much easier to formulate and code if 0 is an allowed index pointing to > the first element
2024 Apr 22
2
x[0]: Can '0' be made an allowed index in R?
You could have negative indices. There are two ways to do this. 1) provide a large offset. Offset <- 30 for (i in -29 to 120) { print(df[i+Offset])} 2) use absolute values if all indices are negative. for (i in -200 to -1) {print(df[abs(i)])} Tim -----Original Message----- From: R-help <r-help-bounces at r-project.org> On Behalf Of Peter Dalgaard via R-help Sent: Monday, April 22,
2024 Apr 22
1
x[0]: Can '0' be made an allowed index in R?
Hans, It is a good question albeit R made a conscious decision to have indices that correspond to things like row numbers and thus start with 1. Some others have used a start of zero but often for reasons more related to making use of all combinations of the implementation of integers on many machines where starting with 1 would only allow use of the 255 of the 256 combinations available in 8
2024 Apr 22
1
x[0]: Can '0' be made an allowed index in R?
Heh. Did anyone bring up negative indices yet? -pd > On 22 Apr 2024, at 10:46 , Rolf Turner <rolfturner at posteo.net> wrote: > > > See fortunes::fortune(36). > > cheers, > > Rolf Turner > > -- > Honorary Research Fellow > Department of Statistics > University of Auckland > Stats. Dep't. (secretaries) phone: > +64-9-373-7599
2024 Apr 23
2
x[0]: Can '0' be made an allowed index in R?
Hello Peter, Unless I too misunderstand your point, negative indices for removal do work with the Oarray package (though -0 doesn't work to remove the 0th element, since -0 == 0 -- perhaps what you meant): > library(Oarray) > v <- Oarray(1:10, offset=0) > v [0,] [1,] [2,] [3,] [4,] [5,] [6,] [7,] [8,] [9,] 1 2 3 4 5 6 7 8 9 10 > dim(v)
2024 Apr 23
1
x[0]: Can '0' be made an allowed index in R?
Doesn't sound like you got the point. x[-1] normally removes the first element. With 0-based indices, this cannot work. - pd > On 22 Apr 2024, at 17:31 , Ebert,Timothy Aaron <tebert at ufl.edu> wrote: > > You could have negative indices. There are two ways to do this. > 1) provide a large offset. > Offset <- 30 > for (i in -29 to 120) { print(df[i+Offset])} >
2024 Apr 23
1
x[0]: Can '0' be made an allowed index in R?
I think it might be fair to say that the discussion is becoming a tad wider than whether you want your data structures indexed starting from 0 or 1. Programming languages have added functionality to do many things on top of the simple concept of accessing or changing the nth element one at a time. If someone wants to make a parallel way to handle things, it may work for some uses but not others
2016 Sep 09
3
Different results for tan(pi/2) and tanpi(1/2)
The same argument would hold for tan(pi/2). I don't say the result 'NaN' is wrong, but I thought, tan(pi*x) and tanpi(x) should give the same result. Hans Werner On Fri, Sep 9, 2016 at 8:44 PM, William Dunlap <wdunlap at tibco.com> wrote: > It should be the case that tan(pi*x) != tanpi(x) in many cases - that is why > it was added. The limits from below and below of the
2016 Sep 09
3
Different results for tan(pi/2) and tanpi(1/2)
As the subject line says, we get different results for tan(pi/2) and tanpi(1/2), though this should not be the case: > tan(pi/2) [1] 1.633124e+16 > tanpi(1/2) [1] NaN Warning message: In tanpi(1/2) : NaNs produced By redefining tanpi with sinpi and cospi, we can get closer: > tanpi <- function(x) sinpi(x) / cospi(x) > tanpi(c(0, 1/2, 1, 3/2, 2))
2010 Mar 21
2
Find a rectangle of maximal area
For an application in image processing -- using R for statistical purposes -- I need to solve the following task: Given n (e.g. n = 100 or 200) points in the unit square, more or less randomly distributed. Find a rectangle of maximal area within the square that does not contain any of these points in its interior. If a, b are height and width of the rectangel, other constraints may have to be
2008 Apr 01
2
Applying rbind() to a sequence of data frame names
I have a set of data frames ds1, ds2, ... each having the same columns and column names: ds1 <- data.frame(x=c(1,2,3,4), y=c(5,6,7,8)) ds1 <- data.frame(x=c(9,10,11,12), y=c(13,14,15,16)) ... and I would like to combine them into just one data frame like ds <- rbind(ds1, ds2, ...) Because there are so many of them, I will have to use a character array nms <-
2007 Sep 16
1
programming question
Dear list, I have a vector of numbers, let's say: myvec <- c(2, 8, 24, 26, 51, 57, 58, 78, 219) My task is to reduce this vector to non-reducible numbers; small numbers can cross-out some of the larger ones, based on a function let's say called reduce() If I apply the function to the first element 2, my vector gets shorted to: > (myvec <- reduce(myvec[1])) [1] 2 24 51
2010 Jan 18
5
[LLVMdev] [patch] Union Types - work in progress
On Jan 16, 2010, at 11:15 AM, Talin wrote: > OK here's the patch for real this time :) > > On Fri, Jan 15, 2010 at 4:36 PM, Talin <viridia at gmail.com> wrote: > Here's a work in progress of the union patch. Note that the test > "union.ll" does not work, so you probably don't want to check this > in as is. However, I'd be interested in any
2023 Aug 13
4
Noisy objective functions
While working on 'random walk' applications, I got interested in optimizing noisy objective functions. As an (artificial) example, the following is the Rosenbrock function, where Gaussian noise of standard deviation `sd = 0.01` is added to the function value. fn <- function(x) (1+rnorm(1, sd=0.01)) * adagio::fnRosenbrock(x) To smooth out the noise, define another
2010 Dec 06
1
How to formulate constraint like abs(x) = y in constrOptim (or other)
Hello list reader, I am trying to form some constraints for an optimization I am working on. I think I have understand the use of the constraints in matrix form. I use them like: constr_mat<- -diag(2) constr_vec<- rep(-0.05,2) constr_mat<- rbind(constr_mat, diag(2)) constr_vec<- c(constr_vec, rep(-1, 2)) To get parameters in the interval [-1, 0.05]. (And this works so far) Now I
2009 Jul 07
3
r-project.org address blacklisted by anti-spam software
Dear List: An e-mail mentioning the r-project.org address and sent to a friend at a German university was considered spam by the local spam filter. Its reasoning: the URL "r-project.org" is blacklisted at uribl.swinog.ch resp. at antispam.imp.ch. I checked the list http://antispam.imp.ch/swinog-uri-rbl.txt [caution: long list] and indeed, there it was. Can anybody explain how or
2010 Jan 28
0
[LLVMdev] [patch] Union Types - work in progress
OK here's a new version of the patch - and the unions.ll test actually passes :) On Mon, Jan 18, 2010 at 1:40 PM, Chris Lattner <clattner at apple.com> wrote: > > On Jan 16, 2010, at 11:15 AM, Talin wrote: > > OK here's the patch for real this time :) >> >> On Fri, Jan 15, 2010 at 4:36 PM, Talin <viridia at gmail.com> wrote: >> Here's a work
2008 Aug 28
2
sample consecutive integers efficiently
Hi all, I have some rough code to sample consecutive integers with length according to a vector of lengths #sample space (representing positions) pos<-c(1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20) #sample lengths lengths<-c(2,3,2) From these two vectors I need a vector of sampled positions. the sampling is without replacement, making things tough as the sampled integers need