[R] How to create multi variables

2014-05-13 Thread Yuanzhi Li

Hi, everyone

I want to create a series of variables (e.g. t1, t2..., t10) which could 
be used in loops. My idea is to use function assign


for (i in 1:10)
{
  assign(paste(t,i,sep=), FUN) # allocate the value from FUN to 
variable ti

}

But when I create a vector containing the names of these variables and 
want to use the variables according to the subscript, it doesn't works.


t-noquote(paste(t,1:10,sep=))
t[1]
t1
it returns only the name of variable t1, but not the value allocated to 
t1 by FUN. So what should I do to realize this?


Or is there any better way to do this?

Can we define a series of variables which can be used according to the 
subscript like

t-f(t1, t2..., t10),
then we have 10 variables which can be used directly?
for(i in 1:10)
{
   t[i]-FUN# with the fines variables we can directly assign the value 
of FUN to ti

}
These are just my thoughts, I don't know whether there are available R 
codes to realized it. I am looking forward any help from you.


Thanks in advance!

Yuanzhi

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


[R] regular pentagon

2014-03-07 Thread Yuanzhi Li

Hello, everyone,

Do you have any idea to get a set of random points within a regular 
pentagon? Thanks in advance!


Yuanzhi

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


[R] subset of data frame

2014-02-08 Thread Yuanzhi Li

Hi, everyone

I met a small problem when I want take a subset from a data frame. The 
data frame(x) looks like the followings(10 species with 3 measured 
traits):


Species trait1trait2 trait3
sp1
sp1
...
sp2
sp2
...

sp10
sp10
...

It would be easy if we want trait values for most abundant species, we 
can do that with the following codes


sp-table(x$Species)
x[x$Species==names(sp)[1],]

but why it doesn't work if we want to select traits values for more than 
one species(most abundant two species) with similar codes


x[x$Species==names(sp)[1:2],]

And there must be other solutions for this problem. Looking forward for 
your help.


Thanks in advance!

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


[R] subset of data frame

2014-02-08 Thread Yuanzhi Li

Hi, everyone

I met a small problem when I want take a subset from a data frame. The 
data frame(x) looks like the followings(10 species with 3 measured 
traits):


Species trait1trait2 trait3
sp1
sp1
...
sp2
sp2
...

sp10
sp10
...

It would be easy if we want trait values for most abundant species, we 
can do that with the following codes


sp-table(x$Species)
x[x$Species==names(sp)[1],]

but why it doesn't work if we want to select traits values for more than 
one species(most abundant two species) with similar codes


x[x$Species==names(sp)[1:2],]

And there must be other solutions for this problem. Looking forward for 
your help.


Thanks in advance!

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


[R] bargraph.CI

2013-12-11 Thread Yuanzhi Li

hello,

I had a problem with the function bargraph.CI. bargraph.CI draws a  
figure according to the alphabet sequence of the factor used. For  
example, I have a factor with for levels CK, N5, N10, N15, but  
the bars appear in CK,N10,N15,N5 order(alphabet sequence), but  
I want the bars to appear  CK, N5, N10, N15(treat level  
sequence). Do you have any ideas to realize the goal?


Thank you!


Yuanzhi

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


[R] volume of ellipsoid

2013-11-13 Thread Yuanzhi Li

Hi, everyone!

I have a matrix X(n*p) which is n samples from a p-dimensional normal  
distribution. Now I want to make the ellipsoid containing (1-α)% of  
the probability in the distribution based on Mahalanobis distance:


μ:(x-μ)'Σ^(-1)(x-μ)≤χ2p(α)

where x and Σ is the mean and variance-covariance matrix of X. Are  
there some functions in R which can plot the ellipsoid and calculate  
the volume (area for p=2, hypervolume for p3) of the ellipsoid? I  
only find the ellipsoidhull function in cluster package, but it  
deal with ellipsoid hull containing X, which obvious not the one I want.


After that, a more difficult is the following. If we have a series of  
matrix X1, X2, X3,… Xm which follow different p-dimensional normal  
distributions. And we make m ellipsoids (E1, E2, … Em) for each matrix  
like the before. How can we calculate the volume of union of the m  
ellipsoids? One possible solution for this problem is the  
inclusion-exclusion principle:


V(⋃Ei)(1≤i≤m)=
V(Ei)(1≤i≤m)-∑V(Ei⋂Ej)(1≤ij≤m)+∑V(Ei⋂Ej⋂Ek)(1≤ijk≤m)+(-1)^(m-1)V(E1⋂…⋂Em)

But the problem is how to calculate the volume of intersection between  
2, 3 or more ellipsoids. Are there some functions which can calculate  
the volume of intersection between two region or functions which  
directly calculate the volume of a union of two region(the region here  
is ellipsoid). OR yo you have any good ideas solving this problem in  
R? Thank you all in advance!


Yuanzhi

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.