Displaying 20 results from an estimated 20000 matches similar to: "Got "Unexpected ELSE error""
2007 May 30
1
Sort in ecdf
Hi!
I've noticed the ecdf() R code (R ver. 2.5.0) contains two call to sort:
--- [R-code] ---
ecdf <- function(x)
x <- sort(x)
n <- length(x)
if (n < 1)
stop("'x' must have 1 or more non-missing values")
vals <- sort(unique(x))
rval <- approxfun(vals, cumsum(tabulate(match(x, vals)))/n,
method
2004 Aug 31
7
blockwise sums
I am looking for a function like
my.blockwisesum(vector, n)
that computes sums of disjoint subsequences of length n from vector
and can work with vector lengths that are not a multiple of n.
It should give me for instance
my.blockwisesum(1:10, 3) == c(6, 15, 24, 10)
Is there a builtin function that can do this?
One could do it by coercing the vector into a matrix of width n,
and then use
2007 Jun 04
2
Abstract plot
I want to make a plot, but instead of showing _numerical_ values,
I would like to show _symbolic_ values.
For example, I want to plot a function y = a x + b, where
x varies between Xmin and Xmax. I would like the plot
to show, in the x-axis, the strings Xmin and Xmax, instead
of their numeric values. Is it possible?
Alberto Monteiro
2007 Nov 19
4
sequence of vectors
Dear All,
I wonder if there is any R function to generate a sequence of vectors from existing ones. For example:
x 1<- c(1,2,3)
x2 <- c(4,5)
x3 <- c(6,7,8)
The desired output is a list of all 3*2*3 = 18 possible combinations of elements of x1,x2 and x3. One element for example is (1,4,6).
Many thanks in advance,
Bernard
2006 Nov 14
2
dividing vectors into bins with equal widths
Hi R-users,
I am trying to divide a vector (say X) into equal frequency bins. If one uses the hist()
function, then a histogram is plotted, but with bins of equal widths, and not with bins
having the same number of data points.
I have then tried the histogram() function as follows:
histogram(X, nint=10, breaks=NULL, equal.widths=F)
This works as I want. However, I can't extract which
2007 May 09
2
pvmnorm, error message
Hello there!
My operating system is Windows XP, my version of R is the latest (R-2.5.0). Recently I have downloaded the package "mvtnorm" and a problem with the command "pmvnorm" occured. Trying to enter the lines ...
A <- diag(3)
A[1,2] <-0.5
A[1,3] <- 0.25
A[2,3] <- 0.5
pvmnorm(lower=c(-Inf,-Inf,-Inf), upper=c(2,2,2),mean = c(0,0,0), corr=A)
I got the following
2008 Feb 12
4
How to run one-way anova R?
En innebygd og tegnsett-uspesifisert tekst ble skilt ut...
Navn: ikke tilgjengelig
Nettadresse: https://stat.ethz.ch/pipermail/r-help/attachments/20080212/d6012c8f/attachment.pl
2007 Jan 24
3
Conversion of column matrix into a vector without duplicates
Hi R,
I have a matrix A,
A=
[,1] [,2]
[1,] a u
[2,] b v
[3,] c x
[4,] d x
[5,] e x
I want to put the 2nd column of this matrix in a vector without
duplicates. i.e., my vector v should be (u, v, x), whose length is 3.
Can anybody help me on this?
Thanks in advance
Shubha.
[[alternative HTML version deleted]]
2005 Feb 25
3
restoring vector v from v[-i]
Hi
I have a little function that takes a vector v and an integer i. I
want to manipulate
v[-i] (to give v.new, say) and
then put (unmanipulated) v[i] back into the appropriate place. For
example,
f <- function(v,i){
v.new <- v[-i]+10
return(c(v.new[1:(i-1)],v[i],v.new[i:length(v.new)]))
}
(my example is adding 10 to v[-i], but the real version is the solution
of a complicated
2006 Jan 10
1
extracting coefficients from lmer
Dear R-Helpers,
I want to compare the results of outputs from glmmPQL and lmer analyses.
I could do this if I could extract the coefficients and standard errors
from the summaries of the lmer models. This is easy to do for the glmmPQL
summaries, using
> glmm.fit <- try(glmmPQL(score ~ x*type, random = ~ 1 | subject, data = df,
family = binomial), TRUE)
> summary(glmmPQL.fit)$tTable
2007 Jul 24
4
values from a linear model
Dear R users,
how can I extrapolate values listed in the summary of an lm model but not
directly available between object values such as the the standard errors of
the calculated parameters?
for example I got a model:
mod <- lm(Crd ~ 1 + Week, data=data)
and its summary:
> summary(mod)
Call:
lm(formula = Crd ~ 1 + Week, data = data, model = TRUE, y = TRUE)
Residuals:
Min
2007 May 16
3
more woes trying to convert a data.frame to a numerical matrix
I have the following csv file:
name,x,y,z
category,delta,gamma,epsilon
a,1,2,3
b,4,5,6
c,7,8,9
I'd like to create a numeric matrix of just the numbers in this csv dataset.
I've tried the following program:
sample.data <- read.csv("sample.csv")
numerical.data <- as.matrix(sample.data[-1,-1])
However, print(numerical.data) returns what appears to be a matrix of
2006 Sep 13
3
functions and strings
Hi
If
string <- "xyz"
f <- function(x){1 + sin(cos(x)) + exp(x^2)}
How do I manipulate "string" and f() to give the string
"1 + sin(cos(xyz)) + exp(xyz^2)"
?
--
Robin Hankin
Uncertainty Analyst
National Oceanography Centre, Southampton
European Way, Southampton SO14 3ZH, UK
tel 023-8059-7743
2005 Jan 25
3
Plotting only masked part of data
Hello,
I have x and y data to plot (synthetic example):
x <- seq(0,4*pi,by=0.1)
y <- sin(x)
I then want to plot (x,y) in those points where abs(y) is smaller than
0.5. As a first approximation
plot(x[abs(y) < 0.5],y[abs(y) < 0.5])
is quite close - however I want to plot with lines, i.e. type="l", and
then I get solid lines connecting the endpoint of one
2005 Mar 07
4
simple if...else causes syntax error
I am trying to do the simplest thing in the world. The following works:
aaa <- ifelse(aaa==5, 6, 7)
But if I want to change the if...else syntax instead, it gives errors
and assigns 7 to aaa. Here is the problem code:
aaa <- 5
if ( aaa==5 ) {
aaa <- 6
}
else {
aaa <- 7
}
Here is the output:
> aaa <- 5
> if ( aaa==5
2007 May 18
3
lapply not reading arguments from the correct environment
Hello,
I am facing a problem with lapply which I ''''think''' may be a bug.
This is the most basic function in which I can reproduce it:
myfun <- function()
{
foo = data.frame(1:10,10:1)
foos = list(foo)
fooCollumn=2
cFoo = lapply(foos,subset,select=fooCollumn)
return(cFoo)
}
I am building a list of dataframes, in each of which I want to keep
only column
2007 Mar 03
3
How to convert List object to function arguments?
Dear R gurus,
I have a function "goftests" that receives the following arguments:
* a vector "x" of data values;
* a distribution name "dist";
* the dots list ("...") containing a list a parameters to pass to CDF
function;
and calls several goodness-of-fit tests on the given data values against
the given distribution.
That is:
##### BEGIN CODE SNIP #####
2005 Jan 14
5
Replacing NAs in a data frame using is.na() fails if there are no NAs
Hi
This is a difference between the way matrices and data frames work I
guess. I want to replace the NA values in a data frame by 0, and the
code works as long as the data frame in question actually includes an NA
value. If it doesn't, there is an error:
df <- data.frame(c1=c(1,1,1),c2=c(2,2,NA))
df[is.na(df)] <- 0
df
df <- data.frame(c1=c(1,1,1),c2=c(2,2,2))
df[is.na(df)] <-
2006 May 12
3
Maximum likelihood estimate of bivariate vonmises-weibulldistribution
Thanks Dimitris!!! That's much clearer now. Still have a lot of work to
do this weekend to understand every bit but your code will prove very
useful.
Cheers,
Aziz
-----Original Message-----
From: Dimitrios Rizopoulos [mailto:Dimitris.Rizopoulos at med.kuleuven.be]
Sent: May 12, 2006 4:35 PM
To: Chaouch, Aziz
Subject: RE: [R] Maximum likelihood estimate of bivariate
2006 Sep 11
2
unexpected behaviour when defining a function
Hi,
I know S manuals used to warn against using the same names for a
variable and a function, but I have never seen that cause problems in
R, so I usually don't pay much attention to it. Which is why the
following behaviour came as a surprise:
> bar <- function() 1
> foo <- function(bar = bar()) {
+ bar
+ }
> foo(9)
[1] 9
> foo()
Error in foo() : recursive default