Displaying 20 results from an estimated 80000 matches similar to: "how does R represent numbers?"
2008 Oct 22
3
retrieving matrix elements by giving pairs of row AND column numbers?
Hi,
this is probably a very trivial question but I can't figure out the right terms to find the solution in the list archive.
I have a matrix or a data.frame or the like:
> m <- matrix(ncol=3,seq(1,9))
> m
[,1] [,2] [,3]
[1,] 1 4 7
[2,] 2 5 8
[3,] 3 6 9
and now I wonder if one can provide somehow two vectors, one containing row numbers, the other
2012 Aug 15
4
which() function not finding certain numbers
Hi,
I am using 32-bit R v 2.15.1, on Mac OsX v 10.6.8 with R GUI 1.52 Leopard
build 32-bit (6188). I have also replicated this error on R 2.13.2 on a
windows 7 machine.
In some sequences of numbers, I am unable to use the which() function to
index certain values. It seems to be primarily numbers with a 3 in the
decimal.
For example:
> S=seq(0,4,0.01)
> which(S==2.02)
[1] 203
>
2004 Jul 28
6
elegant matrix creation
Hello everybody.
I am trying to reproduce a particular matrix in an elegant way. If I
have
jj1 <-
structure(c(1,2,3,1,2,3,1,2,3,1,2,3,1,2,3,1,2,
3,1,2,3,1,2,3,1,2,3,2,3,1,2,3,1,2,3,1,2,3,
1,2,3,1,2,3,1,2,3,1,2,3,1,2,3,1,3,1,2,3,1,
2,3,1,2,3,1,2,3,1,2,3,1,2,3,1,2,3,1,2,3,1,
2),.Dim = as.integer(c(9,9)))
[ image(jj1) is good here ] then I can get this with
2008 Apr 04
4
Arbitrary Precision Numbers
Hi
(If you're wondering, this is a Project Euler question :))
If I wanted to calculate the sum of the digits in the decimal representation
of 2^1000, what would be a good way to go about that? I've tried the
following methods:
# Calculate the sum of digits in the decimal representation of 2^n
# Only works for smaller values of n
bsum <- function(n) {
s <- 0
e <-
2004 Jan 14
2
R internal data types
I am trying to figure out R data types and/or storage mode. For example:
> #From a clean workspace
> gc()
used (Mb) gc trigger (Mb)
Ncells 415227 11.1 597831 16
Vcells 103533 0.8 786432 6
> x <- seq(0,100000,1)
> is.integer(x)
[1] FALSE
> is.double(x)
[1] TRUE
> object.size(x)
[1] 800036
> gc()
used (Mb) gc trigger (Mb)
Ncells 415247
2003 Jan 08
2
Undocumented bahavior of as.integer() (PR#2430)
as.integer() truncates doubles toward zero, as Splus does (at least v. 6.1
under Windows does). Thus:
> look <- (10 * seq(14)) - 76
> 10 * (73.1 + look)
[1] 71 171 271 371 491 586 681 791 886 981 1101 1201 1301 1401
> as.integer(10 * (73.1 + look))
[1] 70 170 270 370 490 586 681 791 886 981 1101 1201 1301 1401
... It is not documented in R! I propose appending
2009 Jun 23
1
Documentation/software inconsistency in `:` and seq
In 2.8.1/Windows:
According to ? :
Details:
For numeric arguments 'from:to' is equivalent to 'seq(from, to)' ...
Value:
For numeric arguments, a numeric vector. This will be of type
'integer' if 'from' and 'to' are both integers and representable
in the integer type, otherwise of type 'numeric'....
The first claim
1999 Dec 13
3
t.test inside function (PR#373)
Full_Name: Bill Simpson
Version: 65.1
OS: linux
Submission from: (NULL) (193.62.250.209)
Try this code as separate lines entered interactively, then try doit()
doit<-function()
{
x<-seq(1,10)
y1<-x+rnorm(10,1,1.5)
y2<-x+rnorm(10,1,1)
t.test(x,y1,paired=TRUE)
t.test(x,y2,paired=TRUE)
}
doit() apparently executes only the last of a series of t.test()s.
Maybe this is no bug,
2005 Apr 07
2
a couple of things about ":"
Dear R-devel,
A colleague was recently surprised by the behavior of the ":" operator (as
sequence generator), so I decided to dig a little bit. Here are a couple of
things I found.
- ?":" seems a bit imprecise. The Details section says:
`The operator : and the seq(from, to) form generate the sequence from,
from+1, ..., to.'
but `to' is not necessarily included in
2010 Mar 26
5
smart way to turn a vector into a matrix
Hello guys, I am working on a matrix which looks like this one:
> initialMatrix <-
> rbind(cbind(rep("A",3),seq(1,3)),cbind(rep("B",4),seq(1,4)),cbind(rep("C",3),seq(1,3)))
> initialMatrix
[,1] [,2]
[1,] "A" "1"
[2,] "A" "2"
[3,] "A" "3"
[4,] "B" "1"
[5,]
2007 Dec 04
1
seq() does not create proper numbers (PR#10489)
Full_Name: Rico Ihle
Version: 2.6.1
OS: Windows XP Professional Version 2002 Pentium(R) 4 CPU 3.2 GHz
Submission from: (NULL) (134.76.183.24)
# Bug in seq() function:
x <- seq(-2,2,by=0.01)
which(x==0.05)# How that??
# although:
x# 0.05 seems to be at position 206 of x!!:
x[206]
# Why is this not equal to 0.05?
# Reason:
x2 <- as.character(x);x2
x2[206]# Ooooh... It's really not equal
2011 Sep 16
3
How to save row values from a matrix into one vector?
Dear R users,
I guess, I have a quit simple problem, but I'm not getting the solution.
I create a matrix like this:
test <- matrix(seq(1,3,1),ncol=5,nrow=3)
then I want to create one vector, consisting of every row of the matrix.
My first idea was to do this with a for loop.
op <- vector()
for (o in 1:3){
op[o] <- as.vector(test.id[o,])
}
The results should be like this:
[1]
2016 Aug 03
2
seq.int does not return a sequence of integers sometimes
I have a script that goes wrong because I assumed that seq.int would
return integers.
Below please see it does not unless user is super cautious about
inserting "L" with inputs. I think seq.int should do coercion for me
before returning the sequence.
> xx <- seq.int(1,10)
> class(xx)
[1] "integer"
> is.integer(xx)
[1] TRUE
> xx <- seq.int(1,10, 2)
>
1999 Oct 05
3
problem with outer and image
I want to make a picture of a cos wave grating (pattern of fuzzy stripes).
First I try to make a plot of a cos wave:
x<-seq(1:100)
y<- 10*cos(2*pi*x*3/length(x)+0)+300
plot(x,y)
That works fine. 3 cycles of cos wave. Now try for grating.
time<-seq(1:100)
f<-function(x,time) 10*cos(2*pi*x*3/length(x)+0)+300
z<-outer(x,time,f)
image(x,time,z)
I get a vertical grating as expected, BUT
2010 Jul 23
2
decimal seperator
Hi R-List,
I have a question regarding R-language formats, I think. I am producing a
series of graphs (using plot, barplot, barchart, and bwplot, using either
text or mtext to place values on the graphs) and tables for a Francophone
country. In fact, I have already done so. However, while they are pleased
with the results they've requested I convert all of my decimal points into
the French
2005 Jan 12
2
Inaccuracy in seq() function (PR#7503)
Full_Name: Vlad Stolin
Version: R 2.0.0
OS: Windows 2000
Submission from: (NULL) (204.128.232.211)
When generating the sequence using seq() function with non-integer numbers
result is somewhat unpredictable. Example:
> v1<-seq(1.60,1.90,.05)
> v2<-c(1.60,1.65,1.70,1.75,1.80,1.85,1.90)
> v1-v2
[1] 0.000000e+00 2.220446e-16 2.220446e-16 0.000000e+00 0.000000e+00
0.000000e+00
2012 Dec 08
2
C function, double problem
Hi everybody,
here's my problem:
i call a C function which calculates a large number of double values and
puts them into an array which is passed from R as a parameter in the
function (like .C("function", other parameters, result = as.double( c ( 1
: quantity ) ).
When the values come back to R in the result array, they are all truncated
to their integer value (i.e. I lose the
2011 Apr 03
1
zoo:rollapply by multiple grouping factors
# Hi there,
# I am trying to apply a function over a moving-window for a large
number of multivariate time-series that are grouped in a nested set of
factors. I have spent a few days searching for solutions with no luck,
so any suggestions are much appreciated.
# The data I have are for the abundance dynamics of multiple species
observed in multiple fixed plots at multiple sites. (I total I
2018 Aug 25
4
Where does L come from?
On 25/08/2018 4:49 PM, Herv? Pag?s wrote:
> The choice of the L suffix in R to mean "R integer type", which
> is mapped to the "int" type at the C level, and NOT to the "long int"
> type, is really unfortunate as it seems to be misleading and confusing
> a lot of people.
Can you provide any evidence of that (e.g. a link to a message from one
of these
2011 Nov 16
1
R not 'seeing' numbers?!
Hello.
I recently came across the extremely strange problem (see below) of R
telling me that elements of a list do not exist...
I have tried running this small script on 2 computers (Mac OSX 10.7 &
Windows 7) running the latest releases or R (2.13.2 on Mac, 2.14.0 on Win).
I have tried it both in the standard R console, and in RStudio (v.
0.94.110), and all have the same problem.
Any