Try this.
as.numeric(levels(fishdata$Age))[fishdata$Age]
HTH,
Thierry
ir. Thierry Onkelinx
Instituut voor natuur- en bosonderzoek / Research Institute for Nature
and Forest
Cel biometrie, methodologie en
Dear useRs,
I'm struggling with the new version of ggplot2. In the previous version
I did something like this. But now this yield an error (object fill
not found).
library(ggplot2)
dummy - data.frame(x = rep(1:10, 4), group = gl(4, 10))
dummy$y - dummy$x * rnorm(4)[dummy$group] + 5 *
]
Verzonden: maandag 3 september 2007 15:15
Aan: ONKELINX, Thierry
CC: r-help@stat.math.ethz.ch
Onderwerp: Re: [R] Legend issue with ggplot2
On 9/3/07, ONKELINX, Thierry [EMAIL PROTECTED] wrote:
Dear useRs,
I'm struggling with the new version of ggplot2. In the previous
version I did
Have you tried read.table() and the similar functions? I think they
would provide a much more simple solution for your problem.
HTH,
Thierry
ir. Thierry Onkelinx
Instituut voor natuur- en bosonderzoek / Research
Jorge,
I'm assuming that you mean dataframes of matrices. Then you could use
merge to join both dataframes into a new one. See ?merge for more
detail.
HTH,
Thierry
ir. Thierry Onkelinx
Instituut voor natuur- en
Dear Rainer,
Your could try something like this.
test - try( plot(runif(ff)) )
if(class(test) == try-error){
#put here code for an empty plot
}
Cheers,
Thierry
ir. Thierry Onkelinx
Instituut voor natuur- en
Dear Rainer,
Have you considered using Sweave?
HTH,
Thierry
ir. Thierry Onkelinx
Instituut voor natuur- en bosonderzoek / Research Institute for Nature
and Forest
Cel biometrie, methodologie en kwaliteitszorg /
Dear Ed,
In my opinion you don't need to set the slope to zero. Just test if the
slope in lm(d ~ t) is significant. If it is significant then you have
evidence that the slope is NOT zero. But when it is not significant (and
in your example it is), you can't say that it is zero. But doing some
?getwd()
ir. Thierry Onkelinx
Instituut voor natuur- en bosonderzoek / Research Institute for Nature
and Forest
Cel biometrie, methodologie en kwaliteitszorg / Section biometrics,
methodology and quality assurance
I think you need something like.
qplot(appetitive.stimulus, graphLabels, data=related.differences,
size=variance, colour=Appetitive Stimulus, xlim=c(-20,20), main=Title
here, xlab=Differences, ylab=Header Concepts) +
geom_point(aes(colour = Aversive Stimulus))
HTH,
Thierry
What you need is
b - data.frame(x = 1:10, y = c(10,9,8,7,6,6.5,7,8,9,10))
w - gls(y ~ I(x)+I(x^2),correlation=corARMA(p=1),method=ML,data=b)
Newdata - data.frame(x = seq(1, 10, length = 41))
plot(predict(w, newdata = Newdata), type=l)
I think you need to escape the '\' character in your string by adding an extra
'\' in front of it. So try
pdf(junk.pdf)
par(family=mono)
plot(1,1)
text(1,1, \\txx)
mtext(\\txx)
dev.off()
HTH,
Thierry
-Oorspronkelijk bericht-
Van: [EMAIL
:[EMAIL PROTECTED] Namens ONKELINX, Thierry
Verzonden: donderdag 19 juli 2007 13:56
Aan: Peter Dalgaard
CC: r-help@stat.math.ethz.ch; Uwe Ligges
Onderwerp: Re: [R] Strange warning in summary.lm
Dear Peter,
Here's an example. Notice the warning in the last two lines
of the summary
Dear useRs,
Recently I've discorved ggplot2 and I must say that I really like it,
although the documentation still is a working in progress.
My first question: How can I change the position of the labels and the
text of the labels? With a basic plot I would use axis(2, at =
-Oorspronkelijk bericht-
Van: Prof Brian Ripley [mailto:[EMAIL PROTECTED]
Verzonden: woensdag 25 juli 2007 12:20
Aan: ONKELINX, Thierry
CC: r-help@stat.math.ethz.ch
Onderwerp: Re: [R] Strange warning in summary.lm
On Wed, 25 Jul 2007, ONKELINX, Thierry wrote:
Dear Peter, Uwe
It's not very clear to me but I think summary(mod)$coef[, Std. Error]
is wat you need?
Cheers,
Thierry
ir. Thierry Onkelinx
Instituut voor natuur- en bosonderzoek / Research Institute for Nature
and Forest
Cel
]
Verzonden: donderdag 19 juli 2007 10:39
Aan: ONKELINX, Thierry
CC: r-help@stat.math.ethz.ch
Onderwerp: Re: [R] Strange warning in summary.lm
ONKELINX, Thierry wrote:
Dear useRs,
Lately I noticed a strange warning in the summary of a
lm-object. Any
idea what this warning is about
. ~William W. Watt
A statistical analysis, properly conducted, is a delicate dissection of
uncertainties, a surgery of suppositions. ~M.J.Moroney
-Oorspronkelijk bericht-
Van: Peter Dalgaard [mailto:[EMAIL PROTECTED]
Verzonden: donderdag 19 juli 2007 13:37
Aan: ONKELINX, Thierry
Dear useRs,
Lately I noticed a strange warning in the summary of a lm-object. Any
idea what this warning is about? I'm using R 2.5.1 on Win XP pro.
x - rnorm(100)
y - rnorm(100)
summary(lm(y~x))
Call:
lm(formula = y ~ x)
Residuals:
Min 1Q Median 3Q Max
-1,77809
Dear useRs,
I'm trying to use ggplot2 in Sweave (R 2.5.1). The plots use the alpha
channel, so I need to use pdf version 1.4. Search the mailinglist
archive I found two solutions: \SweaveOpts{echo = FALSE,
pdf.version=1.4} and explicit writing to a pdf 1.4 file. The latter
works but the first
Dear Bjorn,
Do you know that mean(xy*ind)+mean(xy*!ind) yields the same value for
all i? Maybe you meant mean(xy[ind]) + mean(xy[!ind])
sapply(xord, function(xordi, xy = x){
ind - xy xordi
mean(xy*ind)+mean(xy*!ind)
})
Cheers,
Thierry
A more elegant way to do this is
standard - sapply(calm, function(calmi){calmi / sqrt(emaTA(calmi ^ 2,
0.03))})
Cheers,
Thierry
ir. Thierry Onkelinx
Instituut voor natuur- en bosonderzoek / Research Institute for
Cat - c('a','a','a','b','b','b','a','a','b')
C1 - ifelse(Cat == 'a', -1, 1)
ir. Thierry Onkelinx
Instituut voor natuur- en bosonderzoek / Research Institute for Nature
and Forest
Cel biometrie, methodologie en
Assuming that id is a character.
tab[tab$id == 25-2006, ]
Cheers,
Thierry
ir. Thierry Onkelinx
Instituut voor natuur- en bosonderzoek / Research Institute for Nature
and Forest
Cel biometrie, methodologie en
?which.max
ir. Thierry Onkelinx
Instituut voor natuur- en bosonderzoek / Research Institute for Nature
and Forest
Cel biometrie, methodologie en kwaliteitszorg / Section biometrics,
methodology and quality assurance
Put the return values in a vector or list
somma - function (a, b) {
c - a+b
return (c(a = a, b = b, c = c))
}
somma(5,7)
a b c
5 7 12
somma - function (a, b) {
c - a+b
return (list(a = a, b = b, c = c))
}
somma(5,7)
$a
[1] 5
$b
[1] 7
$c
[1] 12
Cheers,
Thierry
Why don't you use a package like RODBC and read the data directly from
the Excel file? Then you probably won't have to worry on how to get the
dates in the right format.
Another, maybe easier, solution is to export the Excel to CSV and then
use read.csv().
Cheers,
Thierry
You need to put the else statement on the same line as the closing curly
bracket.
a - TRUE
if ( a ){
cat(TRUE,\n)
} else {
cat(FALSE,\n)
}
Cheers,
Thierry
ir. Thierry Onkelinx
Instituut voor natuur-
Steve,
You can do this with the package gstat. Look for ?krige of
?predict.gstat
Post further question on this topic on the R-sig-geo list. You'll get
more response.
Cheers,
Thierry
ir. Thierry Onkelinx
Instituut
Sure you can.
list(list(), list(), list())
library(fortunes)
fortune(Yoda)
Evelyn Hall: I would like to know how (if) I can extract some of the
information from the summary of my nlme.
Simon Blomberg: This is R. There is no if. Only how.
-- Evelyn Hall and Simon 'Yoda' Blomberg
Dear Taija,
You want lines but use points? Try
for(i in levels(fHCGB$code)){
with(subset(fHCGB,code==i),
plot(pooledPlateIntra, type=b, ylim=ylim, xlab=code, ylab=CV%)
lines(fHCGB$limitVarC, col=green))
}
Cheers,
Thierry
Since you are using function(x) the apply function is passing values to
x. So you need to use x inside the function.
Try something like this:
apply(raw.sample,1,function(x){t.test(x[alive],x[dead])})
Cheers,
Thierry
You can do than. You just need to specify the strings in the
axis-labels.
plot(y~x, axes = F)
axis(1, at = range(x), labels = c(Xmin, Xmax))
axis(2)
Cheers,
Thierry
ir. Thierry Onkelinx
Instituut voor natuur- en
Apply passes the row as a vector, not as a dataframe. So you need to remove the
colons in x[, alive] and x[, dead]
results -apply(raw.sample,1,function(x) t.test(x[alive],x[dead]))
Cheers,
Thierry
ir. Thierry Onkelinx
You could combine them with cbind, and then split the rows again inside
the function you're calling with apply.
Mat - cbind(mat1, mat2)
apply(Mat, 1, function(x){
row.mat1 - x[seq_len(length(x)/2)]
row.mat2 - x[length(x)/2 + seq_len(length(x)/2)]
cor(row.mat1, row.mat2)
})
?as.numeric
ir. Thierry Onkelinx
Instituut voor natuur- en bosonderzoek / Reseach Institute for Nature
and Forest
Cel biometrie, methodologie en kwaliteitszorg / Section biometrics,
methodology and quality assurance
Dear Fransico,
The distance matrix would be 102000 x 102000. So it would contain 1040400
values. If you need one bit for each value, this would requier 9,7 GB. So the
distance matrix won't fit in the RAM of your computer.
Cheers,
Thierry
Have a look at packages in the spatial taskview (spatstat, splancs).
Cheers,
Thierry
ir. Thierry Onkelinx
Instituut voor natuur- en bosonderzoek / Reseach Institute for Nature
and Forest
Cel biometrie, methodologie en
Marco,
I've done something similar with spatial data. I defined the points as
SpatialPoints, the grid as SpatialGrid (using the sp package). Then
table(overlay(grid, points)) will give you the number of points inside
each gridcell.
library(sp)
points - SpatialPoints(your.data.frame)
cellsize - 1
Dear Marije,
I think that aggregate() would make your life a lot easier.
aggregate(table.imputed, by = table.imputed[, 1], FUN = mean)
Cheers,
Thierry
ir. Thierry Onkelinx
Instituut voor natuur- en bosonderzoek /
2. I do most of my work in R using Emacs and ESS. That means that I
keep a file in an emacs window and I submit it to R one line at a
time or one region at a time, making corrections and iterating as
needed. When I am done, I just save the file with the last,
working, correct
Have a look at ?cbind, ?rbind and ?matrix
C - cbind(A, B)
C - rbind(A, B)
C - matrix(c(0:3, 0:3), ncol = 2)
Cheers,
Thierry
ir. Thierry Onkelinx
Instituut voor natuur- en bosonderzoek / Reseach Institute for Nature
You need to sed the ylim parameter in the plot function to the range
that you need.
Cheers,
Thierry
ir. Thierry Onkelinx
Instituut voor natuur- en bosonderzoek / Reseach Institute for Nature
and Forest
Cel biometrie,
Have you tried something like
df - cbind(df, ObJeCT[, 1:10])
Cheers,
Thierry
ir. Thierry Onkelinx
Instituut voor natuur- en bosonderzoek / Reseach Institute for Nature
and Forest
Cel biometrie, methodologie en
Dear Gunter,
I've rewritten your functions. But allow me to give you a few tips:
- don't be affraid to use some spacing and indentation. It makes code a
lot more readable
- I prefer to define all variables in a function or I pass them to the
function. In your case would recommend to define the
Erik,
I haven't seen an answer to your question, so I'll try to answer it. The
problem is that you switched the degrees of freedom. You had:
1 - pf(qf(.95, Vl, 1, ncp = 0), Vl, 1, ncp = Dl)
[1] 0.05472242
But it should be:
1 - pf(qf(.95, 1, Vl, ncp = 0), 1, Vl, ncp = Dl)
[1] 0.532651
Cheers,
Creating more than one graphic windows is, as far as I know, not
possible in R. But it's no problem to run a script which create multiply
jpeg's. See ?jpeg on how to create jpeg's.
Cheers,
Thierry
ir. Thierry
a - c(A,B,C,D)
b - c(A,B,E,F)
c - c(A,C,E,G)
Df - cbind(a, b, c)
apply(Df, 2, function(x)(LETTERS[1:7] %in% x))
a b c
[1,] TRUE TRUE TRUE
[2,] TRUE TRUE FALSE
[3,] TRUE FALSE TRUE
[4,] TRUE FALSE FALSE
[5,] FALSE TRUE TRUE
[6,] FALSE TRUE FALSE
[7,] FALSE FALSE
RSF_EU$AREA[RSF_EU$AREA=x]
ir. Thierry Onkelinx
Instituut voor natuur- en bosonderzoek / Reseach Institute for Nature
and Forest
Cel biometrie, methodologie en kwaliteitszorg / Section biometrics,
methodology and
John,
Two things. You don't need to pout the cc variable in the apply. Use
instead something like this.
apply(cc, 2, fn1, y = mylist)
But this still doesn't solve your problem. You'll need to rewrite your
function like this.
fn2 - function(x, y, i){
+ tt - table(x[, i])
+ names(tt) -
Maybe this isn't the most elegant way, but it should work.
dd$g - -1
dd$g[dd$aa == a] - 1
Cheers,
Thierry
ir. Thierry Onkelinx
Instituut voor natuur- en bosonderzoek / Reseach Institute for Nature
and Forest
Cel
See ?points, ?lines and ?par (especially par(new = T)).
Reading an introduction book about R might be a good idea if you're new.
Dalgaard (Introductory Statistics with R)
Everitt Hothorn (A Handbook of Statistical Analyses Using R)
Cheers,
Thierry
?aggregate
?by
ir. Thierry Onkelinx
Instituut voor natuur- en bosonderzoek / Reseach Institute for Nature
and Forest
Cel biometrie, methodologie en kwaliteitszorg / Section biometrics,
methodology and quality
Dear Shubha,
The error message tells you that the error occurs in the line:
merge(d_mer,cdaily)
And the problem is that d_mer and cdaily have a different class. It
looks as you need to convert cdaily to the correct class (same class as
d_mer).
Don't forget to use traceback() when
Have you tried the tri-package?
Cheers,
Thierry
ir. Thierry Onkelinx
Instituut voor natuur- en bosonderzoek / Reseach Institute for Nature
and Forest
Cel biometrie, methodologie en kwaliteitszorg / Section
A statistical analysis, properly conducted, is a delicate dissection of
uncertainties, a surgery of suppositions. ~M.J.Moroney
-Oorspronkelijk bericht-
Van: Shubha Vishwanath Karanth [mailto:[EMAIL PROTECTED]
Verzonden: dinsdag 13 februari 2007 16:06
Aan: ONKELINX, Thierry; r-help
, is a delicate dissection of
uncertainties, a surgery of suppositions. ~M.J.Moroney
-Oorspronkelijk bericht-
Van: [EMAIL PROTECTED]
[mailto:[EMAIL PROTECTED]
Verzonden: dinsdag 13 februari 2007 18:04
Aan: ONKELINX, Thierry
CC: r-help@stat.math.ethz.ch
Onderwerp: RE2: [R] Suddenly Subscript out
Dear Steve,
Reading the data shouldn't be a problem with RODBC. I've been doing that
plenty of times. I'm not sure about writing, but I suppose you probably
will.
Cheers,
Thierry
ir. Thierry Onkelinx
Instituut voor
That's something for the %in% command. Try this (untested!)
tab[(tab$id %in% tabella$id) == FALSE, ]
Cheers,
Thierry
ir. Thierry Onkelinx
Instituut voor natuur- en bosonderzoek / Reseach Institute for Nature
and
You need %in%
a %in% x
d %in% x
ir. Thierry Onkelinx
Instituut voor natuur- en bosonderzoek / Reseach Institute for Nature and Forest
Cel biometrie, methodologie en kwaliteitszorg / Section biometrics, methodology
?unique
unique(A[, 2])
ir. Thierry Onkelinx
Instituut voor natuur- en bosonderzoek / Reseach Institute for Nature
and Forest
Cel biometrie, methodologie en kwaliteitszorg / Section biometrics,
methodology and
The code of the function plot.logi.hist is defined in appendix A of the
article you referred to.
Cheers,
Thierry
ir. Thierry Onkelinx
Instituut voor natuur- en bosonderzoek / Reseach Institute for Nature
and Forest
Instead of discussing this odd behaviour of TINN-R, I would prefer a discussion
on importing data through the clipboard. In my opinion it isn't a good a idea
to import data with the clipboard. I know that it's a quick and dirty way to
get your data fast into R.
But I see two major drawbacks.
You need something like this:
sapply(objects() , function(x)(dim(eval(parse(text = x)
a - rnorm(1)
b - matrix(rnorm(4), ncol = 2, nrow = 2)
sapply(objects() , function(x)(dim(eval(parse(text = x)
$a
NULL
$b
[1] 2 2
Cheers,
Thierry
See ?getwd and ?setwd to set the working directory
See ?load and ?save to read the workspace.
Cheers,
Thierry
ir. Thierry Onkelinx
Instituut voor natuur- en bosonderzoek / Reseach Institute for Nature
and Forest
I can think of two options:
1. Use R2HTML and save the html output as PDF
2. Use Sweave and compile the LaTeX file to PDF. Search the mailing list
archive on how to save the graphs as png or jpeg (as Sweave will
standard generate eps or pdf graphs).
Cheers,
Thierry
This is due to the internal representation of 0.1, which is not exactly
0.1 but very close to it. If you want to do an integer divide, you
should only use integers to divide with.
Cheers,
Thierry
ir. Thierry Onkelinx
dev.list() will give a list with all open devices. dev.off() will close
the current device.
Cheers,
Thierry
ir. Thierry Onkelinx
Instituut voor natuur- en bosonderzoek / Reseach Institute for Nature
and Forest
Cel
Is the length of all your datasets equal? If not try
etype - rep(c(sd1, sd2, sd3, sd4), c(length(data1), length(data2),
length(data3), length(data4))
Cheers,
Thierry
ir. Thierry Onkelinx
Instituut voor natuur- en
Correct me if I'm wrong, but a few weeks ago my professor from the
statistical computing class told us that SAS sometimes stores dates
including the time but only displays the date. So it looks like the time
isn't stored. This was the case with data imported from Excel. In our
exercise we had to
The arrows are messed up because they are partially outside the borders of the
barplot. Try adding a good ylim to the barplot. Something like:
b - barplot(tab, beside=T, ylim = c(0, 8))
Cheers,
Thierry
ir. Thierry
There is no such thing as an unpaired t-test. A t-test can be a paired,
one sample or two sample t-test. Since you want to compare the sample
against a given mean, you need a one sample t-test. You tried to do a
two sample test. That didn't work because you need at least two
observations in each
Hi Daniel,
Make sure to include working code and list all needed packages. I couldn't run
your code on my machine.
If you want equal data points in each class, then you could take every n point
from the sorted vector. This example generates the breakpoints to divide a
vector in 10 parts.
x
Dear all,
I was wondering if it's possible to simplify graphs created with Sweave.
I'm using in a document several plots with each about 4000 points
(qqnorm(rnorm(4000))). It looks likes the information of each points is
maintained in the graph. As a result of that the pdf filesize get's
quite
A quick answer to your questions:
1. Since nobody knows the true delta. I prefer to calculate the power for a
range of deltas. Most of the time for a range spanning - 2 * expected delta up
to 2 * expected delta. This gives an idea on how the power changes if delta
changes.
2. ?power.t.test
I think your script is slow because it has to recalculate the same model
five times. I've tried to avoid this by rewriting your function(df).
function(df){
fit - summary(lm(distance ~ generation, data=df))
result - c(fit$$r.squared, $coefficients[2], $coefficients[4],
, is a delicate dissection of
uncertainties, a surgery of suppositions. ~M.J.Moroney
-Oorspronkelijk bericht-
Van: [EMAIL PROTECTED]
[mailto:[EMAIL PROTECTED] Namens ONKELINX, Thierry
Verzonden: woensdag 25 oktober 2006 11:36
Aan: [EMAIL PROTECTED]; r-help@stat.math.ethz.ch
Onderwerp: Re
Large for loops are slow. Try to avoid them using apply, sapply, etc.
I've made the paste statements a lot shorter by using collapse. See
?paste for more info.
Append.SQL - function(x, channel){
sql=INSERT INTO logger (time, v1, v2, v3, v4, v5, v6, v7, v8, v9,
v10)
Your problem would be a lot easier if you coded the location in one
variable instead of three variables. Then you could calculate the means
with one line of code:
by(results$q1, results$location, mean)
With your dataset you could use
by(results$London, results$location, mean)
by(results$Rome,
Usually I try to do all data import before I do long calculations. A
simple workaround for your problem would be:
foo - function(dsn) {
db - odbcConnect(dsn)
odbcSetAutoCommit(db, FALSE)
data - someDatabaseOperation(db)
odbcClose(db)
data2 - someLongCalculation(data)
db -
This should work. I try to avoid for loops because large (or nested) for
loops tend to consume a lot of memory.
one.dataset - function(dummy = 0, slope = 0.01){
return(c(yr1= mean(rbinom(50,1,.5)), yr2 =mean(rbinom(50,1,.5 +
slope)), yr3 =mean(rbinom(50,1,.5 + 2 * slope)), yr4
Assuming you only use the X direction to split the data into 10 m cells.
table(list(Species, round(X, digits = -1)))
This will generate a table with the number of seedlings per species in
each 10 m cell. Divide this by the area of each cell and you get the
densities.
Cheers,
Thierry
factor(new.fact) will do the trick. But that will recode the levels and
that might be something you don't want.
fact = as.factor(c(rep(A, 3),rep(B, 3), rep(C, 3)))
new.fact = fact[1:6]
new.fact
[1] A A A B B B
Levels: A B C
factor(new.fact)
[1] A A A B B B
Levels: A B
Cheers,
Thierry
83 matches
Mail list logo