Displaying 20 results from an estimated 8000 matches similar to: "reshape()"
2002 Jun 26
3
sapply() and Monte Carlo
Dear Helplist
Some time ago, Professor Ripley gave me a tip which I thought was very
very useful for Monte Carlo simulation; I thought I'd pass it on to
the list, and ask whether this or a similar example could be added to
the sapply() manpage.
Suppose I have ten N(0,1) random variables and I'm interested in the
pair that are closest together:
R> min(diff(sort(rnorm(10))))
[1]
2002 Jun 13
0
possum sleeping: thanks and fisher.test() FEXACT error
Dear helplist
Many many thanks to everyone who helped me. The trick was to use
tabulate() or, better,
tab <- rep(0,50)
names(tab) <- 1:50
tab[names(table(sleeps))] <- table(c)
My original dataset was a list of 50 trees and a length 12 vector
recording which tree a certain possum slept in on 12 nights. As
Professor Ripley points out, a Monte-Carlo simulation is easy to set
up, and it
2002 Jun 12
4
table problems
dear helplist,
my student has fifty trees, numbered one to fifty, and a vector
recording which tree a certain possum slept in on 12 nights.
R> c
[1] 3 14 17 22 26 26 17 40 43 25 46 46
R>
Thus it slept in tree #3 on Monday, then tree #14 on Tues, and so on.
I wish to test the null hypothesis that the animal chooses trees
randomly; try
R> table(c)
c
3 14 17 22 25 26 40 43 46
1 1
2002 Jan 14
1
new R documentation on CRAN
Dear R community
A few weeks ago, I uploaded a small text file called R-and-octave.txt
to the contributed docs section of CRAN. This file details
octave/matlab commands and their (near) equivalents in R (Matlab is a
widely-used high-level graphics/mathematics tool and octave a free
clone).
Someone has just pointed out to me that I never announced its
existence to anyone, hence this email (I
2001 Oct 18
1
tapply problem
Hello everybody.
I have a question that has stumped me and the usual "apply" tricks
don't seem to work. I run a course where each student's performance
is marked by one or more assessors.
I have a data frame containing students' names, assessors' names and
their marks, arranged as follows:
ID student assessor Q1A Q1B Q1C Q2A Q2B Q3
1 2152833
2003 May 02
3
letters to numbers conversion
Hello List
How do I turn
R> simple.example.alphabetic
[,1] [,2] [,3]
[1,] "a" "b" "c"
[2,] "d" "e" "f"
[3,] "g" "h" "i"
into
R> simple.example.numeric
[,1] [,2] [,3]
[1,] 1 2 3
[2,] 4 5 6
[3,] 7 8 9
[ie "a" becomes 1, ..., "z"
2003 May 29
2
R CMD BATCH --vanilla --slave produces unwanted lines
Hello list
(thanks for all the help on my data.frame() question, especially to
Professor R for a working script...I was pleased to see the solution
wasn't obvious!)
Anyway, now I'm trying to run R in batch mode, but I'm getting extra
output, which I don't want (RedHat 8.3, R-1.7.0):
r:~% cat test.R
options(echo=FALSE)
write(rnorm(4),"")
r:~% R CMD BATCH --vanilla
2002 Dec 12
2
width and length arguments to postscript()
Hi everyone
This must be a FAQ but I can't find it anywhere...
I want a postscript image of a contour() plot, with axes of equal
length. Try
R> postscript(file="~/f.ps")
R> contour(matrix(rnorm(100),10,10))
R> dev.off()
This isn't what I want: the plotting region is, as documented, quarter
of an inch shy of the paper edge and the axes appear to be different
lengths.
2003 Mar 06
3
multiple plots and postscript()
Kia Ora everybody.
There must be an obvious answer to this, but I can't see it....
I want four square plots in one postscript file. The canonical answer
would be:
postscript(file="~/f.ps",width=5,height=5)
par(pty="s",mfrow=c(2,2))
plot(1:19,xlab="")
plot(1:19,xlab="")
plot(1:19,xlab="")
plot(1:19,xlab="")
dev.off()
But this
2003 Jun 23
3
right assignment ("->") and functions
Hi everyone
check this out [R-1.7.0]:
R> f1 <- function(x){x^2}
R> f1 -> f2
R> f2(4)
[1] 16
R>
R> function(x){x^2} -> f3
function(x){x^2} -> f3
R> f3(4)
Error: couldn't find function "f3"
Why does right assignment "->" work in the first but not the second
case? Can anyone else reproduce this?
--
Robin Hankin, Lecturer,
School of
2003 Jun 25
0
frequency table
Robin,
the initial output from apply() is always in the form you have below, but if
it can be 'simplified' into a structure like the matrix, it does so. The
same thing happens with sapply().
If you want to produce a nice matrix as the out put you have to ensure that
the simplification is possible. Here is one way.
> apply(x2, 2, function(x, v) table(factor(x, levels=v)),
2002 Sep 22
3
binom.test()
Hello everybody.
Does anyone else find the last test in the following sequence odd?
Can anyone else reproduce it or is it just me?
> binom.test(100,200,0.13)$p.value
[1] 2.357325e-36
> binom.test(100,200,0.013)$p.value
[1] 6.146546e-131
> binom.test(100,200,0.0013)$p.value
[1] 1.973702e-230
> binom.test(100,200,0.00013)$p.value
[1] 0.9743334
(R 1.5.1, Linux RedHat 7.1)
--
2010 Aug 30
1
Help With Post-hoc Testing
I am trying to do post-hoc tests associated with a repeated measures
analysis with on factor nested within respondents.
The factor (SOI) has 17 levels. The overall testing is working fine, but I
can''t seem to get the multiple comparisons to work.
The first step is to "stack" the data.
Then I used "lme" to specify and test the overall model.
Finally
2002 Mar 26
1
ellipsis question
Hello R experten
I have just written a little function to calculate all pairwise
combinations of two vector arguments:
> pair(c(1,2,3),c(7,8))
[,1] [,2]
[1,] 1 7
[2,] 1 8
[3,] 2 7
[4,] 2 8
[5,] 3 7
[6,] 3 8
>
I want to generalize this to any number of arguments, for example,
<fantasy>
> ntuple(c(1,2,3),c(7,8),c(14,15))
[,1] [,2]
2002 Apr 22
2
how can a function tell if defaults are used?
Hello everybody
Is there a good way for a function to tell whether the caller used the
defaults?
I'm writing a little function that may take a pair of real arguments
or a single complex argument (in which case I want the real and
imaginary components).
"e" <- function(first,second=first) {
if (all(first == second) & is.complex(first)) {
2003 Apr 22
3
lexical scope
Hi everyone
another documented feature that was a bit unexpected for me:
R> x <- 19
R> f <- function(t){t+x}
R> f(100)
[1] 119
--as expected: x is visible from within f()
..but...
R> g <- function(a){x <- 1e99 ; return(f(a))}
R> g(4)
[1] 23
--the "x" that is visible from within g() is just 19, which is not the
one I expected it to find.
R> rm(x)
2003 Feb 13
6
generic handling of NA and NaN and NULL
Hello everybody
I have a generic problem which the following toy function illustrates:
f <- function(n) {
if(abs(n) < pi) {
return(TRUE)
} else {
return(FALSE)
}
}
I want it to return TRUE if abs(n)<pi and FALSE otherwise. f() is
fine as far as it goes, but does not deal well with NA or NaN or NULL
(I want these to signal some problem with the
2002 Jan 17
2
R 1.4.0 much slower than R 1.3.1
Dear R-ers
I've recently upgraded to R-1.4 but I have noticed that it is slower
to load datasets than R-1.3.1:
R-1.3.1:
> system.time(a <- read.table("~/people/academics/mitchell/nzsl02.27",header=T))
[1] 40.86 0.51 54.10 0.00 0.00
>
R-1.4.0:
> system.time(a <- read.table("~/people/academics/mitchell/nzsl02.27",header=T))
[1] 293.24 30.76 478.35
2002 Nov 26
5
unexpected behaviour of rnorm()
Hello everyone.
If I do
f <- function(n){max(rnorm(n))}
plot(sapply(rep(5000,4000),f)) #[this takes my PC about 30 seconds]
then I get something quite unexpected: gaps in the distribution. For
me, the most noticable one is at about 3.6.
Do others get this? Is it an optical illusion? It can't be right,
can it? Or maybe I just don't understand the good ol' Gaussian very
2003 Mar 13
1
apply() and unary operators
Hi everyone.
What's going on here?
> a <- matrix(1:4,2,2)
> a
[,1] [,2]
[1,] 1 3
[2,] 2 4
> apply(a,2,sum)
[1] 3 7
> apply(a,2,"+")
[,1] [,2]
[1,] 1 3
[2,] 2 4
> apply(a,1,"+")
[,1] [,2]
[1,] 1 2
[2,] 3 4
>
help(apply) says that "+" should be quoted but is otherwise silent on
unary