Displaying 20 results from an estimated 40000 matches similar to: "Tricky (?) conversion from data.frame to matrix where not all pairs exist"
2013 Mar 11
2
How to 'extend' a data.frame based on given variable combinations ?
Dear expeRts,
I have a data.frame with certain covariate combinations ('group' and 'year')
and corresponding values:
set.seed(1)
x <- data.frame(group = c(rep("A", 4), rep("B", 3)),
year = c(2001, 2003, 2004, 2005,
2003, 2004, 2005),
value = rexp(7))
My goal is essentially to
2012 Dec 08
5
How to efficiently compare each row in a matrix with each row in another matrix?
Dear expeRts,
I have two matrices A and B. They have the same number of columns but possibly different number of rows. I would like to compare each row of A with each row of B and check whether all entries in a row of A are less than or equal to all entries in a row of B. Here is a minimal working example:
A <- rbind(matrix(1:4, ncol=2, byrow=TRUE), c(6, 2)) # (3, 2) matrix
B <-
2012 Mar 01
2
How to colorize the panel backgrounds of pairs()?
Dear expeRts,
I would like to colorize the backgrounds of a pairs plot according to the respective panel number. Here is what I tried (without success):
count <- 0
mypanel <- function(x, y, ...){
count <<- count+1
bg. <- if(count %in% c(1,4,9,12)) "#FDFF65" else NA
points(x, y, cex=0.5, bg=bg)
}
U <- matrix(runif(4*500), ncol=4)
pairs(U, panel=mypanel)
I
2010 Dec 29
2
How to create an array of lists of multiple components?
Hi,
how can I create an array of lists of three components?
This approach does not work:
n1 <- 2
n2 <- 4
n3 <- 5
res <- array(rep(vector("list",3), n1*n2*n3), dim = c(n1,n2,n3))
res[1,1,1] # is not a list with three components...
The goal is that res[1,1,1] is a list with three components. Also, appending the
components didn't work. For example, I tried:
component
2016 May 05
4
R process killed when allocating too large matrix (Mac OS X)
Hi Simon,
thanks for your quick reply.
1) ... so you can reproduce this?
2) Do you know a way how this can be 'foreseen'? We allocate larger
matrices in the copula package depending on the user's input
dimension. It would be good to tell her/him "Your dimension is quite
large. Be aware of killers in your neighborhood"... before the killer
attacks.
Thanks & cheers,
2011 May 27
1
How to convert an ftable object to a matrix including the row names?
Dear expeRts,
What's the easiest way to convert an ftable object to a matrix such that the
row names of the ftable object are shown in the first couple of columns of the
matrix? This is (typically) required, for example, when the final goal is to print
the matrix via xtable.
Below is a rather complicated example of how to do it...
Cheers,
Marius
## Goal: convert an ftable() to a
2011 Aug 17
3
How to apply a function to subsets of a data frame *and* obtain a data frame again?
Dear all,
First, let's create some data to play around:
set.seed(1)
(df <- data.frame(Group=rep(c("Group1","Group2","Group3"), each=10),
Value=c(rexp(10, 1), rexp(10, 4), rexp(10, 10)))[sample(1:30,30),])
## Now we need the empirical distribution function:
edf <- function(x) ecdf(x)(x) # empirical distribution function evaluated at x
##
2016 May 05
1
R process killed when allocating too large matrix (Mac OS X)
Hi,
Interesting "feature" in 10.11.4. I wonder if the process is killed
before or after malloc() returns. If before, it seems very blunt:
"You're asking too much and I don't like it so I kill you now".
If after it doesn't look much better: "You're asking a lot and I
don't like it but I give it to you anyway. I'll kill you quickly
later".
Why
2015 Feb 03
2
Seed in 'parallel' vignette
Hi,
This is most likely only a minor technicality, but I saw the
following: On page 6 of the 'parallel' vignette
(http://stat.ethz.ch/R-manual/R-devel/library/parallel/doc/parallel.pdf),
the random-number generator "L'Ecuyer-CMRG" is said to have seed
"(x_n, x_{n-1}, x_{n-2}, y_n, y_{n-1}, y_{n-2})". However, in L'Ecuyer
et al. (2002), the seed is given with
2010 Dec 22
3
How to integrate a function with additional argument being a vector or matrix?
Dear expeRts,
I somehow don't see why the following does not work:
integrand <- function(x, vec, mat, val) 1 # dummy return value
A <- matrix(runif(16), ncol = 4)
u <- c(0.4, 0.1, 0.2, 0.3)
integrand(0.3, u, A, 4)
integrate(integrand, lower = 0, upper = 1, vec = u, mat = A, val = 4)
I would like to integrate a function ("integrand") which gets an "x" value (the
2016 May 04
1
R process killed when allocating too large matrix (Mac OS X)
Dear expeRts,
The following code leads to R being killed (under Mac OS X 10.11.4; R
installed from source; also happened under a previous unstable
version):
m <- matrix(0, 100000, 100000)
I expected an error that a vector of this size could not be allocated.
Besides the above (a bug?), how can I find out beforehand whether or
not a square matrix can be allocated?
Cheers,
Marius
PS: Here
2010 Dec 30
5
Why is format(10000, big.mark = "\\,") not 10\,000?
Hi,
why does format(10000, big.mark = "\\,") not give me "10\,000"? How can I get this kind of "big.mark"?
Cheers,
Marius
2011 Apr 06
7
Quiz: Who finds the nicest form of X_1^\prime?
Dear expeRts,
I would like to create a plotmath-label of the form X_1^\prime. Here is how to *not* do it [not nicely aligned symbols]:
plot(0,0,main=expression(italic(X*minute[1])))
plot(0,0,main=expression(italic(X[1]*minute)))
plot(0,0,main=expression(italic(X)[1]*minute))
Any suggestions?
Cheers,
Marius
2010 Dec 30
1
latex() etc.: How to nicely format a matrix for a LaTeX document?
Dear (T)eXpeRts,
I try to create a LaTeX table from an R matrix for the first time. I am not sure what the "best" approach is, I just read about latex() from Hmisc (toLatex() didn't work).
Consider the following minimal example:
library(Hmisc)
mat <- matrix(c(1,NA,3,100,10000,4), ncol = 3, byrow = TRUE)
latex(mat, file = "", booktabs = TRUE, numeric.dollar = FALSE,
2010 Dec 26
1
lattice splom: how to adjust space between tick marks and tick labels?
Dear expeRts,
how can I decrease the space between the tick marks and the corresponding labels in an splom?
See here:
library(lattice)
U <- matrix(runif(4000), ncol = 8)
splom(U, axis.text.cex = 0.2) # => space between the [small] tick labels and tick marks is/seems to be too large
I checked ?panel.pairs but could not find an option for that.
Cheers,
Marius
2011 Mar 13
1
R hangs when connected via VPN [incl. minimal example]
Dear expeRts,
This is a similar post as on R-SIG-MAC [I didn't receive an answer there; not sure if it was the right place to post either].
I'm running R version 2.12.1 (Platform: x86_64-apple-darwin9.8.0/x86_64 (64-bit))
on a MacBook Pro under Mac OS X 10.6.6. The following minimal example runs fine
under this setup. However, if I am connected to a server via a VPN client
[Cisco
2012 Sep 15
2
How to convert the output of tapply() so that it has the same order as the input?
Hi,
I try to apply a function to subsets of a data.frame. tapply() does the job, but
the as output, I am looking for a vector (not an array/matrix) ordered in the
same way as the original data, so I can simply cbind the result to the original
data.frame. Below is a minimal example.
I know that there are packages that can do these things easier, but I'm looking
for a fast solution not
2016 May 04
1
R process killed when allocating too large matrix (Mac OS X)
> Can you elaborate on "leads to R being killed"? You should tell to the killer not to do it again :).
Hi Simon!
Sure, but who do you tell it if you don't know the killer?
This is all the killer left me with, the 'crime scene' if you like :-)
> m <- matrix(0, 90000, 100000)
Killed: 9
My colleague Wayne Oldford also tried it on his Mac machine and
apparently the
2014 Aug 22
3
parallel::detectCores(TRUE) gives: Error in system(cmd, TRUE) : error in running command
Hi,
Both under the current R-devel (r66456) and a version from about 3
months ago, I experience the following behavior:
> parallel::detectCores(TRUE)
Error in system(cmd, TRUE) : error in running command
> traceback()
3: system(cmd, TRUE)
2: gsub("^ +", "", system(cmd, TRUE)[1])
1: parallel::detectCores(TRUE)
>
This is on Ubuntu 14.04. Does anybody else see this? [I
2010 Dec 05
1
How to catch both warnings and errors?
Dear expeRts,
I am struggling with warning/error handling.
I would like to call a function which can produce either
a) normal output
b) a warning
c) an error
Since the function is called several (thousand) times in a loop, I would like
to proceed "quietly" and collect the warnings and errors [to deal with them at a
later point].
I have seen constructs with tryCatch (which can