Displaying 20 results from an estimated 10000 matches similar to: "find position"
2009 Sep 13
2
How can I get "predict.lm" results with manual calculations ? (a floating point problem)
Hello dear r-help group
I am turning for you for help with FAQ number 7.31: "Why doesn't R think
these numbers are equal?"
http://cran.r-project.org/doc/FAQ/R-FAQ.html#Why-doesn_0027t-R-think-these-numbers-are-equal_003f
*My story* is this:
I wish to run many lm predictions and need to have them run fast.
Using predict.lm is relatively slow, so I tried having it run faster by
2005 Aug 09
3
floor() rounding problem?
Dear all,
Could someone please explain the following perculiarity?
> 2 == 0.2/0.1
[1] TRUE
> 3 == 0.3/0.1
[1] FALSE
Similarly,
floor(0.2/0.1) = 2
floor(0.3/0.1) = 2
Thank you,
Simon
2009 Mar 16
4
Match .3 in a sequence
Hello:I am trying to match the value 0.3 in the sequence seq(.2,.3). I get
> 0.3 %in% seq(from=.2,to=.3)
[1] FALSE
Yet
> 0.3 %in% c(.2,.3)
[1] TRUE
For arbitrary sequences, this "invisible .3" has been problematic. What is
the best way to work around this?
Thank you.
Dan
[[alternative HTML version deleted]]
2009 Jun 08
4
seq(...) strange logical value
Do you heve any idea why I get after this instruction everywhere false?
> seq (0, 1, by=0.1) == 0.3
[1] FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE
But after different step it's ok:
> seq(0, 1, by=0.1) == 0.4
[1] FALSE FALSE FALSE FALSE TRUE FALSE FALSE FALSE FALSE FALSE FALSE
--
View this message in context:
2007 Oct 24
1
is there a similar function to perform repeated statements as in SAS PROC MIXED?
PROC MIXED is used to fit mixed effects model for correlated data.
Usually we can use either a REPEATED statment or a RANDOM statement.
The random statement is corresponding to lme function in R -- specifying a
random effect term.
The repeated statement actually directly specifies the covariance structure
-- is there a similar function in R to do this? I currently want to specify
a unstructured
2008 Mar 03
7
help for the first poster- a simple question
Hi, there,
I cannot get accurate value for calculation.
for example:
ld<-sqrt(1*0.05*0.95*0.05*0.95)
0.05*0.95-ld=-6.938894e-18
0.05*0.95-ld==0 is False.
I met this problem in my program, how can I handle it. Thanks.
xj.
2006 Nov 22
3
odd behaviour of %%?
Dear R Helpers,
I am trying to extract the modulus from divisions by a sequence of
fractions.
I noticed that %% seems to behave inconsistently (to my untutored eye),
thus:
> 0.1%%0.1
[1] 0
> 0.2%%0.1
[1] 0
> 0.3%%0.1
[1] 0.1
> 0.4%%0.1
[1] 0
> 0.5%%0.1
[1] 0.1
> 0.6%%0.1
[1] 0.1
> 0.7%%0.1
[1] 0.1
> 0.8%%0.1
[1] 0
> 0.9%%0.1
The modulus for 0.1, 0.2, 0.4 and 0.8 is
2009 Aug 01
5
incorrect result (41/10-1/10)%%1 (PR#13863)
Full_Name: jan hattendorf
Version: 2.9.0
OS: XP
Submission from: (NULL) (213.3.108.185)
I get an incorrect result for
(41/10-1/10)%%1
[1] 1
The error did not occur with other numbers than 41 (1, 11, 21, 31, 51, ...)
test <- rep(NA, 1000)
for(i in 1:1000){
test[i] <- i/10-1/10
}
test[test%%1==0]
2009 Jun 19
1
cut with floating point, a bug?
With floating point numbers I'm seeing 'cut' putting values in the wrong
bands. An example below places 0.3 in (0.3,0.6] i.e. 0.3 > 0.3.
> x = 1:5*.1
> x
[1] 0.1 0.2 0.3 0.4 0.5
> cut(x, br=c(0,.3,.6))
[1] (0,0.3] (0,0.3] (0.3,0.6] (0.3,0.6] (0.3,0.6]
Levels: (0,0.3] (0.3,0.6]
I'm sure this is probably the same issue documented in the FAQ (7.31 Why
doesn't R
2007 Jul 13
2
nearest correlation to polychoric
Dear all,
Has someone implemented in R (or any other language)
Knol DL, ten Berge JMF. Least-squares approximation of an improper correlation matrix by a proper one. Psychometrika, 1989, 54, 53-61.
or any other similar algorithm?
Best regards
Jens Oehlschl?gel
Background:
I want to factanal() matrices of polychoric correlations which have negative eigenvalue. I coded
Highham 2002
2006 Oct 16
5
Re : Generate a random bistochastic matrix
Thanks, I tried someting like this, but computation takes times for large matrices
btransf <- function(y,X=length(y)^4) {
N <- length(y)
bm <- matrix(rep(1/N,N^2),N,N)
for(j in 1:X){
coord <- sample(1:N,4,replace=T)
d <- runif(1,0,min(bm[coord[1],coord[2]],bm[coord[3],coord[4]]))
2009 Apr 20
8
bug when subtracting decimals?
Try this:
0.7-0.3==0.4
(We get FALSE)
0.7-0.3<0.4
(We get TRUE)
but
0.8-0.3==0.5
(TRUE)
0.8-0.3<0.5
(FALSE)
Funny, he?
There is a way around:
round(0.7-0.3,1)==0.4
(TRUE)
Obviously there is a problem with some combinations of decimal subtractions,
that - we have the feeling - shouldt be solved.
Best regards
Sven & Wolfgang
--
View this message in context:
2009 Apr 20
8
bug when subtracting decimals?
Try this:
0.7-0.3==0.4
(We get FALSE)
0.7-0.3<0.4
(We get TRUE)
but
0.8-0.3==0.5
(TRUE)
0.8-0.3<0.5
(FALSE)
Funny, he?
There is a way around:
round(0.7-0.3,1)==0.4
(TRUE)
Obviously there is a problem with some combinations of decimal subtractions,
that - we have the feeling - shouldt be solved.
Best regards
Sven & Wolfgang
--
View this message in context:
2007 Feb 27
1
Additional args to fun in integrate() not found?
Hello, fellow Rdicts,
I have the code for the program below. I need to integrate a function
of "x" and "p". I use integrate to integrate over "x" and pass "p" as
an additional argument. "p" is specified and given default value in
the argument list. Still, integrate() cannot read "p", unless I
explicitly insert a numeric value in the
2008 Apr 24
2
problem with "which"
Hi,
I'm having trouble with the "which" or the "seq" function, I'm not sure.
Here's an example :
> lat=seq(1,2,by=0.1)
> lat
[1] 1.0 1.1 1.2 1.3 1.4 1.5 1.6 1.7 1.8 1.9 2.0
> which(lat==1)
[1] 1
> which(lat==1.1)
[1] 2
> which(lat==1.2)
[1] 3
> which(lat==1.3)
[1] 4
> which(lat==1.4)
[1] 5
> which(lat==1.5)
[1] 6
>
2008 Dec 05
3
Logical inconsistency
Dear colleagues
Please could someone kindly explain the following inconsistencies I've discovered when performing logical calculations in R:
8.8 - 7.8 > 1
> TRUE
8.3 - 7.3 > 1
> TRUE
Thank you,
Emma Jane
[[alternative HTML version deleted]]
2010 Jul 10
7
Need help on date calculation
Hi all, please see my code:
> library(zoo)
> a <- as.yearmon("March-2010", "%B-%Y")
> b <- as.yearmon("May-2010", "%B-%Y")
>
> nn <- (b-a)*12 # number of months in between them
> nn
[1] 2
> as.integer(nn)
[1] 1
What is the correct way to find the number of months between "a" and "b",
still
2009 Apr 17
3
Modular Arithmetic Error?
Hi,
I'm using the '%%' operator in some code, and am running into the following erroneous outcome:
> 1.2 %% 0.2
[1] 0.2
Unless I'm very mistaken, the result should be 0 (indeed, 12 %% 2 does result in 0). Furthermore:
> 1.20000000000000001 %% 0.2
[1] 0.2
> (1.2+1e17) %% .2
[1] 0
Warning message:
probable complete loss of accuracy in modulus
(Warning
2018 Aug 30
4
compairing doubles
Dear all,
I a bit unsure, whether this qualifies as a bug, but it is definitly a strange behaviour. That why I wanted to discuss it.
With the following function, I want to test for evenly space numbers, starting from anywhere.
.is_continous_evenly_spaced <- function(n){
if(length(n) < 2) return(FALSE)
n <- n[order(n)]
n <- n - min(n)
step <- n[2] - n[1]
test <-
2017 Jun 07
3
An R question
Hi all,
In checking my R codes, I encountered the following problem. Is there a
way to fix this?
I tried to specify options(digits=). I did not fix the problem.
Thanks so much for your help!
Hanna
> cdf(pmass)[2,2]==pcum[2,2][1] FALSE> cdf(pmass)[2,2][1] 0.9999758> pcum[2,2][1] 0.9999758
[[alternative HTML version deleted]]