Displaying 20 results from an estimated 10000 matches similar to: "Seeking help re: ? single apply command or an alternative"
2010 Sep 16
1
The permutation of one vector into another
Dear R-help-list
I have two character vectors
a <- c("A", "B", "C")
b <- c("A", "C", "B")
Then
sapply(a, function(i) grep(i, b))
computes the permutation of the entries in 'b' needed
to bring 'b' into the same order as 'a'.
I have searched around, but haven't been able to find
any existing function
2011 Jan 29
1
environment question: changing variables from a formula through model.frame?
Hello all,
I came across a behavior of R with environments that I'm not sure what is
causing it.
It involves changing variables that are found through using model.frame on a
formula inside a function.
I wonder if it's a "bug" or a "feature". And in either case, how it might
be managed.
Here is a simple example:
# let's say we have an x and y variables:
temp_x
2011 Apr 17
5
cube root
This is some interesting:
> -8^(1/3)
[1] -2
> x=(-8:8)
> y=x^(1/3)
> y
[1] NaN NaN NaN NaN NaN NaN NaN NaN
0.000000 1.000000
[11] 1.259921 1.442250 1.587401 1.709976 1.817121 1.912931 2.000000
So, can anybody explain this?! (Why is x[1]^(1/3)=y[1]=NaN, but
-8^(1/3)=-2?)
Thx!!!
[[alternative HTML version deleted]]
2010 Aug 26
1
Passing arguments between S4 methods fails within a function:bug? example with raster package.
Dear all,
This problem came up initially while debugging a function, but it
seems to be a more general problem of R. I hope I'm wrong, but I can't
find another explanation. Let me illustrate with the raster package.
For an object "RasterLayer" (which inherits from Raster), there is a
method xyValues defined with the signature
2010 Aug 26
3
Using termplot() with transformations of x
Hi all
I was playing with termplot(), and came across what appears to be an inconsistency.
It would appreciate if someone could enlighten me:
> # First, generate some data:
> y <- rnorm(100)
> x <- runif(length(y),1,2)
> # Now find the log of x:
> logx <- log(x)
>
> # Now fit two models that are exactly the same, but specified differently:
> m1 <-
2010 Sep 30
4
interactive session
Hi guys,
My concern is to create an automated process from the beginning to the end. I
want to copy all my code together in one piece and paste it to R console and sit
back and relax :) except one moment in which the program should ask me to enter
a number.. and only then (only after getting a valid number from me) it should
continue to read and process the rest of the code. I tried lots of
2006 Aug 18
3
iproute2, alternative tables, no default route: routing trouble for localhost
Hi.
The task:
1. There 3 servers and a router with 2 PPPoE connections (let call them:
ppp0, ppp1).
2. There are several groups of Inet-clients to be served (Servers,
Clients and Club).
3. The task is:
- to route Club through the ppp1;
- to Servers and Clients through ppp0;
(Next is reproduced from memory and may be slightly incorrect)
router # netstat -nr
Kernel IP routing table
2002 Mar 05
1
apply question
Sorry to bother the list with another apply question, but I am having
trouble getting my mind around the various apply forms. A simplified
version of my problem is the following:
data _
data.frame(ct=seq(1,10),a1=rnorm(10),a2=rnorm(10),a3=rnorm(10),b=rnorm(10))
listofAvars _ grep('^a',names(data),value=T)
I would like a1, a2, a3 to be multiplied by 10. That is, I would like a
cleaner
2011 Mar 29
1
Dirichlet surface
Dear list members,
I want to draw surfaces of Dirichlet distributions with different
parameter settings.
My code is the following:
#<begin code>
a1 <- a2 <- a3 <- 2
#a2 <- .5
#a3 <- .5
x1 <- x2 <- seq(0.01, .99, by=.01)
f <- function(x1, x2){
term1 <- gamma(a1+a2+a3)/(gamma(a1)*gamma(a2)*gamma(a3))
term2 <- x1^(a1-1)*x2^(a2-1)*(1-x1-x2)^(a3-1)
2010 Sep 03
1
'seq' help page: seq_length -> seq_len?
In the Value section of the 'seq' help page it says
'seq_along' and 'seq_length' always return an integer vector.
I believe it should be
'seq_along' and 'seq_len' always return an integer vector.
as there are no seq_length function?
Best, Niels
--
Niels Richard Hansen Web: www.math.ku.dk/~richard
Associate Professor
2003 Nov 18
1
aov with Error and lme
Hi
I searched in the list and only found questions
without answers e.g.
http://finzi.psych.upenn.edu/R/Rhelp02a/archive/19955.html
: Is there a way to get the same results with lme as
with aov with Error()?
Can anybody reproduce the following results with lme:
id<-c(1,1,1,2,2,2,3,3,3,4,4,4,5,5,5,1,1,1,2,2,2,3,3,3,4,4,4,5,5,5,1,1,1,2,2,2,3,3,3,4,4,4,5,5,5)
2011 Apr 14
2
Krylov subspace computations of matrix exponentials
I use the very nice expm functions available from the expm and Matrix
packages. My understanding is that for large sparse matrices the
currently best methods available are Krylov subspace methods, but
they are as far as I can tell not implemented in either of the packages
mentioned, nor in any other R package I have found.
Does anybody know if Krylov subspace methods are available from
any R
2007 Jan 20
4
Question about converting from square roots to decimals and back
Hi,
I apologize if there is a simple answer to this question that I've
missed. I did search the mailing list but I might not have used the
right keywords. Why does sum(A3^2) give the result of 1, but
sum(A3^2)==1 give the result of FALSE?
> A3<-matrix(nrow=3,c(1/(2^.5),1/(2^.5),0))
> A3
[,1]
[1,] 0.7071068
[2,] 0.7071068
[3,] 0.0000000
> sum(A3^2)
[1] 1
>
2011 Jul 05
3
plotting survival curves (multiple curves on single graph)
Hello.
This is a follow-up to a question I posted last week. With some
previous suggestions from the R-help community, I have been able to
plot survival (, hazard, and density) curves using published data for
Siler hazard parameters from a number of ethnographic populations.
Can the function below be modified, perhaps with a "for" statement, so
that multiple curves (different line
2009 Apr 22
1
Gee with nested desgin
Dear all,
Is it possible to incorporate a nested design in GEE? I have
measurements on trees that where measured in two years. The trees are
nested in plots. Each plot contains 24 trees. The number of plots is 72.
Hence we would expect 2 * 24 * 72 = 3456 data points. A few are missing,
so we end up wih 3431 data points.
This is what I have tried until now.
#assuming independence between trees
2009 Oct 29
3
Removing & generating data by category
Dear R users,
Basically, from the following arbitrary data set:
a <-
data.frame(id=c(c("A1","A2","A3","A4","A5"),c("A3","A2","A3","A4","A5")),loc=c("B1","B2","B3","B4","B5"),clm=c(rep(("General"),6),rep("Life",4)))
> a
2011 Jul 04
1
placing multiple rows in a single row
Dear people from the R help list,
I have a question that I can't get my head around to start answering,
that is why I am writing to the list.
I have data in a format like this (tabs might look weird):
John A1 1 0 1
John A2 1 1 1
John A3 1 0 0
Mary A1 1 0 1
Mary A2 0 0 1
Mary A3 1 1 0
Peter A1 1
2011 Nov 18
1
Producing plot using polygon function
Hi,
I am looking forward to fill the plot using conditions on variables a2 and
a3. Whenever variable(a2) goes above variable(a3) i fill it with some color
.
I am storing the coordinates of a2 and a3 in x and y as well as time where
it is occurring . But it is not producing properly. I must be wrong
in assigning coordinates.
What should be the correct way to produce the desired plot?
Thanks in
2009 Sep 04
1
User defined function's argument as Subset function's input
Dear R users,
I have a data where I desire to subset according to certain conditions.
However, the script is very messy as there are about 30 distinct conditions.
(i.e. same script but with different conditions)
I would like to make a user defined function so that I can input the desired
conditions and just get the results accordingly.
Below is an arbitrary data set & sample statements
2010 Mar 07
2
Why can't "apply" be used with "as.factor" on a data.frame ?
Hi all,
Let's say I have a data.frame and wants to turn each of it's columns into a
factor.
My instinct would be to use as.factor with apply. But this won't work, and
result with a data.frame of characters.
I found another solution for how to achieve this, but I would also like to
understand - *WHY* does it work this way?
Here is an example script:
a <- data.frame(x1 = rnorm(100),