[R] regex sub with specified number of characters

2015-10-06 Thread Johannes Radinger
Hi

I'd like to remove a leading "3" if my number is 7 digits long, if it is
only 6 I don't want to anything.
I think this should be possible with a 1-liner using sub() but I am not
sure how to define the number of characters following the leading one.

For example my vector:

a <- c(3593857,384723,4395843,3398374)

with sub("^3","",a) I also remove the leading from the second element which
is only 6 digits long. So how to restrict that using sub? The final result
should be

a <- c(593857,384723,4395843,398374)

Any suggestions?

Best regards,
Johannes

[[alternative HTML version deleted]]

__
R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
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] Package dismo: Extracting sensitivity and specificity from gbm.step() object

2015-08-24 Thread Johannes Radinger
Dear R-User!

This is a question to all of you that are familiar with the 'dismo'
package, in particular we are interested in the gbm.step() function to
create a boosted regression tree model in R. From the model output object we
can use the $cv.statistics to get information on the cross-validation model
performance (e.g. cross-validation AUC). However, quite often the AUC has
been criticized for various reasons (e.g. Lobo et al. 2008) and it was
proposed also to use other measures of model performance (e.g. sensitivity
and specificity, Cohen's kappa, TSS).

Thus I am wondering wondering which of the $cv.statistical output is the
most appropriate indicator of model performance (e.g. for comparing two
boosted regression tree models). Moreover I'd like to know if it is somehow
possible to extract/calculate values of specificity and sensitivity from
the output model object (i.e without re-calculating the model). This would
be valuable information to calculate e.g. a kappa value or TSS value from a
gbm.step - model-object.

Thanks for your answers,

Best,
Johannes

[[alternative HTML version deleted]]

__
R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
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.


Re: [R] Optimization to fit data to custom density distribution

2015-03-23 Thread Johannes Radinger
On Sat, Mar 21, 2015 at 3:41 PM, Prof Brian Ripley rip...@stats.ox.ac.uk
wrote:

 On 21/03/2015 14:27, Johannes Radinger wrote:

 Thanks for the fast response. The fitdistr() function works well for the
 predefined density functions. However, what is the recommended approach
 to optimize/fit a density function described by two superimposed normal
 distributions? In my case it is N1(mean=0,sd1)*p+N2(mean=0,sd2)*(1-p).
 With fitdistr one can only choose among the 15 distributions. Probably


 That is simply not true.  The help says

 densfun: Either a character string or a function returning a density
   evaluated at its first argument.

 and the second alternative is used in the examples.


Of course, that was my mistake. So fitdistr() works fine for this case.
Here an example to complete that case:

x - c(rnorm(mean=0,sd=50,70),rnorm(mean=0,sd=500,30))
hist(x,breaks=30)

ddoublenorm - function(x,sigma_stat,sigma_mob,p) {
  dnorm(x,mean=0,sd=sigma_stat)*p+dnorm(x,mean=0,sd=sigma_mob)*(1-p)}

fitdistr(x=x,densfun=ddoublenorm,
start=list(sigma_stat=30,sigma_mob=300,p=0.5),

 method=L-BFGS-B,lower=c(0.001,0.001,0.1),upper=c(Inf,Inf,0.9))

Thanks a lot!

Best regards,
Johannes




  this needs an approach using optim()? However I am so far unfamiliar
 with these packages. So any suggestion ist welcome. :)


 There are examples of that in MASS (the book), chapter 16.


 /Johannes

 On Sat, Mar 21, 2015 at 2:16 PM, Prof Brian Ripley
 rip...@stats.ox.ac.uk mailto:rip...@stats.ox.ac.uk wrote:

 One way using the standard R distribution:

 library(MASS)
 ?fitdistr

 No optimization is needed to fit a normal distribution, though.


 On 21/03/2015 13:05, Johannes Radinger wrote:

 Hi,

 I am looking for a way to fit data (vector of values) to a
 density function
 using an optimization (ordinary least squares or maximum
 likelihood fit).
 For example if I have a vector of 100 values generated with rnorm:

 rnorm(n=100,mean=500,sd=50)

 How can I fit these data to a Gaussian density function to
 extract the mean
 and sd value of the underlying normal distribution. So the
 result should
 roughly meet the parameters of the normal distribution used to
 generate the
 data. The results will ideally be closer the true parameters the
 more data
 (n) are used to optimize the density function.


 That's a concept called 'consistency' from the statistical theory of
 estimation.  If you skipped that course, time to read up (but it is
 off-topic here).

 --
 Brian D. Ripley, rip...@stats.ox.ac.uk mailto:rip...@stats.ox.ac.uk
 Emeritus Professor of Applied Statistics, University of Oxford
 1 South Parks Road, Oxford OX1 3TG, UK




 --
 Brian D. Ripley,  rip...@stats.ox.ac.uk
 Emeritus Professor of Applied Statistics, University of Oxford
 1 South Parks Road, Oxford OX1 3TG, UK


[[alternative HTML version deleted]]

__
R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
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.


Re: [R] Optimization to fit data to custom density distribution

2015-03-21 Thread Johannes Radinger
Thanks for the fast response. The fitdistr() function works well for the
predefined density functions. However, what is the recommended approach to
optimize/fit a density function described by two superimposed normal
distributions? In my case it is N1(mean=0,sd1)*p+N2(mean=0,sd2)*(1-p). With
fitdistr one can only choose among the 15 distributions. Probably this
needs an approach using optim()? However I am so far unfamiliar with these
packages. So any suggestion ist welcome. :)

/Johannes

On Sat, Mar 21, 2015 at 2:16 PM, Prof Brian Ripley rip...@stats.ox.ac.uk
wrote:

 One way using the standard R distribution:

 library(MASS)
 ?fitdistr

 No optimization is needed to fit a normal distribution, though.


 On 21/03/2015 13:05, Johannes Radinger wrote:

 Hi,

 I am looking for a way to fit data (vector of values) to a density
 function
 using an optimization (ordinary least squares or maximum likelihood fit).
 For example if I have a vector of 100 values generated with rnorm:

 rnorm(n=100,mean=500,sd=50)

 How can I fit these data to a Gaussian density function to extract the
 mean
 and sd value of the underlying normal distribution. So the result should
 roughly meet the parameters of the normal distribution used to generate
 the
 data. The results will ideally be closer the true parameters the more data
 (n) are used to optimize the density function.


 That's a concept called 'consistency' from the statistical theory of
 estimation.  If you skipped that course, time to read up (but it is
 off-topic here).

 --
 Brian D. Ripley,  rip...@stats.ox.ac.uk
 Emeritus Professor of Applied Statistics, University of Oxford
 1 South Parks Road, Oxford OX1 3TG, UK


[[alternative HTML version deleted]]

__
R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
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] Optimization to fit data to custom density distribution

2015-03-21 Thread Johannes Radinger
Hi,

I am looking for a way to fit data (vector of values) to a density function
using an optimization (ordinary least squares or maximum likelihood fit).
For example if I have a vector of 100 values generated with rnorm:

rnorm(n=100,mean=500,sd=50)

How can I fit these data to a Gaussian density function to extract the mean
and sd value of the underlying normal distribution. So the result should
roughly meet the parameters of the normal distribution used to generate the
data. The results will ideally be closer the true parameters the more data
(n) are used to optimize the density function.

Any suggestions?

/Johannes

[[alternative HTML version deleted]]

__
R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
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] Two wireframe plots (lattice) aside (grid.arrange) without outer box

2014-12-02 Thread Johannes Radinger
Hi,

I'd like to arrange two wireframe plots (library lattice) next to each
other using the grid.arrange function of the library gridExtra. However
the two wireframe plots should be closer to each other and the outer 2D box
should be removed (to save space).
To remove the outer box for a single plot I am using
trellis.par.set(axis.line,list(col=NA,lty=1,lwd=1))
However this approach does not work in combination with grid.arrange().

Here a small working example:

trellis.par.set(axis.line,list(col=NA,lty=1,lwd=1))
p1 - wireframe(volcano, shade = TRUE,
  aspect = c(61/87, 0.4),
  light.source = c(10,0,10))
grid.arrange(p1,p1,nrow=1)

Does anybody have any suggestions?

/johannes

[[alternative HTML version deleted]]

__
R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
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] Match beginning and end of string (grepl)

2014-09-02 Thread Johannes Radinger
Hi,

I'd like to match the beginning and the end of a string. E.g. I want to
extract all strings from a vector that beginn with 12 and end with
Apples:

a - 2 green Apples
b - 12 green Apples
c - 12 Apples and 2 green Bananas
d - 12 yellow Bananas

fruitlist - c(a,b,c,d)

# This is how to extract all that beginn with 12
grepl(^12,fruitlist)

But how can I get only those that also end with Apples. So basically
just item b 12 green Apples should remain.

Is there any clear description and examples of regular expressions
and how to use them? I find the manual ?grepl very difficult to read.

Thanks,
Johannes

[[alternative HTML version deleted]]

__
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] Set file path in Biomod2

2014-07-15 Thread Johannes Radinger
Hi,

I am wondering if it is possible to set the path to the output file of the
function
BIOMOD_Modeling() from the 'Biomod2' package. I can see the option
SaveObj to state if the output should be save to the hard disk. When this is
enabled, all files are printed to the working directory. So is Biomod2
output
always linked to the working directory or can the output path also set
manually,
without changing the working directory?
Probably I am just missing a single option

Thanks,

/Johannes

[[alternative HTML version deleted]]

__
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.


Re: [R] Cutting hierarchical cluster tree at specific height fails

2014-07-14 Thread Johannes Radinger
Of course,
manually checking the number of clusters that are cut at a specific height
(e.g. by abline())
is one possibility. However, this only makes sense for single trees, but is
not a feasible
approach for multiple model runs when hundreds of trees are built with many
cluster branches.

Thus, I'd be nice if somebody knows a more programatic approach or another
package
that allows cutting centroid-trees.

/Johannes


On Fri, Jul 11, 2014 at 4:19 PM, David L Carlson dcarl...@tamu.edu wrote:

  The easiest workaround is the one you included in your original posting.
 Specify k= and not h=. Examine the dendrogram and decide how many clusters
 are at the level you want. You could add guidelines to the dendrogram with
 abline() to make it easier to see the number of clusters at various heights.



 plot(hc)

 abline(h=c(20, 40, 60, 80, 100, 120), lty=3)



 David C



 *From:* Johannes Radinger [mailto:johannesradin...@gmail.com]
 *Sent:* Friday, July 11, 2014 3:24 AM
 *To:* David L Carlson; R help
 *Subject:* Re: [R] Cutting hierarchical cluster tree at specific height
 fails



 Hi,



 @David: Thanks for the explanation why this does not work. This of

 course makes theoretically sense.



 However in a recent discussion

 (
 http://stats.stackexchange.com/questions/107448/spatial-distance-between-cluster-means
 )

 it was stated that the 'reversals problem' of  centroid method is

 not a serious reason to deactivate the option of 'tree cut'. Instead

 a warning message should be provided rather than a deactivation.



 So does anyone know how a tree that was created with centroid can still

 be cut at a specific height? I tried the package dynamicTreeCut, but this

 also relies on cutree and consequently raises an error when used for
 cutting

 centroid trees.



 Does anyone know a work around and can provide a minimum working example?



 /Johannes



 On Wed, Jul 9, 2014 at 4:58 PM, David L Carlson dcarl...@tamu.edu wrote:

 To cut the tree, the clustering algorithm must produce consistently
 increasing height values with no reversals. You used one of the two options
 in hclust that does not do this. Note the following from the hclust manual
 page:

 Note however, that methods median and centroid are not leading to a
 monotone distance measure, or equivalently the resulting dendrograms can
 have so called inversions (which are hard to interpret).

 The cutree manual page:

 Cutting trees at a given height is only possible for ultrametric trees
 (with monotone clustering heights).

 Use a different method (but not median).

 -
 David L Carlson
 Department of Anthropology
 Texas AM University
 College Station, TX 77840-4352


 -Original Message-
 From: r-help-boun...@r-project.org [mailto:r-help-boun...@r-project.org]
 On Behalf Of Johannes Radinger
 Sent: Wednesday, July 9, 2014 7:07 AM
 To: R help
 Subject: [R] Cutting hierarchical cluster tree at specific height fails

 Hi,

 I'd like to cut a hierachical cluster tree calculated with hclust at a
 specific height.
 However ever get following error message:
 Error in cutree(hc, h = 60) :
   the 'height' component of 'tree' is not sorted (increasingly)


 Here is a working example to show that when specifing a height in  cutree()
 the code fails. In contrast, specifying the number of clusters in cutree()
 works.
 What is the exact problem and how can I solve it?

 x - c(rnorm(100,50,10),rnorm(100,200,25),rnorm(100,80,15))
 y - c(rnorm(100,50,10),rnorm(100,200,25),rnorm(100,150,25))
 df - data.frame(x,y)
 plot(df)

 hc - hclust(dist(df,method = euclidean), method=centroid)
 plot(hc)

 df$memb - cutree(hc, h = 60) # this does not work
 df$memb - cutree(hc, k = 3) # this works!

 plot(df$x,df$y,col=df$memb)


 Thank you for your hints!

 Best regards,
 Johannes

 [[alternative HTML version deleted]]

 __
 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.




[[alternative HTML version deleted]]

__
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.


Re: [R] Cutting hierarchical cluster tree at specific height fails

2014-07-11 Thread Johannes Radinger
Hi,

@David: Thanks for the explanation why this does not work. This of
course makes theoretically sense.

However in a recent discussion
(
http://stats.stackexchange.com/questions/107448/spatial-distance-between-cluster-means
)
it was stated that the 'reversals problem' of  centroid method is
not a serious reason to deactivate the option of 'tree cut'. Instead
a warning message should be provided rather than a deactivation.

So does anyone know how a tree that was created with centroid can still
be cut at a specific height? I tried the package dynamicTreeCut, but this
also relies on cutree and consequently raises an error when used for cutting
centroid trees.

Does anyone know a work around and can provide a minimum working example?

/Johannes


On Wed, Jul 9, 2014 at 4:58 PM, David L Carlson dcarl...@tamu.edu wrote:

 To cut the tree, the clustering algorithm must produce consistently
 increasing height values with no reversals. You used one of the two options
 in hclust that does not do this. Note the following from the hclust manual
 page:

 Note however, that methods median and centroid are not leading to a
 monotone distance measure, or equivalently the resulting dendrograms can
 have so called inversions (which are hard to interpret).

 The cutree manual page:

 Cutting trees at a given height is only possible for ultrametric trees
 (with monotone clustering heights).

 Use a different method (but not median).

 -
 David L Carlson
 Department of Anthropology
 Texas AM University
 College Station, TX 77840-4352

 -Original Message-
 From: r-help-boun...@r-project.org [mailto:r-help-boun...@r-project.org]
 On Behalf Of Johannes Radinger
 Sent: Wednesday, July 9, 2014 7:07 AM
 To: R help
 Subject: [R] Cutting hierarchical cluster tree at specific height fails

 Hi,

 I'd like to cut a hierachical cluster tree calculated with hclust at a
 specific height.
 However ever get following error message:
 Error in cutree(hc, h = 60) :
   the 'height' component of 'tree' is not sorted (increasingly)


 Here is a working example to show that when specifing a height in  cutree()
 the code fails. In contrast, specifying the number of clusters in cutree()
 works.
 What is the exact problem and how can I solve it?

 x - c(rnorm(100,50,10),rnorm(100,200,25),rnorm(100,80,15))
 y - c(rnorm(100,50,10),rnorm(100,200,25),rnorm(100,150,25))
 df - data.frame(x,y)
 plot(df)

 hc - hclust(dist(df,method = euclidean), method=centroid)
 plot(hc)

 df$memb - cutree(hc, h = 60) # this does not work
 df$memb - cutree(hc, k = 3) # this works!

 plot(df$x,df$y,col=df$memb)


 Thank you for your hints!

 Best regards,
 Johannes

 [[alternative HTML version deleted]]

 __
 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.


[[alternative HTML version deleted]]

__
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] Cutting hierarchical cluster tree at specific height fails

2014-07-09 Thread Johannes Radinger
Hi,

I'd like to cut a hierachical cluster tree calculated with hclust at a
specific height.
However ever get following error message:
Error in cutree(hc, h = 60) :
  the 'height' component of 'tree' is not sorted (increasingly)


Here is a working example to show that when specifing a height in  cutree()
the code fails. In contrast, specifying the number of clusters in cutree()
works.
What is the exact problem and how can I solve it?

x - c(rnorm(100,50,10),rnorm(100,200,25),rnorm(100,80,15))
y - c(rnorm(100,50,10),rnorm(100,200,25),rnorm(100,150,25))
df - data.frame(x,y)
plot(df)

hc - hclust(dist(df,method = euclidean), method=centroid)
plot(hc)

df$memb - cutree(hc, h = 60) # this does not work
df$memb - cutree(hc, k = 3) # this works!

plot(df$x,df$y,col=df$memb)


Thank you for your hints!

Best regards,
Johannes

[[alternative HTML version deleted]]

__
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] dataframe calculations based on certain values of a column

2014-03-26 Thread Johannes Radinger
Hi,

I have data in a dataframe in following structure
var1 - c(a,b,c,a,b,c,a,b,c)
var2 - c(X,X,X,Y,Y,Y,Z,Z,Z)
var3 - c(1,2,2,5,2,6,7,4,4)
df - data.frame(var1,var2,var3)

Now I'd like to calculate relative values of var3. This values
should be relative to the base value (where var1=c) which is
indicated for each group (var2).

To illustrate how my result column should look like I divide
the column var3 by a vector c(2,2,2,6,6,6,4,4,4) (= for each group
of var2 the value c)

Of course this can also be done like this:
df$div - rep(df$var3[df$var1==c],each=length(unique(df$var1)))
df$result_calc - df$var3/df$div


However what when the dataframe is not as simple and not that well ordered
as
in the example here. So for example there is always a value c for each group
but all the cs are clumped in the last rows of the dataframe or scatterd
in a random
mannar. Is there a simple way to still calculate such relative values.
Probably with an approach using apply, but maybe someone can give me a hint.
Or do I need to sort my dataframe in order to do such calculations?

best,

/Johannes

[[alternative HTML version deleted]]

__
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] Solving a normal distribution pnorm for q

2013-12-12 Thread Johannes Radinger
Hi,



I found follwowing example of pnorm here:

http://www.r-tutor.com/elementary-statistics/probability-distributions/normal-distribution



Problem

Assume that the test scores of a college entrance exam fits a normal
distribution. Furthermore, the mean test score is 72, and the standard
deviation is 15.2. What is the percentage of students scoring 84 or more in
the exam?



Solution

 pnorm(84, mean=72, sd=15.2, lower.tail=FALSE)

[1] 0.21492



That is straight forward, however what if I want to know the score the best
30% students are reaching at least. So I know the solution of pnorm but
want to know its q. How can that be achieved in R?



Any suggestions?



/Johannes

[[alternative HTML version deleted]]

__
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.


Re: [R] Solving a normal distribution pnorm for q

2013-12-12 Thread Johannes Radinger
Thanks for the fast response. Of course I totally overlooked qnorm as I had
a more complex task in my head.

I wanted to reverse following equation:
r=0.67
q=-150
sd1=100
sd2=1000

X - pnorm(q=q,sd=sd1)*r+pnorm(q=q,sd=sd2)*(1-r)

Maybe its mathematically really easy, but somehow I don't get it how to do
reverse and provide X and
get q especially with the presence of r respectively as weighting factors
for the two distributions.

/J


On Thu, Dec 12, 2013 at 3:09 PM, Dániel Kehl ke...@ktk.pte.hu wrote:

 Looks like homework.

 Try ?qnorm
 
 Feladó: r-help-boun...@r-project.org [r-help-boun...@r-project.org] ;
 meghatalmaz#243;: Johannes Radinger [johannesradin...@gmail.com]
 Küldve: 2013. december 12. 14:56
 To: R help
 Tárgy: [R] Solving a normal distribution pnorm for q

 Hi,



 I found follwowing example of pnorm here:


 http://www.r-tutor.com/elementary-statistics/probability-distributions/normal-distribution



 Problem

 Assume that the test scores of a college entrance exam fits a normal
 distribution. Furthermore, the mean test score is 72, and the standard
 deviation is 15.2. What is the percentage of students scoring 84 or more in
 the exam?



 Solution

  pnorm(84, mean=72, sd=15.2, lower.tail=FALSE)

 [1] 0.21492



 That is straight forward, however what if I want to know the score the best
 30% students are reaching at least. So I know the solution of pnorm but
 want to know its q. How can that be achieved in R?



 Any suggestions?



 /Johannes

 [[alternative HTML version deleted]]

 __
 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.


[[alternative HTML version deleted]]

__
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.


Re: [R] Solving a normal distribution pnorm for q

2013-12-12 Thread Johannes Radinger
Thanks Eik...
..the uniroot() was the function I was looking for.

Best regards,
/J


On Thu, Dec 12, 2013 at 4:27 PM, Eik Vettorazzi e.vettora...@uke.de wrote:

 Assuming r, sd1 and sd2 as known(fixed) components, this works:

 X - pnorm(q=q,sd=sd1)*r+pnorm(q=q,sd=sd2)*(1-r)

 uniroot(function(x)pnorm(q=x,sd=sd1)*r+pnorm(q=x,sd=sd2)*(1-r)-X,c(-1e6,1e6))


 Cheers

 Am 12.12.2013 15:58, schrieb Johannes Radinger:
  Thanks for the fast response. Of course I totally overlooked qnorm as I
 had
  a more complex task in my head.
 
  I wanted to reverse following equation:
  r=0.67
  q=-150
  sd1=100
  sd2=1000
 
  X - pnorm(q=q,sd=sd1)*r+pnorm(q=q,sd=sd2)*(1-r)
 
  Maybe its mathematically really easy, but somehow I don't get it how to
 do
  reverse and provide X and
  get q especially with the presence of r respectively as weighting factors
  for the two distributions.
 
  /J
 
 
  On Thu, Dec 12, 2013 at 3:09 PM, Dániel Kehl ke...@ktk.pte.hu wrote:
 
  Looks like homework.
 
  Try ?qnorm
  
  Feladó: r-help-boun...@r-project.org [r-help-boun...@r-project.org] ;
  meghatalmaz#243;: Johannes Radinger [johannesradin...@gmail.com]
  Küldve: 2013. december 12. 14:56
  To: R help
  Tárgy: [R] Solving a normal distribution pnorm for q
 
  Hi,
 
 
 
  I found follwowing example of pnorm here:
 
 
 
 http://www.r-tutor.com/elementary-statistics/probability-distributions/normal-distribution
 
 
 
  Problem
 
  Assume that the test scores of a college entrance exam fits a normal
  distribution. Furthermore, the mean test score is 72, and the standard
  deviation is 15.2. What is the percentage of students scoring 84 or
 more in
  the exam?
 
 
 
  Solution
 
  pnorm(84, mean=72, sd=15.2, lower.tail=FALSE)
 
  [1] 0.21492
 
 
 
  That is straight forward, however what if I want to know the score the
 best
  30% students are reaching at least. So I know the solution of pnorm but
  want to know its q. How can that be achieved in R?
 
 
 
  Any suggestions?
 
 
 
  /Johannes
 
  [[alternative HTML version deleted]]
 
  __
  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.
 
 
[[alternative HTML version deleted]]
 
 
 
  __
  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.
 

 --
 Eik Vettorazzi
 Institut für Medizinische Biometrie und Epidemiologie
 Universitätsklinikum Hamburg-Eppendorf

 Martinistr. 52
 20246 Hamburg

 T ++49/40/7410-58243
 F ++49/40/7410-57790
 --

 Besuchen Sie uns auf: www.uke.de
 _

 Universitätsklinikum Hamburg-Eppendorf; Körperschaft des öffentlichen
 Rechts; Gerichtsstand: Hamburg
 Vorstandsmitglieder: Prof. Dr. Christian Gerloff (Vertreter des
 Vorsitzenden), Prof. Dr. Dr. Uwe Koch-Gromus, Joachim Prölß, Rainer Schoppik
 _

 SAVE PAPER - THINK BEFORE PRINTING



[[alternative HTML version deleted]]

__
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] Overlay boxplot and scatter.smooth line

2013-11-19 Thread Johannes Radinger
Hi,

I'd like to plot a boxplot and use a scatter.smooth line plot as an overlay
for this plot.
This works except for the problem that the x-axis ticks for both plots are
differently spaced:
The boxplot ticks are closer and the space between the outer most boxplots
and the plot region (box) is larger for boxplots than for the
scatter.smooth plot. Is there any plot-option that can be changed to
produce the desired plot.

Here an example to illustrate what problem I am facing:

x - c(rep(1,100),rep(2,100),rep(3,100))
y - c(rnorm(100,1),rnorm(100,2),rnorm(100,3))

boxplot(y~x)
par(new=TRUE)
scatter.smooth(x, y, xaxt=n, yaxt=n, ann=FALSE)

Moreover, I'd like to plot just the smoothed line only and not the
datapoints.
Any suggestions?

best regards,

J.

[[alternative HTML version deleted]]

__
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.


Re: [R] Overlay boxplot and scatter.smooth line

2013-11-19 Thread Johannes Radinger
Thanks...that works great!

/J


On Tue, Nov 19, 2013 at 2:39 PM, Adams, Jean jvad...@usgs.gov wrote:

 Use lines() with loess.smooth() instead of scatter.smooth() to add to the
 already existing boxplot.  For example,

 boxplot(y~x)
 lines(loess.smooth(x, y))

 Jean


 On Tue, Nov 19, 2013 at 4:43 AM, Johannes Radinger 
 johannesradin...@gmail.com wrote:

 Hi,

 I'd like to plot a boxplot and use a scatter.smooth line plot as an
 overlay
 for this plot.
 This works except for the problem that the x-axis ticks for both plots are
 differently spaced:
 The boxplot ticks are closer and the space between the outer most boxplots
 and the plot region (box) is larger for boxplots than for the
 scatter.smooth plot. Is there any plot-option that can be changed to
 produce the desired plot.

 Here an example to illustrate what problem I am facing:

 x - c(rep(1,100),rep(2,100),rep(3,100))
 y - c(rnorm(100,1),rnorm(100,2),rnorm(100,3))

 boxplot(y~x)
 par(new=TRUE)
 scatter.smooth(x, y, xaxt=n, yaxt=n, ann=FALSE)

 Moreover, I'd like to plot just the smoothed line only and not the
 datapoints.
 Any suggestions?

 best regards,

 J.

 [[alternative HTML version deleted]]

 __
 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.




[[alternative HTML version deleted]]

__
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.


Re: [R] indicating significant differences in boxplots

2013-10-28 Thread Johannes Radinger
Hi,

I'd like to follow up an older discussion on adding significance stars to
boxplots.
(
http://r.789695.n4.nabble.com/indicating-significant-differences-in-boxplots-td862335.html
)
As suggested by Jim Lemon, there is following solution for a single boxplot:

boxplot(count ~ spray, data = InsectSprays, col = lightgray)

#and we'll assume that the second and third boxplots require a star:
par(xpd=TRUE)
yrange-par(usr)[3:4]
ypos-yrange[2]+diff(yrange)/40
segments(2,ypos,3,ypos)
text(2.5,ypos+diff(yrange)/40,*,cex=2)
par(xpd=FALSE)

But what if one wants to plot two boxplots (e.g. with each only two groups
which are significantly different) and
add such stars to each of the boxplots. I usually use par(mfrow(1,2)) to
plot all boxplots in a row.
How can I also add segments and stars on top of each plot?

/johannes

[[alternative HTML version deleted]]

__
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] Latin Hypercube Sample and transformation to uniformly distributed integers or classes

2013-10-08 Thread Johannes Radinger
Hi,

I'd like to use Latin Hypercube Sampling (LHC) in the the context of
uncertainty / sensitivity analysis of a complex model with approximately 10
input variables. With the LHC approach I'd like to generate parameter
combinations for my model input variables.
Therefore I came across an simple example here on the mailing list (
https://stat.ethz.ch/pipermail/r-help/2011-June/279931.html):

Easy Example
Parameter 1: normal(1, 2)
Parameter 2: normal(3, 4)
Parameter 3: uniform(5, 10)

require(lhs)
N - 1000
x - randomLHS(N, 3)
y - x
y[,1] - qnorm(x[,1], 1, 2)
y[,2] - qnorm(x[,2], 3, 4)
y[,3] - qunif(x[,3], 5, 10)

par(mfrow=c(2,2))
apply(x, 2, hist)

par(mfrow=c(2,2))
apply(y, 2, hist)


However, some of my parameters are uniformly distributed integer values
and/or uniformly distributed classes. So, for example one input parameter
can be yellow, green, red with equal probability. Of course these
attributes can be transformed into integers (1,2,3) with a uniform
distribution.

So far I've tried to use the round function:

y[,3] - round(qunif(x[,3], 5, 10))

which does not sample the 1 and 10 eqally to 2:8 (this is discussed already
somewhere else here on the list in another context, and the function
sample() is suggested). How can this be applied here and how can a column
of the lhs-output be transformed in e.g integers 1:10 or the three colors
as mentioned above?

thanks,

Johannes

[[alternative HTML version deleted]]

__
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] Margins in dcast (reshape2)

2013-06-26 Thread Johannes Radinger
Hi,


I'd like to get mean values for the margins of my casted data.frame.
For the casting I am using dcast() from reshape2. However, when I set
the margins parameter (margins=c(grand\_row)) I get following error
concerning
an unrecognized escape character '\_'. So what is the correct command
to get the outermost margins only in reshape2?

/johannes

[[alternative HTML version deleted]]

__
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] Error when using median as aggregation function in dcast

2013-06-26 Thread Johannes Radinger
Hi,


I am trying to calculated various summary statistics using the dcast
function
of reshape2. This works perfectly for getting the mean, sum, length, sd. But
when I want to calculate the median I get an error. I tried it with and
without removing
NAs:

my_median - function(x) median(x, na.rm = FALSE)
median_df - dcast(patch_stats_dfm,formula=species~input+barriers,my_median)

Error in vapply(indices, fun, .default) : values must be type 'integer',
 but FUN(X[[1]]) result is type 'double'

What does this error mean and what is causing the error, resp. how can I
solve the problem and
get a median?

/Johannes

[[alternative HTML version deleted]]

__
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.


Re: [R] Fwd: NaN-result from fuzzy_inference (package sets) with certain input

2013-05-10 Thread Johannes Radinger
Hi,

@David: thank you for your fast response. I changed the universe to cover
the at least the total range of the values in the dataframe. However, this
does not save the problem for several combination of depth and velocity. I
attached the same example as before but with a dataframe of such
combinations that don't work. Is the problem caused by the definition of
the membership classes? How can the problem bis solved?

## set universe
sets_options(universe, seq(from = 0, to = 5, by = 0.001))

## set up fuzzy variables
variables -
set(depth = fuzzy_variable(verylow = fuzzy_trapezoid(corners =
c(-3,0,0.2,0.5)),
   medium = fuzzy_trapezoid(corners
=c(0.45,0.55,0.7,0.9)),
   veryhigh = fuzzy_trapezoid(corners =
c(0.85,1,15,20))),
velocity = fuzzy_variable(verylow = fuzzy_trapezoid(corners =
c(-3,0,0.2,0.5)),
  medium = fuzzy_trapezoid(corners =
c(0.35,0.55,0.65,0.8)),
  veryhigh = fuzzy_trapezoid(corners =
c(0.7,0.9,15,20))),
suitability = fuzzy_partition(varnames = c(none = 0.2, low = 0.4,
medium = 0.6, high = 0.8),FUN = fuzzy_cone, radius = 0.2))


## set up rules
rules -
  set(
fuzzy_rule(depth %is% verylow  velocity %is% verylow, suitability
%is% low),
fuzzy_rule(depth %is% medium  velocity %is% verylow, suitability %is%
medium),
fuzzy_rule(depth %is% veryhigh  velocity %is% verylow, suitability
%is% low),
fuzzy_rule(depth %is% verylow  velocity %is% medium, suitability %is%
medium),
fuzzy_rule(depth %is% medium  velocity %is% medium, suitability %is%
high),
fuzzy_rule(depth %is% veryhigh  velocity %is% medium, suitability
%is% medium),
fuzzy_rule(depth %is% verylow  velocity %is% veryhigh, suitability
%is% none),
fuzzy_rule(depth %is% medium  velocity %is% veryhigh, suitability
%is% low),
fuzzy_rule(depth %is% veryhigh  velocity %is% veryhigh, suitability
%is% none)
  )

## combine to a system
system - fuzzy_system(variables, rules)
print(system)
plot(system) ## plots variables

# test df
test_df -
data.frame(depth=c(1.71,0.61,1.56,0.47,0.70,0.42,1.90),velocity=c(0.70,1.40,0.95,0.65,0.58,0.47,1.24),suitability=NA)

# do inference on test_df
fuzzy_result - function(df){
  gset_defuzzify(fuzzy_inference(system, list(depth = df[depth], velocity
= df[velocity])),centroid)
}

apply(test_df,1,fuzzy_result)



/Johannes



On Thu, May 9, 2013 at 12:35 AM, David Meyer david.me...@wu.ac.at wrote:

 It's because you restricted the universe to [0,1], so the fuzzy inference
 returns empty sets for those entries in your df with values larger than 1
 ...

 David


 On 2013-05-08 14:53, Johannes Radinger wrote:

 This email has already been sent to the R-mailing list,
 but maybe you as the author of the package sets can help here best

 Hi,

 I am trying to use the fuzzy_inference system on multiple input values.
 Basically I combine two variables (depth, velocity) into the variable
 suitability.
 Both depth and velocity have 3 trapezoid classes (verylow,medium,high)
 each.
 The consequent (suitability) has 4 fuzzy levels (none,low,medium,high)
 and should
 finally range between 0 and 1.
 I already set up the level definitions (trapez-corners) and the rules (a
 combination
 of all depth-levels with all velocity-levels and the consequent
 suitability).

 Now I wanted to test the system on a dataframe with dummy variables (in
 the range
 of values I will supply), but some how I get for some combinations of
 depth
 and velocity no resulting suitablilty.

 I provide here now some code (simpler than my actual) that produces also
 this
 NaN values:

 # Load sets
 library(sets)

 ## set universe
 sets_options(universe, seq(from = 0, to = 1, by = 0.001))

 ## set up fuzzy variables
 variables -
  set(depth = fuzzy_variable(verylow = fuzzy_trapezoid(corners =
 c(-3,0,0.2,0.5)),
 medium = fuzzy_trapezoid(corners
 =c(0.45,0.55,0.7,0.9)),
 veryhigh = fuzzy_trapezoid(corners =
 c(0.85,1,15,20))),
  velocity = fuzzy_variable(verylow = fuzzy_trapezoid(corners =
 c(-3,0,0.2,0.5)),
medium = fuzzy_trapezoid(corners =
 c(0.35,0.55,0.65,0.8)),
veryhigh = fuzzy_trapezoid(corners =
 c(0.7,0.9,15,20))),
  suitability = fuzzy_partition(varnames = c(none = 0.2, low =
 0.4, medium = 0.6, high = 0.8),FUN = fuzzy_cone, radius = 0.15))


 ## set up rules
 rules -
set(
  fuzzy_rule(depth %is% verylow  velocity %is% verylow, suitability
 %is% low),
  fuzzy_rule(depth %is% medium  velocity %is% verylow, suitability
 %is% medium),
  fuzzy_rule(depth %is% veryhigh  velocity %is% verylow,
 suitability %is% low),
  fuzzy_rule(depth %is% verylow  velocity %is% medium, suitability
 %is% medium),
  fuzzy_rule(depth %is% medium  velocity %is% medium, suitability
 %is% high),
  fuzzy_rule(depth

[R] Fuzzy rules definition (package sets) from data.frame

2013-05-08 Thread Johannes Radinger
Hi,

I just discovered the package sets and its ability to perform fuzzy
systems calculations.

The example in the manual of fuzzyinference() gives an overview how to
develop rules.
However my rules are already available as data.frame and I'd like to
convert them into the format
that is needed by fuzzy_rules.

Here how the rules would be defined manually:

rules -
  set(
fuzzy_rule(depth %is% low  velocity %is% medium, suitability %is%
low),
fuzzy_rule(depth %is% medium  velocity %is% medium, suitability %is%
medium),
fuzzy_rule(depth %is% high  velocity %is% low, suitability %is% low)
  )

In my case I have the rules in following dataframe where a combination of
depth and velocity ()
result in a certain suitability. So every single row is actually a rule:

df -
data.frame(depth=c(low,medium,high),velocity=c(medium,medium,low),suitability=c(low,medium,low))

Is there an easy way to combine the columns per row in a way that in the
end I get the same format
as the object rules? As a single rule (fuzzy_rule) is not a pure text
string I don't know how to do that resp. to combine
all rules/rows into a set().

Any suggestions?

Best regards,
Johannes

[[alternative HTML version deleted]]

__
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.


Re: [R] Fuzzy rules definition (package sets) from data.frame

2013-05-08 Thread Johannes Radinger
Following my last mail, I found a simple solution using eval(parse)):

df -
data.frame(depth=c(low,medium,high),velocity=c(medium,medium,low),suitability=c(low,medium,low))
df$rule - paste(fuzzy_rule(depth %is% ,df[,depth],  ,velocity
%is% ,df[,velocity],, ,suitability %is%
,df[,suitability],),sep=)
rules -
eval(parse(text=paste(set(,paste(df[,rule],collapse=,),),sep=)))

which turns the dataframe into the rules definition object similar to:

rules -
  set(
fuzzy_rule(depth %is% low  velocity %is% medium, suitability %is%
low),
fuzzy_rule(depth %is% medium  velocity %is% medium, suitability %is%
medium),
fuzzy_rule(depth %is% high  velocity %is% low, suitability %is% low)
  )

/johannes

[[alternative HTML version deleted]]

__
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] NaN-result from fuzzy_inference (package sets) with certain input

2013-05-08 Thread Johannes Radinger
Hi,

I am trying to use the fuzzy_inference system on multiple input values.
Basically I combine two variables (depth, velocity) into the variable
suitability.
Both depth and velocity have 3 trapezoid classes (verylow,medium,high) each.
The consequent (suitability) has 4 fuzzy levels (none,low,medium,high) and
should
finally range between 0 and 1.
I already set up the level definitions (trapez-corners) and the rules (a
combination
of all depth-levels with all velocity-levels and the consequent
suitability).

Now I wanted to test the system on a dataframe with dummy variables (in the
range
of values I will supply), but some how I get for some combinations of depth
and velocity no resulting suitablilty.

I provide here now some code (simpler than my actual) that produces also
this
NaN values:

# Load sets
library(sets)

## set universe
sets_options(universe, seq(from = 0, to = 1, by = 0.001))

## set up fuzzy variables
variables -
set(depth = fuzzy_variable(verylow = fuzzy_trapezoid(corners =
c(-3,0,0.2,0.5)),
   medium = fuzzy_trapezoid(corners
=c(0.45,0.55,0.7,0.9)),
   veryhigh = fuzzy_trapezoid(corners =
c(0.85,1,15,20))),
velocity = fuzzy_variable(verylow = fuzzy_trapezoid(corners =
c(-3,0,0.2,0.5)),
  medium = fuzzy_trapezoid(corners =
c(0.35,0.55,0.65,0.8)),
  veryhigh = fuzzy_trapezoid(corners =
c(0.7,0.9,15,20))),
suitability = fuzzy_partition(varnames = c(none = 0.2, low = 0.4,
medium = 0.6, high = 0.8),FUN = fuzzy_cone, radius = 0.15))


## set up rules
rules -
  set(
fuzzy_rule(depth %is% verylow  velocity %is% verylow, suitability
%is% low),
fuzzy_rule(depth %is% medium  velocity %is% verylow, suitability %is%
medium),
fuzzy_rule(depth %is% veryhigh  velocity %is% verylow, suitability
%is% low),
fuzzy_rule(depth %is% verylow  velocity %is% medium, suitability %is%
medium),
fuzzy_rule(depth %is% medium  velocity %is% medium, suitability %is%
high),
fuzzy_rule(depth %is% veryhigh  velocity %is% medium, suitability
%is% medium),
fuzzy_rule(depth %is% verylow  velocity %is% veryhigh, suitability
%is% none),
fuzzy_rule(depth %is% medium  velocity %is% veryhigh, suitability
%is% low),
fuzzy_rule(depth %is% veryhigh  velocity %is% veryhigh, suitability
%is% none)
  )

## combine to a system
system - fuzzy_system(variables, rules)
print(system)
plot(system) ## plots variables

# test df
test_df -
data.frame(depth=round(runif(20,0,2),2),velocity=round(runif(20,0,1.5),2),suitability=NA)

# do inference on test_df
fuzzy_result - function(df){
  gset_defuzzify(fuzzy_inference(system, list(depth = df[depth], velocity
= df[velocity])),centroid)
}

apply(test_df,1,fuzzy_result)


Does anyone know what is happening there?

/Johannes

[[alternative HTML version deleted]]

__
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] string split at xth position

2013-03-13 Thread Johannes Radinger
Hi,

I have a vector of strings like:
c(a1b1,a2b2,a1b2) which I want to spilt into two parts like:
c(a1,a2,a2) and c(b1,b2,b2). So there is
always a first part with a+number and a second part with b+number.
Unfortunately there is no separator I could use to directly split
the vectors.. Any idea how to handle such cases?

/Johannes

__
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.


Re: [R] string split at xth position

2013-03-13 Thread Johannes Radinger
Thank you Jorge!

thats working perfectly...

/johannes



On Wed, Mar 13, 2013 at 9:45 AM, Jorge I Velez jorgeivanve...@gmail.com wrote:
 Dear Johannes,

 May not be the best way, but this looks like what you described:

 x - c(a1b1,a2b2,a1b2)
 x
 [1] a1b1 a2b2 a1b2
 substr(x, 1, 2)
 [1] a1 a2 a1
 substr(x, 3, 4)
 [1] b1 b2 b2

 HTH,
 Jorge.-


 On Wed, Mar 13, 2013 at 7:37 PM, Johannes Radinger  wrote:

 Hi,

 I have a vector of strings like:
 c(a1b1,a2b2,a1b2) which I want to spilt into two parts like:
 c(a1,a2,a2) and c(b1,b2,b2). So there is
 always a first part with a+number and a second part with b+number.
 Unfortunately there is no separator I could use to directly split
 the vectors.. Any idea how to handle such cases?

 /Johannes

 __
 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-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] Colour branches/labels of dendrogram according to a grouping variable

2013-03-07 Thread Johannes Radinger
Hi,

is there a way to color the branches or text label of the branches of
dendrograms e.g. from hclust() according to a grouping variable. Here
I have something in mind like:
http://www.sigmaaldrich.com/content/dam/sigma-aldrich/life-science/biowire/biowire-fall-2010/proteome-figure-1.Par.0001.Image.gif
(ectodermal, endodermal, mesodermal).

/johannes

__
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] Which df to extract from ANCOVA model

2013-01-18 Thread Johannes Radinger
Hi,

I am running an ANCOVA model like:

aov(Y ~ Var1 + Var2 + Var3 + Var4 + CoVar1 + CoVar2)

where Y is the response (metric, 1.0-1000.0), VarX are all
metric predictors, and CoVarX are two Covariates each a
factor of 4-5 levels.

So far as I can remember results of an ANCOVA for a Covariate
of interest (e.g. CoVar1) are given as e.g. (ANCOVA Fx,y = 2.72,
P-value = 0.01).
But which degrees of freedom (df) are usually reported together with
an F-value (x and y?)? Which df do I need to extract from the model
resp the model summary?

best regards,

Johannes

__
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] Merging list of dataframes with reshape merge_all

2013-01-11 Thread Johannes Radinger
Hi,

I'd like to merge mutliple dataframes from a list of dataframes by some common
columns. The approach for simply merging 2 dataframes is working with:

merge(df1,df2,by=c(col1,col2,col3),all=TRUE)

For mutliple dataframes in a list I try to use the merge_all command
from the package reshape.
The documentation states that the command takes a list of dataframes
and other additional
argument which are passed on to merge. So I tried (just for the case
of two dataframes):

merge_all(list(df1,df2),by=c(col1,col2,col3),all=TRUE)

but I get following error:
Error in merge.data.frame(dfs[[1]], dfs[[2]], all = TRUE, sort = FALSE,  :
  formal argument all matched by multiple actual arguments

What do I need to do to solve that problem?

PS: Just a related side-question: Why is merge_all not included in the
newer package reshape2 as this is considered to be a reboot of the
reshape package?

/johannes

__
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.


Re: [R] Merging list of dataframes with reshape merge_all

2013-01-11 Thread Johannes Radinger
Hi Rui,

thank you so far for your answer...
...as i found these other problems also myself, I decided to go
for a looping apporach with the base merge command and always
add a new dataframe to the old one (growing dataframe).

/johannes

On Fri, Jan 11, 2013 at 1:26 PM, Rui Barradas ruipbarra...@sapo.pt wrote:
 Hello,

 To solve the problem you can use all.x and all.y but I think there are
 other problems with merge_all, in the example below it doesn't include df2$Y
 in the result df.


 df1 - data.frame(col1=1:10, col2=11:20, col3=21:30, X = rnorm(10))
 df2 - data.frame(col1=1:10, col2=11:20, col3=21:30, Y = rnorm(10))

 merge_all(list(df1, df2), by=c(col1,col2,col3), all.x=TRUE,
 all.y=TRUE)  # No Y column
 merge(df1, df2, by=c(col1,col2,col3), all.x=TRUE, all.y=TRUE)


 Contact the package maintainer for more info.

 maintainer('reshape')
 [1] Hadley Wickham h.wick...@gmail.com


 Hope this helps,

 Rui Barradas

 Em 11-01-2013 10:08, Johannes Radinger escreveu:

 Hi,

 I'd like to merge mutliple dataframes from a list of dataframes by some
 common
 columns. The approach for simply merging 2 dataframes is working with:

 merge(df1,df2,by=c(col1,col2,col3),all=TRUE)

 For mutliple dataframes in a list I try to use the merge_all command
 from the package reshape.
 The documentation states that the command takes a list of dataframes
 and other additional
 argument which are passed on to merge. So I tried (just for the case
 of two dataframes):

 merge_all(list(df1,df2),by=c(col1,col2,col3),all=TRUE)

 but I get following error:
 Error in merge.data.frame(dfs[[1]], dfs[[2]], all = TRUE, sort = FALSE,  :
formal argument all matched by multiple actual arguments

 What do I need to do to solve that problem?

 PS: Just a related side-question: Why is merge_all not included in the
 newer package reshape2 as this is considered to be a reboot of the
 reshape package?

 /johannes

 __
 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-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] split rbind (cast) dataframe

2013-01-11 Thread Johannes Radinger
Hi,

I would like to split dataframe based on one colum and want
to connect the two dataframes by rows (like rbind). Here a small example:

# The orgininal dataframe
df1 - data.frame(col1 = c(A,A,B,B),col2 = c(1:4), col3 = c(1:4))

# The datafame how it could look like
df2 - data.frame(A.col2 = c(1,2), A.col3 = c(1,2), B.col2 = c(3,4),
B.col3 = c(3,4))

I think I already did a similar procedure sometime ago with the
cast() command from reshape-package but I cant remember correctly...
...maybe someone can point me to the correct formula...

Best

/johannes

__
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] Calculate geographic/euclidian distance between consecutive XY-pairs

2012-12-18 Thread Johannes Radinger
Hi,

I have a dataframe containing 3 columns:

data.frame(X=c(100,102,104,102,103),Y=c(12,14,14,13,16),Time=c(1,2,3,4,5))

where X and Y are coordinates and Time refers to an index of a timestep.
Now I would like to get the distance between the consecutive timesteps.

This should actually provide a vector of length=4, representing the euclidian
resp. geopgraphic distance between the first and the second, and the second
and the third timestep and so on...

Is there a simple way to calculate this and get the resulting vector
as a result?
Or can anyone give an example?


best regards,
/j

__
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.


Re: [R] Calculate geographic/euclidian distance between consecutive XY-pairs

2012-12-18 Thread Johannes Radinger
Hi Ray,

thank you very much. That one-line approach is what I was looking for.
A very simple but very efficient way without loading any other packages.

/j

On Tue, Dec 18, 2012 at 11:17 AM, Ray Brownrigg
ray.brownr...@ecs.vuw.ac.nz wrote:
 On 18/12/2012 10:56 p.m., Johannes Radinger wrote:

 Hi,

 I have a dataframe containing 3 columns:

 data.frame(X=c(100,102,104,102,103),Y=c(12,14,14,13,16),Time=c(1,2,3,4,5))

 where X and Y are coordinates and Time refers to an index of a timestep.
 Now I would like to get the distance between the consecutive timesteps.

 This should actually provide a vector of length=4, representing the
 euclidian
 resp. geopgraphic distance between the first and the second, and the
 second
 and the third timestep and so on...

 Is there a simple way to calculate this and get the resulting vector
 as a result?
 Or can anyone give an example?

 How about something like:
 coords -
 data.frame(X=c(100,102,104,102,103),Y=c(12,14,14,13,16),Time=c(1,2,3,4,5))
 with(coords, sqrt(diff(X)^2 + diff(Y)^2))

 Ray Brownrigg


 best regards,
 /j

 __
 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-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] Renaming column names according to another dataframe

2012-12-11 Thread Johannes Radinger
Hi,

I've got a dataframe having a code as column name.
Addtionally I have another dataframe with a two columns (and lots of
rows), the first
containing the code and the second some Text (real name).

Now I'd like to use the information (pairs of code and name) of the
second dataframe to rename all the columnnames in the first dataframe.
How is it possible to achieve that?

Here a small example of the two dataframes:

df - data.frame(A=(1:10),B=(1:10),C=(1:10))
df_names - data.frame(code=c(A,B,C,D,E),name=c(Col A,Col
B,Col C,Col D,Col E))

/j

__
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.


Re: [R] Renaming column names according to another dataframe

2012-12-11 Thread Johannes Radinger
Hi,

thank you so much, that works perfectly. I used
the first suggestion by Anthony (names( df ) - df_names[ match(
names( df ) , df_names[ , 'code' ] ) , 'name' ]).
Thank you for the hint about ?match... that was the function I was
looking for, makes comparing vectors very easy.

best,
/Johannes

On Tue, Dec 11, 2012 at 1:06 PM, arun smartpink...@yahoo.com wrote:
 HI,

 You can also try this:
 df - data.frame(A=(1:10),B=(1:10),C=(1:10))
 df_names - data.frame(code=c(A,B,D,E,C),name=c(Col A,Col 
 B,Col D,Col E,Col C))

 names(df)-df_names$name[match(names(df),df_names$code)]


 A.K.

 - Original Message -
 From: Johannes Radinger johannesradin...@gmail.com
 To: r-help@r-project.org
 Cc:
 Sent: Tuesday, December 11, 2012 5:55 AM
 Subject: [R] Renaming column names according to another dataframe

 Hi,

 I've got a dataframe having a code as column name.
 Addtionally I have another dataframe with a two columns (and lots of
 rows), the first
 containing the code and the second some Text (real name).

 Now I'd like to use the information (pairs of code and name) of the
 second dataframe to rename all the columnnames in the first dataframe.
 How is it possible to achieve that?

 Here a small example of the two dataframes:

 df - data.frame(A=(1:10),B=(1:10),C=(1:10))
 df_names - data.frame(code=c(A,B,C,D,E),name=c(Col A,Col
 B,Col C,Col D,Col E))

 /j

 __
 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-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] Crosstable-like analysis (ks test) of dataframe

2012-09-28 Thread Johannes Radinger
Hi,

I have a dataframe with multiple (appr. 20) columns containing
vectors of different values (different distributions).
 Now I'd like to create a crosstable
where I compare the distribution of each vector (df-column) with
each other. For the comparison I want to use the ks.test().
The result should contain as row and column names the column names
of the input dataframe and the cells should be populated with
the p-value of the ks.test for each pairwise analysis.

My data.frame looks like:
df - data.frame(X=rnorm(1000,2),Y=rnorm(1000,1),Z=rnorm(1000,2))

And the test for one single case is:
ks - ks.test(df$X,df$Z)

where the p value is:
ks[2]

How can I create an automatized way of this pairwise analysis?
Any suggestions? I guess that is a quite common analysis (probably with
other tests).

cheers,
Johannes

__
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.


Re: [R] Crosstable-like analysis (ks test) of dataframe

2012-09-28 Thread Johannes Radinger
Thank you Rui!

that works as I want it... :)

/Johannes

On Fri, Sep 28, 2012 at 12:30 PM, Rui Barradas ruipbarra...@sapo.pt wrote:
 Hello,

 Try the following.


 f - function(x, y, ...,
 alternative = c(two.sided, less, greater), exact = NULL){
 #w - getOption(warn)
 #options(warn = -1)  # ignore warnings
 p - ks.test(x, y, ..., alternative = alternative, exact =
 exact)$p.value
 #options(warn = w)
 p
 }

 n - 1e1
 dat - data.frame(X=rnorm(n), Y=runif(n), Z=rchisq(n, df=3))

 apply(dat, 2, function(x) apply(dat, 2, function(y) f(x, y)))

 Hope this helps,

 Rui Barradas
 Em 28-09-2012 11:10, Johannes Radinger escreveu:

 Hi,

 I have a dataframe with multiple (appr. 20) columns containing
 vectors of different values (different distributions).
   Now I'd like to create a crosstable
 where I compare the distribution of each vector (df-column) with
 each other. For the comparison I want to use the ks.test().
 The result should contain as row and column names the column names
 of the input dataframe and the cells should be populated with
 the p-value of the ks.test for each pairwise analysis.

 My data.frame looks like:
 df - data.frame(X=rnorm(1000,2),Y=rnorm(1000,1),Z=rnorm(1000,2))

 And the test for one single case is:
 ks - ks.test(df$X,df$Z)

 where the p value is:
 ks[2]

 How can I create an automatized way of this pairwise analysis?
 Any suggestions? I guess that is a quite common analysis (probably with
 other tests).

 cheers,
 Johannes

 __
 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-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] Colsplit, removing parts of a string

2012-09-27 Thread Johannes Radinger
Hi,

I am using colsplit (package = reshape) to split all strings
in a column according to the same patterns. Here
an example:

library(reshape2)


df1 - data.frame(x=c(str1_name2, str3_name5))
df2 - data.frame(df1, colsplit(df1$x, pattern = _, names=c(str,name)))

This is nearly what I want but I want to remove the words str and
name from the values, because the columns are already named with
that words. Is there a way to remove them using colsplit? Or any other
simple way?

/johannes

__
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.


Re: [R] Colsplit, removing parts of a string

2012-09-27 Thread Johannes Radinger
Thank you,

this works perfectly...

best regards,
Johannes

On Thu, Sep 27, 2012 at 1:43 PM, Ista Zahn istaz...@gmail.com wrote:
 Hi Johannes,

 On Thu, Sep 27, 2012 at 7:25 AM, Johannes Radinger
 johannesradin...@gmail.com wrote:
 Hi,

 I am using colsplit (package = reshape) to split all strings
 in a column according to the same patterns. Here
 an example:

 library(reshape2)


 df1 - data.frame(x=c(str1_name2, str3_name5))
 df2 - data.frame(df1, colsplit(df1$x, pattern = _, names=c(str,name)))

 This is nearly what I want but I want to remove the words str and
 name from the values, because the columns are already named with
 that words. Is there a way to remove them using colsplit? Or any other
 simple way?

 You can remove them afterwords, e.g.,

 df2$str - gsub([^0-9], , df2$str)
 df2$name - gsub([^0-9], , df2$name)

 Best,
 Ista


 /johannes

 __
 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-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] Installing packages xslx on Ubuntu (32bit)

2012-07-25 Thread Johannes Radinger
Hi,

I just recently changed my OS to Ubuntu 12.04 (32bit). Now I tried to install 
some packages required by my old and working scripts. Unfortunately I fail when 
trying to install the package xslx. Maybe it is related to the 32bit version 
of my R (its not possible to install a 64 bit version).

Can anyone help me to sucessfully install xslx?

Here some console output (e.g. sessionInfo()):

 install.packages(xslx)
Installing package(s) into '/usr/local/lib/R/site-library'
(as 'lib' is unspecified)
--- Please select a CRAN mirror for use in this session ---
Loading Tcl/Tk interface ... done
Warning message:
In getDependencies(pkgs, dependencies, available, lib) :
  package 'xslx' is not available (for R version 2.14.1)
 sessionInfo()
R version 2.14.1 (2011-12-22)
Platform: i686-pc-linux-gnu (32-bit)

locale:
[1] C

attached base packages:
[1] stats graphics  grDevices utils datasets  methods   base 

loaded via a namespace (and not attached):
[1] tcltk_2.14.1 tools_2.14.1
 

Any suggestions?

/Johannes

__
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.


Re: [R] Installing packages xslx on Ubuntu (32bit) [On R 2.14.1]

2012-07-25 Thread Johannes Radinger
Hi


 Hmm, there is no such package: did you mean xlsx?

of course xlsx :), 

I upgraded to 2.15.1 and installed openjdk-6-jdk and run R CMD javareconf.
Then I was successful in installing package xlsx.

Thank you!

/Johannes

 
 However, your R is old and quite a few packages are not available for 
 it.  Please do as the posting guide suggests and update to R 2.15.1 (or 
 R-patched).
 
 
 On 25/07/2012 09:47, Johannes Radinger wrote:
  Hi,
 
  I just recently changed my OS to Ubuntu 12.04 (32bit). Now I tried to
 install some packages required by my old and working scripts. Unfortunately I
 fail when trying to install the package xslx. Maybe it is related to the
 32bit version of my R (its not possible to install a 64 bit version).
 
  Can anyone help me to sucessfully install xslx?
 
  Here some console output (e.g. sessionInfo()):
 
  install.packages(xslx)
  Installing package(s) into '/usr/local/lib/R/site-library'
  (as 'lib' is unspecified)
  --- Please select a CRAN mirror for use in this session ---
  Loading Tcl/Tk interface ... done
  Warning message:
  In getDependencies(pkgs, dependencies, available, lib) :
 package 'xslx' is not available (for R version 2.14.1)
  sessionInfo()
  R version 2.14.1 (2011-12-22)
  Platform: i686-pc-linux-gnu (32-bit)
 
  locale:
  [1] C
 
  attached base packages:
  [1] stats graphics  grDevices utils datasets  methods   base
 
  loaded via a namespace (and not attached):
  [1] tcltk_2.14.1 tools_2.14.1
 
 
  Any suggestions?
 
  /Johannes
 
  __
  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.
 
 
 
 -- 
 Brian D. Ripley,  rip...@stats.ox.ac.uk
 Professor of Applied Statistics,  http://www.stats.ox.ac.uk/~ripley/
 University of Oxford, Tel:  +44 1865 272861 (self)
 1 South Parks Road, +44 1865 272866 (PA)
 Oxford OX1 3TG, UKFax:  +44 1865 272595

__
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] reshape - reshape 2: function cast changed?

2012-07-25 Thread Johannes Radinger
Hi,

I used to use reshape and moved to reshape2 (R 2.15.1). Now I tried some of my 
older scripts and was surprised that my cast function wasn't working like 
before.
What I did/want to do:
1) Melt a dataframe based on a vector specifying column names as measure.vars. 
Thats working so far:
dfm - melt(df, measure.vars=n, variable_name = species, na.rm = FALSE)

2) Recast the dataframe:
dfc - cast(dfm, Var1 + Var2 + Var3 + Var4 ~ species,max) # with reshape
dfc - dcast(dfm, Var1 + Var2 + Var3 + Var4 ~ species,max) # with reshape2

but then I get (this is new to reshape2!) a warning message:
In .fun(.value[0], ...) : no non-missing arguments to max; returning -Inf

The result seems to be similar (but I haven't checked it yet properly)? A 
message to ignore?

I use melt/cast/melt e.g. for multiple measurements (similar name in one 
column) to get only one row (one measurement) with e.g. the max value. Of 
course during the procedure I can also use cast/melt to drop columns that are 
not relevant for further processing.

/Johannes

__
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] Complex summary of counts of rank positions over multiple dataframes

2012-06-14 Thread Johannes Radinger
Hi,

I've kind of a tricky question, which I don't know how to solve yet:

I get multiple dataframes  loaded (readRDS) in a loop function. Each loaded 
dataframe contains two columns one with a var-name and one with a value. The 
rownumber (order) is very important as it is a value of the rank (1:x). 
A example with a similar looped structure:

df1 - data.frame(var=c(A,B,C,D),value=c(12,5,4,2))
df2 - data.frame(var=c(B,A,G,C,J),value=c(24,6,4,3,1))
df3 - data.frame(var=c(A,B,D,K), value=c(22,15,5,2))

df.list - list(df1,df2,df3)

for(i in df.list){
print(i)
}



Now I want to create a summary which should contain a list of all 'vars' 
(overall in all dataframes), and counts of their ranks. For the example: There 
are 7 unique 'vars' in all dataframes (A,B,C,D,G,J,K) and e.g.
A is two times on the first position and 1 time on the second rank etc.
A resulting dataframe could look like:
uniquevars - c(A,B,C,D,G,J,K)
rank1a - c(2,1,0,0,0,0,0)
rank2a - c(1,2,0,0,0,0,0)
rank3a - c(0,0,1,1,1,0,0)
rank4a - c(0,0,1,1,0,0,1)
result_a - data.frame(uniquevars,rank1a,rank2a,rank3a,rank4a)


In addition I would like to have for all populated 'cells' of the
result_a-dataframe the sum of the all 'values' from the original dataframes
instead of the counts.
Like:
rank1b - c(34,24,0,0,0,0,0)
rank2b - c(6,20,0,0,0,0,0)
rank3b - c(0,0,4,5,4,0,0)
rank4b - c(0,0,3,2,0,0,2)
result_b - data.frame(uniquevars,rank1b,rank2b,rank3b,rank4b)


Is there any common procedure to get counts of ranks for multiple dataframes?

Has anyone done similar things I can help me to get this done in a simple way 
considering the multiple dataframes in the loop?

/Johannes
-- 

Jetzt informieren: http://mobile.1und1.de/?ac=OM.PW.PW003K20328T7073a

__
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] Sort 1-column dataframe with rownames

2012-06-08 Thread Johannes Radinger
Hi,

I have a 1-column dataframe with rownames and I want to sort it
based on the single column. The typical procedure that is recommended
in diverse posts is to use order in the index. But that destroys my
dataframe structure. Probabaly it is a very simple solution. Here is a
short reproducable example:

x - c(1,3,51,2,34,44,12,33,2,8)

df - data.frame(x)
rownames(df) - c(A,B,C,D,E,F,G,H,I,J)

df.sort - df[order(df[,x]),]

/Johannes
-- 

Jetzt informieren: http://mobile.1und1.de/?ac=OM.PW.PW003K20328T7073a

__
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.


Re: [R] Sort 1-column dataframe with rownames

2012-06-08 Thread Johannes Radinger
Hi Achim,

thank you for your good explanation and the solution to my
question...

cheers,
/j

 Original-Nachricht 
 Datum: Fri, 8 Jun 2012 09:30:42 +0200 (CEST)
 Von: Achim Zeileis achim.zeil...@uibk.ac.at
 An: Johannes Radinger jradin...@gmx.at
 CC: R-help@r-project.org
 Betreff: Re: [R] Sort 1-column dataframe with rownames

 On Fri, 8 Jun 2012, Johannes Radinger wrote:
 
  Hi,
 
  I have a 1-column dataframe with rownames and I want to sort it
  based on the single column. The typical procedure that is recommended
  in diverse posts is to use order in the index. But that destroys my
  dataframe structure. Probabaly it is a very simple solution. Here is a
  short reproducable example:
 
  x - c(1,3,51,2,34,44,12,33,2,8)
 
  df - data.frame(x)
  rownames(df) - c(A,B,C,D,E,F,G,H,I,J)
 
  df.sort - df[order(df[,x]),]
 
 If you select a single column, then the default is to drop the data.frame 
 property. You exploit this in your own code in df[,x] which yields a 
 simple vector. To suppress this behavior you can set drop = FALSE:
 
 df.sort - df[order(df[,x]), , drop = FALSE]
 
 hth,
 Z
 
  /Johannes
  -- 
 
  Jetzt informieren: http://mobile.1und1.de/?ac=OM.PW.PW003K20328T7073a
 
  __
  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.
 

-- 

Jetzt informieren: http://mobile.1und1.de/?ac=OM.PW.PW003K20328T7073a

__
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] Redefine multiple columns (using grep) as factor variables

2012-06-01 Thread Johannes Radinger
Hi,

I have a dataframe with around 100 columns. Now I want
to redefine some of the columns as factors (using as.factor).
Luckily all the names of the columns I want to redefine start with 
crast. Thus I thought I can use grep() for that purpose...
...I found an example for redefining a single column as factor
but that is not working with multiple columns I get from grep()...

what I tried so far:
df[, grep(^crast, colnames(df))] - as.factor(df[, grep(^crast, 
colnames(df))])

any suggestions?

cheers,

/Johannes


-- 

Jetzt informieren: http://mobile.1und1.de/?ac=OM.PW.PW003K20328T7073a

__
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] Transform counts into presence/absence

2012-05-31 Thread Johannes Radinger
Hi,

I am looking for a very easy way to transform
a column in a dataframe from counts (eg. c(1,0,21,2,0,0,234,2,0))
into a binary form to get presence/absence values
e.g. c(1,0,1,1,0,0,1,1,0). Is there a simple built-in function?
or do I have do to it with a replaceement funciton using IF x  0
THEN 1 etc.?

/johannes
-- 

Jetzt informieren: http://mobile.1und1.de/?ac=OM.PW.PW003K20328T7073a

__
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.


Re: [R] Transform counts into presence/absence

2012-05-31 Thread Johannes Radinger


 Original-Nachricht 
 Datum: Thu, 31 May 2012 11:16:32 +
 Von: ONKELINX, Thierry thierry.onkel...@inbo.be
 An: Johannes Radinger jradin...@gmx.at, R-help@r-project.org 
 R-help@r-project.org
 Betreff: RE: [R] Transform counts into presence/absence

 Just use the logical operators.


of course, that simple :) . thank you!


 
 Counts - c(1,0,21,2,0,0,234,2,0)
 Counts  0
 1 *(Counts  0)
 
 ir. Thierry Onkelinx
 Instituut voor natuur- en bosonderzoek / Research Institute for Nature and
 Forest
 team Biometrie  Kwaliteitszorg / team Biometrics  Quality Assurance
 Kliniekstraat 25
 1070 Anderlecht
 Belgium
 + 32 2 525 02 51
 + 32 54 43 61 85
 thierry.onkel...@inbo.be
 www.inbo.be
 
 To call in the statistician after the experiment is done may be no more
 than asking him to perform a post-mortem examination: he may be able to say
 what the experiment died of.
 ~ Sir Ronald Aylmer Fisher
 
 The plural of anecdote is not data.
 ~ Roger Brinner
 
 The combination of some data and an aching desire for an answer does not
 ensure that a reasonable answer can be extracted from a given body of data.
 ~ John Tukey
 
 
 -Oorspronkelijk bericht-
 Van: r-help-boun...@r-project.org [mailto:r-help-boun...@r-project.org]
 Namens Johannes Radinger
 Verzonden: donderdag 31 mei 2012 13:13
 Aan: R-help@r-project.org
 Onderwerp: [R] Transform counts into presence/absence
 
 Hi,
 
 I am looking for a very easy way to transform a column in a dataframe from
 counts (eg. c(1,0,21,2,0,0,234,2,0)) into a binary form to get
 presence/absence values e.g. c(1,0,1,1,0,0,1,1,0). Is there a simple built-in
 function?
 or do I have do to it with a replaceement funciton using IF x  0 THEN 1
 etc.?
 
 /johannes
 --
 
 Jetzt informieren: http://mobile.1und1.de/?ac=OM.PW.PW003K20328T7073a
 
 __
 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.
 * * * * * * * * * * * * * D I S C L A I M E R * * * * * * * * * * * * *
 Dit bericht en eventuele bijlagen geven enkel de visie van de schrijver
 weer en binden het INBO onder geen enkel beding, zolang dit bericht niet
 bevestigd is door een geldig ondertekend document.
 The views expressed in this message and any annex are purely those of the
 writer and may not be regarded as stating an official position of INBO, as
 long as the message is not confirmed by a duly signed document.

-- 

Jetzt informieren: http://mobile.1und1.de/?ac=OM.PW.PW003K20328T7073a

__
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] Remove columns from dataframe based on their statistics

2012-05-31 Thread Johannes Radinger
Hi,

I have a dataframe and want to remove columns from it
that are populated with a similar value (for the total
column) (the variation of that column is 0). Is there an
easier way than to calculate the statistics and then
remove them by hand?

A - runif(100)
B - rep(1,100)
C - rep(2.42,100)
D - runif(100)
df - data.frame(A,B,C,D) # if want to conditionally remove column B and C as 
they show no variations

/Johannes
-- 

Jetzt informieren: http://mobile.1und1.de/?ac=OM.PW.PW003K20328T7073a

__
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.


Re: [R] Remove columns from dataframe based on their statistics

2012-05-31 Thread Johannes Radinger
Hi James
Hi Jorge,

Thank you very much!
I like the apply-approach, it seems really quite
simple and I get back the TRUE-FALSE vector which
I can use for indexing the dataframe.
Now there popped the questions if one can implement
any exeption, like do the selection of
the columns exept for column with name B.
I have to think about this

/Johannes

 Original-Nachricht 
 Datum: Thu, 31 May 2012 09:20:27 -0500
 Von: J Toll jct...@gmail.com
 An: Johannes Radinger jradin...@gmx.at
 CC: R-help@r-project.org
 Betreff: Re: [R] Remove columns from dataframe based on their statistics

 On Thu, May 31, 2012 at 8:52 AM, J Toll jct...@gmail.com wrote:
 
  for (i in seq(ncol(df), 1))
   if (length(unique(df[, i])) == 1) {
   df[, i] - NULL
  }
 
 Here's a similar method employing a more functional approach:
 
 df[, apply(df, 2, function(x) length(unique(x))  1)]
 
 
 James

-- 

Jetzt informieren: http://mobile.1und1.de/?ac=OM.PW.PW003K20328T7073a

__
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] text(): combine expression and line break

2012-05-11 Thread Johannes Radinger
Hi,

I would like to plot some extra text in my plot.
This should be a two line text including a special character (sigma).
I tried so far a to use expression in combination with paste and \n...
but I can't get the line break...

Here what I've done so far:

plot(1,type=n, xaxt='n', yaxt='n', ann=FALSE)
text(1,1,labels=expression(paste(sigma,\n (log scale, m))),cex = 2)

Maybe someone knows how I can achieve that...


cheers,

/johannes



[[alternative HTML version deleted]]

__
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] plotting legend-grob with grid.layout

2012-05-10 Thread Johannes Radinger
Hi,

I am using ggplot2 and arrange differnet plots into
one viewport by dividing it into rows and columns:


pushViewport(viewport(layout = grid.layout(nrow=2,ncol=2,widths = unit(c(50, 
50), mm),heights = unit(c(50, 50), mm

with following function I can extract the legend of a previously defined
plot (ggplot2-plot) as a grob:

legend - function(plot){
tmp - ggplot_gtable(ggplot_build(plot))
leg - which(sapply(tmp$grobs, function(x) x$name) == guide-box)
legend - tmp$grobs[[leg]]
}

The plot themselves are sent to the viewport with:

vplayout - function(x, y)
viewport(layout.pos.row = x, layout.pos.col = y)
print(p1, vp = vplayout(1, 1))


But, how can I put the legend into the viewport (e.g. colum=1,row=2)...

I tried with draw.grob() which works, but then I can define the posiiton...
This grid-arraning-viewport stuff is very confusing to me, so maybe someone can 
help out here...

/johannes

-- 

Jetzt informieren: http://mobile.1und1.de/?ac=OM.PW.PW003K20328T7073a

__
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] Correct use of ddply with own function

2012-05-05 Thread Johannes Radinger
Hi,

I am really confused how ddply work, so maybe you can help me.

I created a function that sorts a vector etc.

fn - function(x){
x1 - sort(x)
x2 - seq(length(x))
x3 - x2/max(x2)
df - data.frame(x1,x2,x3)
df
}

Probably this is not the best form of the function, but at least it produces 
what I want (data to plot a cumulative count curve).
This function works on a single vector but I have a melted dataframe like:

var1 - rep(c(a,b),c(100,100))
var2 - runif(200,1,50)
df.test - data.frame(var1,var2)

..and I want to apply that function on var2 but splitted by the variable var1. 
I think this might be a case for ddply...

anything like: ddply(df.test,.(var1),fn(var2))...
maybe someone know how to do that (modifying my function and applying it on a 
splitted dataframe).

Best regards,

Johannes

__
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] Absolute cumulative curve with ecdf/stepfun?

2012-05-04 Thread Johannes Radinger
Hi,

I have two variables ranging both from 0 to 1 (n=500 each).
Now I am interested in plotting them both in one plot (using ggplot2).

So far I used ecdf() (from an example I found with google) to get
values for the cumulatice distribution function which gives a relative
curve. I also want to do the same plot but using absolute cumulative
values instead of relative. Can that be done with ecdf or with stepfun()
to get values I can use to plot the curves?

Here a small example that shows the result with ecdf:

library(ggplot2)
library(reshape)

dftest1 - data.frame(value=runif(1000,0,1),variable=rep(c(a,b),c(500,500)))
dftest2 - ddply(dftest1,.(variable),transform, ecd = ecdf(value)(value))

ggplot(dftest2,aes(x = value, y = ecd)) + 
geom_line(aes(group = variable,colour = variable))

I'd like to replace the ecdf-function in ddply with a function that gives 
cumulative counts resp. the cumulative position of each observation, so that I 
get an absolute cumulative curve as a result? Is that understandable?

Thank you very much,

Johannes
-- 

Jetzt informieren: http://mobile.1und1.de/?ac=OM.PW.PW003K20328T7073a

__
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] Generate strings from multiple variables

2012-05-04 Thread Johannes Radinger
Hi,

it is easiest to explain what I want to do by an example:

lets assume there are two factors/variables:
A - c(1,2,3)
B - c(1,3,3)

Now I would like to generate a list of strings that should look like
(A1_B1,A1_B2,A2_B1,A2_B2). So actually the string
contains all possible combinations of A and B (separated by _). This should
be also possible for more variables. Is there simple way
to that? I thought about looping over A and B (nested for-loop)
but maybe there is a straight foward solution to get such strings.

/johannes


-- 

Jetzt informieren: http://mobile.1und1.de/?ac=OM.PW.PW003K20328T7073a

__
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.


Re: [R] Two ecdf with log-scales

2012-05-03 Thread Johannes Radinger
Thank you Steve,

thats the thing I was looking for

/Johannes

 Original-Nachricht 
 Datum: Thu, 3 May 2012 08:20:51 -0400
 Von: Steven Wolf wolfs...@msu.edu
 An: \'David Winsemius\' dwinsem...@comcast.net, \'Johannes Radinger\' 
 jradin...@gmx.at
 CC: R-help@r-project.org
 Betreff: RE: [R] Two ecdf with log-scales

 I've done it this way before:
 
 eX - ecdf(distribution 1)
 eY - ecdf(distribution 2)
 par(mar=c(5,5,2,1),xlog=TRUE)
 plot(eX, do.points=FALSE, verticals=TRUE, col=black, xlab=xlabel,
 xlim=c(1,10), ylab=ylabel, 
   lty=1, cex.lab=1.5, cex.axis=1.5, main=,
 lwd=3,log=x)
 plot(eY, do.points=FALSE, verticals=TRUE, col=blue, add=TRUE,
 xlim=c(1,10), main=)
 
 Warning:  It makes a stair-step that may be difficult to see unless you
 use
 color.  I had to change how the ecdf was plotted when I made b/w figures
 for
 my publication so that different dashed lines were distinct.
 
 HTH,
 -Steve
 
 -Original Message-
 From: David Winsemius [mailto:dwinsem...@comcast.net] 
 Sent: Wednesday, May 02, 2012 10:17 AM
 To: Johannes Radinger
 Cc: R-help@r-project.org
 Subject: Re: [R] Two ecdf with log-scales
 
 
 On May 2, 2012, at 6:14 AM, Johannes Radinger wrote:
 
  Hi,
 
  i want to plot empirical cumulative density functions for two 
  variables in one plot. For better visualizing the differences in the 
  two cumulative curves I'd like to log-scale the axis.
 
  So far I found 3 possible functions to plot ecdf:
 
  1) ecdf() from the package 'stats'. I don't know how to successfully 
  set the log.scales? Combining two plots is not a problem:
 
  plot(ecdf(x1))
  lines(ecdf(x2),col.h=red)
 
  2) gx.ecdf() from package 'rgr'. It is easily possible to plot log- 
  scales, but I don't know how to plot two densities?
 
  gx.ecdf(x1,log=TRUE,ifqs = TRUE)
 
  3) Ecdf() from package 'Hmisc'. No log-option directly available and 
  here I also don't know how to 'stack' two plots...
 
  Ecdf(x1,what=F)
 
 
  Probably there are many more solutions (e.g. ggplot etc.)...
  ...Has anyone faced a similar task and found a simple solution? Any 
  suggestions are welcome!
 
 Have you searched the Archives? I seem to remember that the log(0) was a
 barrier to persons attempting this in the past. (ISTR a posting in the
 last
 few weeks.)  Maybe you could also provide a test data object that has the
 same range as your x1 and x 2 variables.
 
  and provide commented, minimal, self-contained, reproducible code.
 
 -- 
 
 David Winsemius, MD
 West Hartford, CT
 
 
 

-- 

Jetzt informieren: http://mobile.1und1.de/?ac=OM.PW.PW003K20328T7073a

__
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] Two ecdf with log-scales

2012-05-02 Thread Johannes Radinger
Hi,

i want to plot empirical cumulative density functions for two variables in
one plot. For better visualizing the differences in the two cumulative curves 
I'd like to log-scale the axis.

So far I found 3 possible functions to plot ecdf:

1) ecdf() from the package 'stats'. I don't know how to successfully set the 
log.scales? Combining two plots is not a problem:

plot(ecdf(x1))
lines(ecdf(x2),col.h=red)

2) gx.ecdf() from package 'rgr'. It is easily possible to plot log-scales, but 
I don't know how to plot two densities?

gx.ecdf(x1,log=TRUE,ifqs = TRUE)

3) Ecdf() from package 'Hmisc'. No log-option directly available and here I 
also don't know how to 'stack' two plots...

Ecdf(x1,what=F)


Probably there are many more solutions (e.g. ggplot etc.)...
...Has anyone faced a similar task and found a simple solution? Any suggestions 
are welcome!

Best regards,

Johannes


-- 

Jetzt informieren: http://mobile.1und1.de/?ac=OM.PW.PW003K20328T7073a

__
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] Scatterplot matrix with partly transformed axis

2012-04-10 Thread Johannes Radinger
Hi,

I am wondering if anybody has experience with
scatterplot matrices where some (but NOT all) axis
are transformed and the labels are nicely plotted.

So far I looked into
1) pairs()
2) scatterplotMatrix() from package 'car'
3) splom() from packagae 'lattice'
4) plotmatrix() from 'ggplot2'

I can see no easy way to get what I want which is:
*) a scatterplot matrix of three variables
*) 2 of 3 variables should be log-transformed
*) the labels for the log transformed variables should be e^2 etc resp. 10^2 
etc.
*) the variable names in the diagonal panel
*) no need for any densities
*) Correlation coefficients in the upper panel

I am not sure what is the best way to go to get a nice scatterplot matrix to 
publish...

One example with pairs() so far...but I didn't get the log scales and the 
labels:

panel.cor - function(x, y, digits=2, prefix=, cex.cor)
{
usr - par(usr); on.exit(par(usr))
par(usr = c(0, 1, 0, 1))
r - abs(cor(x, y))
txt - format(c(r, 0.123456789), digits=digits)[1]
txt - paste(prefix, txt, sep=)
if(missing(cex.cor)) cex - 0.5/strwidth(txt)

test - cor.test(x,y)
# borrowed from printCoefmat
Signif - symnum(test$p.value, corr = FALSE, na = FALSE,
cutpoints = c(0, 0.001, 0.01, 0.05, 0.1, 1),
symbols = c(***, **, *, .,  ))

text(0.5, 0.5, paste(txt,Signif), cex = 2)
}

# Test with data
data(iris)
pairs(iris[1:3], lower.panel = function(...) panel.smooth(..., 
col.smooth=grey), upper.panel=panel.cor)


Maybe someone can help me here as I think this is also helpful to others with a 
similar kind of problem.

Best regards,

Johannes

-- 

Jetzt informieren: http://mobile.1und1.de/?ac=OM.PW.PW003K20328T7073a

__
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] output of several results from a function

2012-04-03 Thread Johannes Radinger
Hi,

I try my first time to write a summary method for my function. The result of my 
function is a list of two objects (2 arrays). In my summary both objects should 
be displayed but with a some introductory text like:

ls - list(A=A123,B=B123)

summaryout=function(x,...){
cat(This is output A:/n)
x$A
cat(This is output B:/n)
x$B
}

How can I achieve that both list-elements are displayed and the lines 
inbetween, so that it looks nice? 

As the single list elements are arrays (partly 5-dimensional) is there a nice 
way to display them i a summary or print method?

cheers,


best regards,

Johannes
-- 

Jetzt informieren: http://mobile.1und1.de/?ac=OM.PW.PW003K20328T7073a

__
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] Make package out of own function

2012-04-02 Thread Johannes Radinger
Hello,

I already posted that on stackoverflow[1], but although it's crossposting,
I think this question can probably easier to be answered by other R-users on 
this list, which maintain packages etc.

I would like to make a package out of a function. The function
is working in a script, but when I install and load it as library()
I get an error. The example-function is:

#Make generic function
f - function(x,...) UseMethod(f)

#Default method
f.default - function(a,b=5,c=3,...){
out - a+b+c
class(out) - f
out
}

# Print method
print.f - function(x,...){
cat(Result for f: )
print(unclass(x))
}

In the NAMESPACE for export I set f.
When I try to run the function from the package I get: 
Error in UseMethod(f) : 
  no applicable method for 'f' applied to an object of class c('double', 
'numeric')

here some additional info:
 sessionInfo()
R version 2.14.2 (2012-02-29)
Platform: i386-apple-darwin9.8.0/i386 (32-bit)

locale:
[1] en_US.UTF-8/en_US.UTF-8/en_US.UTF-8/C/en_US.UTF-8/en_US.UTF-8

attached base packages:
[1] stats graphics  grDevices utils datasets  methods   base 

other attached packages:
[1] fishmove_0.0-1 plyr_1.7.1 ggplot2_0.9.0 

loaded via a namespace (and not attached):
 [1] colorspace_1.1-1   dichromat_1.2-4digest_0.5.1   grid_2.14.2   
 MASS_7.3-17   
 [6] memoise_0.1munsell_0.3proto_0.3-9.2  
RColorBrewer_1.0-5 reshape2_1.2.1
[11] scales_0.2.0   stringr_0.6   
 


Can anyone explain me how to solve that resp. how to make my own function into 
a package?

Best regards,

Johannes

[1]: 
http://stackoverflow.com/questions/8430178/arguments-and-classes-for-writing-generic-functions-in-r

-- 

Jetzt informieren: http://mobile.1und1.de/?ac=OM.PW.PW003K20328T7073a

__
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] Unwanted page break in Rd2pdf

2012-04-02 Thread Johannes Radinger
Hi,

I want to create a pdf of my Man-pages from my package.
Therefore I run in the terminal Rd2pdf on the package and
a pdf of all the pages is created.

After the titlepage there is the general package page, which includes
Description and Details etc. Unfortunately after the Subtitle Details 
there is a pagebreak (and 3/4 white page) which I did not set there...

Any recommendation how I can avoid this?

best regards,

/Johannes
-- 

Jetzt informieren: http://mobile.1und1.de/?ac=OM.PW.PW003K20328T7073a

__
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] Enhance Pairs Scatterplot Matrix

2012-03-26 Thread Johannes Radinger
Hi,

I am trying to do plot a scatterplot matrix using pairs() from
the package graphics. There are now a few things I'd like to improve
for a better understanding.

1) My scatterplot uses two log-scaled axis...as I
don't know how to set them in pairs() I calculated the log before but now
the labels are not as I want them. I'd like them as 10^1,10^2 etc.
What is the best way to handle log-scales with scatterplot matrices?

2) I use the upper panel for showing correlation coefficients instead of
the scatterplots. For these panels I don't need axis. So I'd like to 
concentrate my axis in the lower panel, how can that be done?

3) Is it possible to label the axis e.g with the dimensions etc.?

Here my code so far and the result is attached as pdf:

cor.resp.log - na.omit(data.frame(log(SIGMA_STAT),p,log(SIGMA_MOB)))

panel.cor - function(x, y, digits=2, prefix=, cex.cor)
{
usr - par(usr); on.exit(par(usr))
par(usr = c(0, 1, 0, 1))
r - abs(cor(x, y))
txt - format(c(r, 0.123456789), digits=digits)[1]
txt - paste(prefix, txt, sep=)
if(missing(cex.cor)) cex - 0.5/strwidth(txt)

test - cor.test(x,y)
# borrowed from printCoefmat
Signif - symnum(test$p.value, corr = FALSE, na = FALSE,
cutpoints = c(0, 0.001, 0.01, 0.05, 0.1, 1),
symbols = c(***, **, *, .,  ))

text(0.5, 0.5, paste(txt,Signif), cex = 2)
}

#correlation pair plot
pairs.resp - pairs(cor.resp.log, 
labels=c(expression(paste('log(',sigma[stat],')')),p,expression(paste('log(',sigma[mob],')'))),lower.panel
 = function(...) panel.smooth(..., col.smooth=grey), upper.panel=panel.cor)

Thanks!

Best regards,
Johannes

-- 

Jetzt informieren: http://mobile.1und1.de/?ac=OM.PW.PW003K20328T7073a


cor_move_factors.pdf
Description: Adobe PDF document
__
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] Save/Load function()-result to file in a loop

2012-03-08 Thread Johannes Radinger
Hi,

I am looking for a way to save the result of a function, e.g the lm()-function 
to a file and reload it afterwards again. I'd like to do that in order to 
minimize the used memory when running the function in a loop. The actual 
function I want to store is the evaluate() from the dismo package.
I tried it with save() and load() but I am not sure if that is the way I should 
do it as I don't get the result I desire...

ls - list(A,B,C)
for(i in ls){
x - lm(c(1,2,3)~c(2,5,6))
save(x, file = paste(/path/to/file_,i,sep=))
}

A - load(/path/to/file_A)

/Johannes
-- 

Jetzt informieren: http://mobile.1und1.de/?ac=OM.PW.PW003K20328T7073a

__
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.


Re: [R] Save/Load function()-result to file in a loop

2012-03-08 Thread Johannes Radinger

 Original-Nachricht 
 Datum: Thu, 08 Mar 2012 09:51:01 -0500
 Von: Duncan Murdoch murdoch.dun...@gmail.com
 An: R. Michael Weylandt michael.weyla...@gmail.com
 CC: Johannes Radinger jradin...@gmx.at, R-help@r-project.org
 Betreff: Re: [R] Save/Load function()-result to file in a loop

 On 08/03/2012 8:42 AM, R. Michael Weylandt wrote:
  Load doesn't return the object you saved, but rather a character
  vector with the name of that object, here x. So you would do
  something like
 
  load(/path/to/file_A)
  x # Here's your data
 
  or more robustly
 
  get(load(/path/to/file_A))
 
  See ?load (value) for details.
 
 I think that's a bad idea:  it still wipes out any existing x in the 
 workspace.   Use saveRDS() and readRDS() instead.  For example,
 
 # Save the object, not its name
 i - A
 saveRDS(x, file =/path/to/file_A)
 
 # Load it into a new name
 A - loadRDS(/path/to/file_A)

Hi Duncan,
Thank for that good tip to use the RDS-functions.
Anyway I think you meant readRDS() instead of loadRDS().
I tried it out and it is working as I want it :)

/johannes

 
 Duncan Murdoch
 
  Michael
 
  On Thu, Mar 8, 2012 at 7:57 AM, Johannes Radingerjradin...@gmx.at 
 wrote:
Hi,
  
I am looking for a way to save the result of a function, e.g the
 lm()-function to a file and reload it afterwards again. I'd like to do that in
 order to minimize the used memory when running the function in a loop. The
 actual function I want to store is the evaluate() from the dismo package.
I tried it with save() and load() but I am not sure if that is the
 way I should do it as I don't get the result I desire...
  
ls- list(A,B,C)
for(i in ls){
x- lm(c(1,2,3)~c(2,5,6))
save(x, file = paste(/path/to/file_,i,sep=))
}
  
A- load(/path/to/file_A)
  
/Johannes
--
  
Jetzt informieren: http://mobile.1und1.de/?ac=OM.PW.PW003K20328T7073a
  
__
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-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.
 

-- 

Jetzt informieren: http://mobile.1und1.de/?ac=OM.PW.PW003K20328T7073a

__
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] Wildcard for indexing?

2012-02-14 Thread Johannes Radinger
Hi,

I'd like to know if it is possible to use wildcards * for indexing...
E.g. I have a vector of strings. Now I'd like to select all elements
which start with A_*? I'd also need to combine that with logical operators:

Select all elements of a vector that start with A (A*) OR that start with B 
(B*)

Probably that is quite easy. I looked into grep() which I think might perform 
such tasks, but probably there is a more straigth forward solution.

a - c(A_A,A_B,C_A,BB,A_Asd)
a[a==A_A| a==A_B] # here I'd like an index but with wildcard

/johannes
--

__
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.


Re: [R] Wildcard for indexing?

2012-02-14 Thread Johannes Radinger
Hi,

 Original-Nachricht 
 Datum: Tue, 14 Feb 2012 09:59:39 -0500
 Von: R. Michael Weylandt michael.weyla...@gmail.com
 An: Johannes Radinger jradin...@gmx.at
 CC: R-help@r-project.org
 Betreff: Re: [R] Wildcard for indexing?

 I think the grep()-family (regular expressions) will be the easiest
 way to do this, though it sounds like you might prefer grepl() which
 returns a logical vector:
 
 ^[AB] # Starts with either an A or a B
 ^A_ # Starting with A_
 
 a -  c(A_A,A_B,C_A,BB,A_Asd
 grepl(^[AB], a)
 grepl(^A_)

Yes grepl() is what I am looking for.
is there also something like an OR statement e.g. if I want to
select for elements that start with as OR df?

/johannes

 
 Michael
 
 On Tue, Feb 14, 2012 at 9:54 AM, Johannes Radinger jradin...@gmx.at
 wrote:
  Hi,
 
  I'd like to know if it is possible to use wildcards * for indexing...
  E.g. I have a vector of strings. Now I'd like to select all elements
  which start with A_*? I'd also need to combine that with logical
 operators:
 
  Select all elements of a vector that start with A (A*) OR that start
 with B (B*)
 
  Probably that is quite easy. I looked into grep() which I think might
 perform such tasks, but probably there is a more straigth forward solution.
 
  a - c(A_A,A_B,C_A,BB,A_Asd)
  a[a==A_A| a==A_B] # here I'd like an index but with wildcard
 
  /johannes
  --
 
  __
  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-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.


Re: [R] Wildcard for indexing?

2012-02-14 Thread Johannes Radinger


 Original-Nachricht 
 Datum: Tue, 14 Feb 2012 10:18:33 -0500
 Von: Sarah Goslee sarah.gos...@gmail.com
 An: Johannes Radinger jradin...@gmx.at
 CC: R-help@r-project.org
 Betreff: Re: [R] Wildcard for indexing?

 Hi,
 
 You should probably do a bit of reading about regular expressions, but
 here's one way:
 
 On Tue, Feb 14, 2012 at 10:10 AM, Johannes Radinger jradin...@gmx.at
 wrote:
  Hi,
 
   Original-Nachricht 
  Datum: Tue, 14 Feb 2012 09:59:39 -0500
  Von: R. Michael Weylandt michael.weyla...@gmail.com
  An: Johannes Radinger jradin...@gmx.at
  CC: R-help@r-project.org
  Betreff: Re: [R] Wildcard for indexing?
 
  I think the grep()-family (regular expressions) will be the easiest
  way to do this, though it sounds like you might prefer grepl() which
  returns a logical vector:
 
  ^[AB] # Starts with either an A or a B
  ^A_ # Starting with A_
 
  a -  c(A_A,A_B,C_A,BB,A_Asd
  grepl(^[AB], a)
  grepl(^A_)
 
  Yes grepl() is what I am looking for.
  is there also something like an OR statement e.g. if I want to
  select for elements that start with as OR df?
 
  a - c(as1, bb, as2, cc, df, aa, dd, sdf)
  grepl(^as|^df, a)
 [1]  TRUE FALSE  TRUE FALSE  TRUE FALSE FALSE FALSE
 
 
 The square brackets match any of those characters, so are good
 for single characters. For more complex patterns, | is the or symbol.
 ^ marks the beginning.

Thank you so much Sarah! I tried that | symbol intuitively, there was just a 
problem with the quotation marks :(

Now everything is solved...

/johannes

 
 Sarah
 
 -- 
 Sarah Goslee
 http://www.functionaldiversity.org

--

__
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] remove NAs from list collectively

2012-02-08 Thread Johannes Radinger
Hi,

I am importing dataframe from an Excel file (xlsx package).
The columns contain acutally measurements for single species and
the column-length is of variable. As it is imported as a dataframe the 
difference to the longest column is filled with NA.
To explain it with an example, my dataframe looks like:

A - seq(1:10)
B - c(seq(1:5),rep(NA,5))
C - c(seq(1:7),rep(NA,3))

df - data.frame(A,B,C)


Now I'd like to transform that to a list of vectors of different length. 
Therefore I need to remove the NAs collectively from the single columns...I 
tried for transforming:

as.list(df)

...but I don't know how can I remove the NAs now? as.list doesn't take 
na.rm=TRUE argument. Is there any ready function to perform such tasks?
Or is there a better way then to assign the data to a list of vectors with 
variable length?

/johannes
--

__
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.


Re: [R] remove NAs from list collectively

2012-02-08 Thread Johannes Radinger
Hi,

lapply(df, function (x) x[!is.na(x)])
thats is really great!

Thank you!

 Original-Nachricht 
 Datum: Wed, 08 Feb 2012 12:01:17 +0100
 Von: Dimitris Rizopoulos d.rizopou...@erasmusmc.nl
 An: Johannes Radinger jradin...@gmx.at
 CC: R-help@r-project.org
 Betreff: Re: [R] remove NAs from list collectively

 Two possibilities are:
 
 lapply(df, function (x) x[!is.na(x)])
 
 and
 
 lapply(df, na.exclude)
 
 
 I hope it helps.
 
 Best,
 Dimitris
 
 
 On 2/8/2012 11:54 AM, Johannes Radinger wrote:
  Hi,
 
  I am importing dataframe from an Excel file (xlsx package).
  The columns contain acutally measurements for single species and
  the column-length is of variable. As it is imported as a dataframe the
 difference to the longest column is filled with NA.
  To explain it with an example, my dataframe looks like:
 
  A- seq(1:10)
  B- c(seq(1:5),rep(NA,5))
  C- c(seq(1:7),rep(NA,3))
 
  df- data.frame(A,B,C)
 
 
  Now I'd like to transform that to a list of vectors of different length.
 Therefore I need to remove the NAs collectively from the single
 columns...I tried for transforming:
 
  as.list(df)
 
  ...but I don't know how can I remove the NAs now? as.list doesn't take
 na.rm=TRUE argument. Is there any ready function to perform such tasks?
  Or is there a better way then to assign the data to a list of vectors
 with variable length?
 
  /johannes
  --
 
  __
  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.
 
 
 -- 
 Dimitris Rizopoulos
 Assistant Professor
 Department of Biostatistics
 Erasmus University Medical Center
 
 Address: PO Box 2040, 3000 CA Rotterdam, the Netherlands
 Tel: +31/(0)10/7043478
 Fax: +31/(0)10/7043014
 Web: http://www.erasmusmc.nl/biostatistiek/

--

__
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] List to dataframe

2012-02-08 Thread Johannes Radinger
Hi,
I want to melt my list and get certain deskriptive factors (length of a 
vector etc.) into a dataframe. Best to describe it with an example:

A - seq(4)
B - seq(6)
C - seq(9)

ls - list(A,B,C) # this is my list with vectors of different length

# thats the dataframe how it should look like:
namelength(x)   length(x[x5])  length(x[x5])  
A   4   0   4
B   6   1   4
C   9   4   4

How can that be achieved?


/johannes
--

__
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.


Re: [R] List to dataframe

2012-02-08 Thread Johannes Radinger
Hi,

 Try
 
 list - list(1:4, 1:6, 1:9)
 t(sapply(list, function(x) c(length(x), sum(x  5), sum(x  5
 

thank you...the sapply approach seems straight forward, although I don't get 
the names into an own column... When the list elements are named the name is 
used for the rownames. I'd like to have them as an own column and no row 
names...

like for the list:
list - list(A=1:4, B=1:6, C=1:9)
t(sapply(list, function(x) c(length(x), sum(x  5), sum(x  5

/Johannes

 HTH,
 Jorge.-
 
 
 On Wed, Feb 8, 2012 at 8:50 AM, Johannes Radinger  wrote:
 
  Hi,
  I want to melt my list and get certain deskriptive factors (length of
 a
  vector etc.) into a dataframe. Best to describe it with an example:
 
  A - seq(4)
  B - seq(6)
  C - seq(9)
 
  ls - list(A,B,C) # this is my list with vectors of different length
 
  # thats the dataframe how it should look like:
  namelength(x)   length(x[x5])  length(x[x5])
  A   4   0   4
  B   6   1   4
  C   9   4   4
 
  How can that be achieved?
 
 
  /johannes
  --
 
  __
  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-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] Split dataframe into new dataframes

2012-02-08 Thread Johannes Radinger
Hi,

I want to split a dataframe based on a grouping variable (in one column). The 
resulting new
dataframes should be stored in a new variable. I tried to split the dataframe 
using split() and
to store it using a FOR loop, but thats not working so far:

df - data.frame(A=c(A1,A1,A2,A2),B=seq(1:4))

Fsplit - function(x,y){
ls - split(x,f=x$y)
for (i in names(ls)){
i - ls$i
}
}

Fsplit(df,A) #1st argument is dataframe to split, 2nd argument grouping variable
 

Any suggestions how to get that done?

Best regards
Johannes
[[alternative HTML version deleted]]

__
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.


Re: [R] Split dataframe into new dataframes

2012-02-08 Thread Johannes Radinger

Am 08.02.2012 um 22:19 schrieb David Winsemius:

 
 On Feb 8, 2012, at 4:11 PM, Johannes Radinger wrote:
 
 Hi,
 
 I want to split a dataframe based on a grouping variable (in one column). 
 The resulting new
 dataframes should be stored in a new variable. I tried to split the 
 dataframe using split() and
 to store it using a FOR loop, but thats not working so far:
 
 df - data.frame(A=c(A1,A1,A2,A2),B=seq(1:4))
 
 Fsplit - function(x,y){
  ls - split(x,f=x$y)
  for (i in names(ls)){
  i - ls$i
  }
 }
 
 Fsplit(df,A) #1st argument is dataframe to split, 2nd argument grouping 
 variable
 
 
 It appears you want the name of the levels of df$A to be the names of 
 separate variables in the global environment. If that is correct, then see 
 the FAQ. I'm not sure which one it is among the Miscellaneous section, but 
 you should be looking of the one that tells you how to construct a named 
 variable.
 

Your hint with the global environment brought me on track. It seems that I this 
task can be done with list2env() although there is still a problem with my 
function. How
can I parse the name of the dataframe and the column name in the function...

df - data.frame(A=c(A1,A1,A2,A2),B=seq(1:4))

Fsplit - function(x,y){
ls - split(x,f=x$y)
list2env(ls,envir = .GlobalEnv)
}

Fsplit(df,A)

/johannes

 Or:
 
 ? assign
 
 -- 
 David Winsemius, MD
 West Hartford, CT
 


[[alternative HTML version deleted]]

__
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.


Re: [R] Split dataframe into new dataframes

2012-02-08 Thread Johannes Radinger

Am 08.02.2012 um 23:47 schrieb David Winsemius:

 
 On Feb 8, 2012, at 5:06 PM, Johannes Radinger wrote:
 
 
 Am 08.02.2012 um 22:19 schrieb David Winsemius:
 
 
 On Feb 8, 2012, at 4:11 PM, Johannes Radinger wrote:
 
 Hi,
 
 I want to split a dataframe based on a grouping variable (in one column). 
 The resulting new
 dataframes should be stored in a new variable. I tried to split the 
 dataframe using split() and
 to store it using a FOR loop, but thats not working so far:
 
 df - data.frame(A=c(A1,A1,A2,A2),B=seq(1:4))
 
 Fsplit - function(x,y){
ls - split(x,f=x$y)
for (i in names(ls)){
i - ls$i
}
 }
 
 Fsplit(df,A) #1st argument is dataframe to split, 2nd argument grouping 
 variable
 
 
 It appears you want the name of the levels of df$A to be the names of 
 separate variables in the global environment. If that is correct, then see 
 the FAQ. I'm not sure which one it is among the Miscellaneous section, but 
 you should be looking of the one that tells you how to construct a named 
 variable.
 
 
 Your hint with the global environment brought me on track. It seems that I 
 this task can be done with list2env() although there is still a problem with 
 my function. How
 can I parse the name of the dataframe and the column name in the function...
 
 df - data.frame(A=c(A1,A1,A2,A2),B=seq(1:4))
 
 Fsplit - function(x,y){
  ls - split(x,f=x$y)
  list2env(ls,envir = .GlobalEnv)
 }
 
 Fsplit(df,A)
 
 I still have not figured out what you really want to do. The simple answer to 
 what you ask for in your written request is simply:
 
 dfvar - split(df, df$A)
 
 So what is it about that result that is not useful for your (as yet unstated) 
  destination?
 
  split(df, df$A)
 $A1
A B
 1 A1 1
 2 A1 2
 
 $A2
A B
 3 A2 3
 4 A2 4
 
 

Sorry for not being clear enough, and your are
right as split(df, df$A) is what I want. Additionally I want to store 
afterwards
the single objects of the list in new dataframes 
where variable name = name of list object (which can be done with list2env()).
Is that clear enough so far?

What I want exactly is to express that two operations (split, list2env) within
one function. I need the function for other tasks in R.

/johannes

 
 
 
 
 /johannes
 
 Or:
 
 ? assign
 
 -- 
 David Winsemius, MD
 West Hartford, CT
 
 
 
 David Winsemius, MD
 West Hartford, CT
 


[[alternative HTML version deleted]]

__
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] Assigning objects to variable and variable to list in a for loop

2012-02-03 Thread Johannes Radinger
Hello,

I want to use a for loop for repeadely calculating
a maxent model (package dismo, function maxent()) which
creates an object of the class maxent (S4).
I want to collect all the resulting object in a list.

I tried to simplify my for loop to explain what I want.
There are two problems/questions:
1) How can I create the new variables in the loop (using paste) and assign the 
objects
2) How can I collect the results (objects) in a list

X - factor(c(A,B,C))

for(in in X){
as.name(paste(result,X,sep=_)) - runif(5) #any object
# create list of objects with names
}

I read something about assign(), but that assigns a value and not an object to 
a variable. Some time ago I did something similar but with a matrix: Thus I 
created an empty matrix before the loop and indexed the matrix inside the loop 
to assign values. But here it is about assigning ojects to variables and 
coercing these to a list.

Any suggestions are mostly welcomme.

Thank you,

best regards,
Johannes Radinger
--

__
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.


Re: [R] Assigning objects to variable and variable to list in a for loop

2012-02-03 Thread Johannes Radinger
Hello,

I tried to use the lapply approach, but I am not sure how to 
se it correctly for my task. Here I just want to give an short
script which explains how my data structure looks like. It also
contains the second approach with a for loop which is working but
there is the question of how assining the result to a list.

I think the script is somehow self explaining. Anyway what is called
res is in reality rather an object (maxent) than a single value (thats why I 
need the list)

#create data
cat - c(A,A,B,C,C)
value - runif(5)
df - data.frame(cat,value)

# get names of cat with more than 1 entries
select.cat - names(table(df$cat)[table(df$cat)1])
cat.list - as.list(select.cat)

## lapply approach 
fun = function(x){
sub.df- subset(df,cat ==  x)
# here are other operations, result is an object
res - sub.df
res #here just a single value but in the long script it is an object
}   
reslist - lapply(cat.list, fun(unlist(cat.list)))

## For loop approach 
for(i in select.cat){
sub.df- subset(df,cat ==  i)
res - sub.df
print(res) #here just a single value but in the long script it is an 
object
#Now I have to collect the results in a list
}

# My task is to do run a function on different parts
#of a dataframe. This dataframe is subdivided with subset on
#one variable.


Thank you very much,

best regards,

Johannes

 Original-Nachricht 
 Datum: Fri, 3 Feb 2012 02:22:30 -0800
 Von: Joshua Wiley jwiley.ps...@gmail.com
 An: Johannes Radinger jradin...@gmx.at
 CC: r-help@r-project.org
 Betreff: Re: [R] Assigning objects to variable and variable to list in a for 
 loop

 Hi Johannes,
 
 There is a relatively elegant solution if you assign in a list:
 
 reslist - lapply(1:3, function(x) runif(5))
 names(reslist) - paste(result, LETTERS[1:3], sep = _)
 
 Cheers,
 
 Josh
 
 On Fri, Feb 3, 2012 at 2:07 AM, Johannes Radinger jradin...@gmx.at
 wrote:
  Hello,
 
  I want to use a for loop for repeadely calculating
  a maxent model (package dismo, function maxent()) which
  creates an object of the class maxent (S4).
  I want to collect all the resulting object in a list.
 
  I tried to simplify my for loop to explain what I want.
  There are two problems/questions:
  1) How can I create the new variables in the loop (using paste) and
 assign the objects
  2) How can I collect the results (objects) in a list
 
  X - factor(c(A,B,C))
 
  for(in in X){
         as.name(paste(result,X,sep=_)) - runif(5) #any object
         # create list of objects with names
         }
 
  I read something about assign(), but that assigns a value and not an
 object to a variable. Some time ago I did something similar but with a matrix:
 Thus I created an empty matrix before the loop and indexed the matrix
 inside the loop to assign values. But here it is about assigning ojects to
 variables and coercing these to a list.
 
  Any suggestions are mostly welcomme.
 
  Thank you,
 
  best regards,
  Johannes Radinger
  --
 
  __
  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.
 
 
 
 -- 
 Joshua Wiley
 Ph.D. Student, Health Psychology
 Programmer Analyst II, Statistical Consulting Group
 University of California, Los Angeles
 https://joshuawiley.com/

--

__
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.


Re: [R] Assigning objects to variable and variable to list in a for loop

2012-02-03 Thread Johannes Radinger
hi,

 Original-Nachricht 
 Datum: Fri, 3 Feb 2012 09:04:19 -0500
 Von: Steve Lianoglou mailinglist.honey...@gmail.com
 An: Johannes Radinger jradin...@gmx.at
 CC: Joshua Wiley jwiley.ps...@gmail.com, r-help@r-project.org
 Betreff: Re: [R] Assigning objects to variable and variable to list in a for 
 loop

 Hi,
 
 On Fri, Feb 3, 2012 at 8:00 AM, Johannes Radinger jradin...@gmx.at
 wrote:
  Hello,
 
  I tried to use the lapply approach, but I am not sure how to
  se it correctly for my task. Here I just want to give an short
  script which explains how my data structure looks like. It also
  contains the second approach with a for loop which is working but
  there is the question of how assining the result to a list.
 
  I think the script is somehow self explaining. Anyway what is called
  res is in reality rather an object (maxent) than a single value (thats
 why I need the list)
 
  #create data
  cat - c(A,A,B,C,C)
  value - runif(5)
  df - data.frame(cat,value)
 
  # get names of cat with more than 1 entries
  select.cat - names(table(df$cat)[table(df$cat)1])
  cat.list - as.list(select.cat)
 
  ## lapply approach 
  fun = function(x){
         sub.df- subset(df,cat ==  x)
         # here are other operations, result is an object
         res - sub.df
         res #here just a single value but in the long script it is an
 object
         }
  reslist - lapply(cat.list, fun(unlist(cat.list)))
 
 I think you may need to thumb through the ?lapply documentation a bit
 more. lapply will feed ever element in the list you are iterating over
 into the first argument of the function you have in lapply's second
 argument, so you would rather have something like:
 
 reslist - lapply(cat.list, fun)

Thank you! Thats it...fun doesn't need any argument to be specified as it is 
autmatically feed in as you said..

/johannes

 
 Assuming that `fun` only needs one element from cat.list to do its duty
 ...
 
 -steve
 
 -- 
 Steve Lianoglou
 Graduate Student: Computational Systems Biology
  | Memorial Sloan-Kettering Cancer Center
  | Weill Medical College of Cornell University
 Contact Info: http://cbio.mskcc.org/~lianos/contact

--

__
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.


Re: [R] reshape dataframe to array (pivot table)

2012-01-25 Thread Johannes Radinger
Hi Rainer,

thank you for your response.
The combination of melt/cast was what I was looking for.
Now, also the reshape-package and its advantage is a lot clearer
to me.

cheers,
johannes
 Original-Nachricht 
 Datum: Tue, 24 Jan 2012 19:28:43 +0100
 Von: Rainer Schuermann rainer.schuerm...@gmx.net
 An: Johannes Radinger jradin...@gmx.at
 CC: r-help@r-project.org r-help@r-project.org
 Betreff: Re: [R] reshape dataframe to array (pivot table)

 Hi,
 
 I wouldn't know how to fill the data into the array form you want, but 
 you can get the aggregated data with
 
 dfm - melt( df )
 dfc - cast( dfm, LOC ~ variable, sum )
   dfc
LOC SPEC1 SPEC2
 1   123 5
 2   223 2
 3   3 0 0
 
 Hope this helps as a first step!
 
 Rgds,
 Rainer
 
 
 On 2012-01-24 17:15, Johannes Radinger wrote:
  Hello,
 
  I would like to reshape a dataframe into an array. This is kind a
 similar task as Excel performs with a Pivot table. To illustrate it:
 
  LOC- factor(c(1,2,2,3,1,1))
  SPEC1- c(0,0,23,0,12,11)
  SPEC2- c(1,2,0,0,0,4)
 
  df- data.frame(LOC,SPEC1,SPEC2) # original dataframe
 
  a-
 array(NA,dim=c(length(levels(LOC)),1,2),dimnames=list(levels(LOC),LOC,c(SPEC1,SPEC2)))
  #new array set up, how it should look like
 
  The final array is splitted by the SPEC (for each SPEC an new layer),
 and
  the LOC is collapsed so that there is only one line per level of LOC.
  The array should get populated with:
  1) the sums
  2) and presence/absence (can be easily calculated from sums)
 
  What is the best way to do that? I looked into reshape and
 apply...probably one of them is suitable but I don't know how...Or has that 
 to be done
 with a loop?
 
  cheers,
  /johannes

-- 
Feel free - 10 GB Mailbox, 100 FreeSMS/Monat ...

__
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] x11() graphic device, displaying raster

2012-01-25 Thread Johannes Radinger
Hello,

I am wondering about the X11() graphic device on Windows. 
I try to plot a raster image but nothing gets displayed. I
found some pages where it is mentioned that x11() not
always supports raster rendering.
Is there any add on for x11, any update or any R-package
which solves that displaying problem in Windows?

What I try to test it is an example from the
package {raster}:

library(raster)
DEU_alt - getData(alt, country=DEU, mask=TRUE)
x11()
plot(DEU_alt,axes=TRUE)

best regards,

/johannes
-- 
Feel free - 10 GB Mailbox, 100 FreeSMS/Monat ...

__
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.


Re: [R] x11() graphic device, displaying raster

2012-01-25 Thread Johannes Radinger

 
 On 25.01.2012 12:45, Johannes Radinger wrote:
  Hello,
 
  I am wondering about the X11() graphic device on Windows.
  I try to plot a raster image but nothing gets displayed. I
  found some pages where it is mentioned that x11() not
  always supports raster rendering.
  Is there any add on for x11, any update or any R-package
  which solves that displaying problem in Windows?
 
  What I try to test it is an example from the
  package {raster}:
 
  library(raster)
  DEU_alt- getData(alt, country=DEU, mask=TRUE)
  x11()
  plot(DEU_alt,axes=TRUE)
 
  best regards,
 
  /johannes
 
 Try an R version that is recent - it works for me.
 
 Uwe Ligges

I first tried it with R 2.13.2 and raster version 1.9-64 (16-January-2012).
Now I also installed the most recent version R 2.14.1 (Platform: 
i386-pc-mingw32/i386 (32-bit)) and raster version 1.9-64 (16-January-2012).

But in both cases no success. X11() opens and draws the axis and the
border for the scale but no raster...

There is no problem with vector graphics...like:
DEU_border - getData(GADM, country=DEU, level=1)
plot(DEU_border,axes=TRUE)

Any suggestions what is going on resp. how to solve it...?

/johannes


-- 
Feel free - 10 GB Mailbox, 100 FreeSMS/Monat ...

__
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.


Re: [R] x11() graphic device, displaying raster

2012-01-25 Thread Johannes Radinger

 
 On 25.01.2012 13:42, Johannes Radinger wrote:
 
 
  On 25.01.2012 12:45, Johannes Radinger wrote:
  Hello,
 
  I am wondering about the X11() graphic device on Windows.
  I try to plot a raster image but nothing gets displayed. I
  found some pages where it is mentioned that x11() not
  always supports raster rendering.
  Is there any add on for x11, any update or any R-package
  which solves that displaying problem in Windows?
 
  What I try to test it is an example from the
  package {raster}:
 
  library(raster)
  DEU_alt- getData(alt, country=DEU, mask=TRUE)
  x11()
  plot(DEU_alt,axes=TRUE)
 
  best regards,
 
  /johannes
 
  Try an R version that is recent - it works for me.
 
  Uwe Ligges
 
  I first tried it with R 2.13.2 and raster version 1.9-64
 (16-January-2012).
  Now I also installed the most recent version R 2.14.1 (Platform:
 i386-pc-mingw32/i386 (32-bit)) and raster version 1.9-64 (16-January-2012).
 
  But in both cases no success. X11() opens and draws the axis and the
  border for the scale but no raster...
 
 I do not really understand why you are using x11(). The Windows device 
 is called windows() and you actually do not need to open it, since plot 
 opens it anyway. Or are you under cygwin (which is not really Windows)?
 If not: Which version of Windows is this?

Of course I do not need to open a graphic device (as you said it is open when 
calling plot). I just wanted to make it reproducable as e.g. Mac OS X opens 
Quartz as a standard device when calling plot on my Mac machine.

So far as I understand the help are all the devices (X11(), x11() and 
windows() implemented as variants of the same device. Thus it makes no 
difference if I call x11() or windows() or if 'plot' opens the device 
automatically. In all cases there is no raster displayed.

Just some additional information from the 'grDevices' package:
 library(grDevices)
 dev.capabilities()
$semiTransparency
[1] TRUE

$transparentBackground
[1] fully

$rasterImage
[1] yes

$capture
[1] TRUE

$locator
[1] TRUE

$events
[1] MouseDown MouseMove MouseUp   Keybd  

I am running R via the standard RGUI (so no Eclipse, Rtinn etc.). The machine I 
am working on is Windows 2008 Server Enterprise (Version 6.0) which I am 
remotely accessing from a ThinClient with WindowsXP-embedded.
This is the standard configuration of our institution. Maybe that configuration 
with ThinClients is a reason? But what should I ask our admin? What should he 
check etc?

best regards,
johannes



 
 Uwe Ligges
 
 
  There is no problem with vector graphics...like:
  DEU_border- getData(GADM, country=DEU, level=1)
  plot(DEU_border,axes=TRUE)
 
  Any suggestions what is going on resp. how to solve it...?
 
  /johannes
 
 

-- 
Feel free - 10 GB Mailbox, 100 FreeSMS/Monat ...

__
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] reshape dataframe to array (pivot table)

2012-01-24 Thread Johannes Radinger
Hello,

I would like to reshape a dataframe into an array. This is kind a similar task 
as Excel performs with a Pivot table. To illustrate it:

LOC - factor(c(1,2,2,3,1,1))
SPEC1 - c(0,0,23,0,12,11)
SPEC2 - c(1,2,0,0,0,4)

df - data.frame(LOC,SPEC1,SPEC2) # original dataframe

a - 
array(NA,dim=c(length(levels(LOC)),1,2),dimnames=list(levels(LOC),LOC,c(SPEC1,SPEC2)))
 #new array set up, how it should look like

The final array is splitted by the SPEC (for each SPEC an new layer), and
the LOC is collapsed so that there is only one line per level of LOC.
The array should get populated with:
1) the sums
2) and presence/absence (can be easily calculated from sums)

What is the best way to do that? I looked into reshape and apply...probably one 
of them is suitable but I don't know how...Or has that to be done with a loop?

cheers,
/johannes
-- 
Feel free - 10 GB Mailbox, 100 FreeSMS/Monat ...

__
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] test if text is part of vector

2012-01-20 Thread Johannes Radinger
Hello,

this is a very simple question:
How can I find out if a word is part of a list of words

like:
a - word1
b - word4

vector - c(word1,word2,word3)

I tried it with match(a,vector)
but this gives the position of the word.

I am not sure if and how that can be
done with a logical operator like if:
IF text is part of vector THEN print is part

Probably a very easy thing to do, but I am missing
the logical operator... and help(if) is not working

best regards,
johannes
-- 
Feel free - 10 GB Mailbox, 100 FreeSMS/Monat ...

__
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.


Re: [R] test if text is part of vector

2012-01-20 Thread Johannes Radinger
Hi,

thank you very much... %in% is the operator I was looking for.

cheers,
johannes

 Original-Nachricht 
 Datum: Fri, 20 Jan 2012 13:01:54 +0100
 Von: Rainer M Krug r.m.k...@gmail.com
 An: Johannes Radinger jradin...@gmx.at
 CC: R-help@r-project.org
 Betreff: Re: [R] test if text is part of vector

 -BEGIN PGP SIGNED MESSAGE-
 Hash: SHA1
 
 On 20/01/12 12:50, Johannes Radinger wrote:
  Hello,
  
  this is a very simple question: How can I find out if a word is
  part of a list of words
  
  like: a - word1 b - word4
  
  vector - c(word1,word2,word3)
  
  I tried it with match(a,vector) but this gives the position of the
  word.
  
  I am not sure if and how that can be done with a logical operator
  like if: IF text is part of vector THEN print is part
  
  Probably a very easy thing to do, but I am missing the logical
  operator... and help(if) is not working
 
 check out %in%
 
 help:
 
 ?%in%
 
 Cheers,
 
 Rainer
 
  
  best regards, johannes
 
 
 - -- 
 Rainer M. Krug, PhD (Conservation Ecology, SUN), MSc (Conservation
 Biology, UCT), Dipl. Phys. (Germany)
 
 Centre of Excellence for Invasion Biology
 Stellenbosch University
 South Africa
 
 Tel :   +33 - (0)9 53 10 27 44
 Cell:   +33 - (0)6 85 62 59 98
 Fax :   +33 - (0)9 58 10 27 44
 
 Fax (D):+49 - (0)3 21 21 25 22 44
 
 email:  rai...@krugs.de
 
 Skype:  RMkrug
 -BEGIN PGP SIGNATURE-
 Version: GnuPG v1.4.11 (GNU/Linux)
 Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org/
 
 iEYEARECAAYFAk8ZV7IACgkQoYgNqgF2egroawCfYAN/eOBMKN4VDTbBZtiBVGdS
 LAUAnR+h9kg2INJTICiGIAUTfYm2fCbC
 =Ws2h
 -END PGP SIGNATURE-

-- 
Feel free - 10 GB Mailbox, 100 FreeSMS/Monat ...

__
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.


Re: [R] Split values in vector

2012-01-20 Thread Johannes Radinger
Hello all,

I think I am now on the way to correctly split the vector as I want it
using for loops.
I got now to a point where I got stuckedSo maybe someone can help
me out...

Remember the result I am looking for should look like (for
the input vector I want to split see below: var3)

var1  var2  var3_00   var3_01   var3_02   var3_04
1 A 1 0 0 0
2 B 0 1 3 1
3 C 0 2 1 0
4 D 0 0 0 12
5 E NANANANA

The input and my approach so far:
It is probably not the most elegant solution but I think I will get
where I want..I am very open for your improvements:

var1 -seq(1,5)
var2 -c(A,B,C,D,E)
var3 -c(00,01-1;02-3;04-1,01-2;02-1,01-0;04-2,NA)

x - data.frame(var1,var2,var3)

#create new columns and prefill with 0
x$var3_01 - 0
x$var3_02 - 0
x$var3_03 - 0
x$var3_04 - 0

a - strsplit(as.character(x$var3), split = ;, fixed = TRUE)

for (i in 1:length(a)){
A - length(a[[i]])
for (j in 1:A){
column - (unlist(strsplit((a[[i]][j]), 
split=-,fixed=TRUE))[1])
if(column!=00){
value - (unlist(strsplit((a[[i]][j]), 
split=-,fixed=TRUE))[2])
print(column)
print(value)
if(is.na(column)) {
x$var3_01[i] - NA
x$var3_02[i] - NA
x$var3_03[i] - NA
x$var3_04[i] - NA
} else
if(column %in% c(01,02,03,04)) {
#print(paste(x$var3_,column,sep=))
(paste(x$var3_,column,sep=))[i]- 
as.numeric(value)
} else print(Problem with category)
}
}
}

I think there is a problme with (paste(x$var3_,column,sep=))[i]
which is not recognized correctly as it is interpreted as a string.

Thank you...

best regards,

/johannes



 Original-Nachricht 
 Datum: Thu, 19 Jan 2012 13:42:24 +0100 (MET)
 Von: Gerrit Eichner gerrit.eich...@math.uni-giessen.de
 An: Johannes Radinger jradin...@gmx.at
 CC: R-help@r-project.org
 Betreff: Re: [R] Split values in vector

 Hi, Johannes,
 
 maybe
 
 X - unlist( strsplit( as.character( x$ART), split = ;, fixed = TRUE))
 X - strsplit( X, split = -, fixed = TRUE)
 
 X - sapply( X, function( x)
   if( length(x) == 2)
rep( x[1], as.numeric( x[2])) else x[1]
  )
 
 table(X, useNA = always)
 
 
 comes close to what you want.
 
   Hth  --  Gerrit
 
 
 On Thu, 19 Jan 2012, Johannes Radinger wrote:
 
  Hello,
 
  I have a vector which looks like
 
  x$ART
  ...
 
  [35415] 0001-1;02-1;05-1;
  [35417] 01-1; 01-1;02-1;
  [35419] 01-1; 00
  [35421] 01-1;04-1;05-1;
  [35423] 02-1; 01-1;02-1;
  [35425] 01-1;02-1;NA
  [35427] 01-1; NA
  ...
 
 
  This is a vector I got in this format. To explain it:
  there are several categories (00,01,02 etc) and its counts (values after
 -)
  So I have to split each value and create new dataframe-columns/vectors
  for each categories one column and the value should be then in the
  corresponding cell. I know that this vector has 7 categories (00-06)
  and NA values but each case (row) has not all the categories (as you can
 see).  How can do such as split?
 
  In the end I should get:
  x$ART_00, x$ART_01, x$ART_03,... with its values. In the case of NA
 all the categories should have also NA.
 
  Maybe someone can help.
 
  Thank you,
 
  Best regards
 
  Johannes
 
 
 
  -- 
  Feel free - 10 GB Mailbox, 100 FreeSMS/Monat ...
 
  __
  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.

-- 
Feel free - 10 GB Mailbox, 100 FreeSMS/Monat ...

__
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.


Re: [R] Split values in vector

2012-01-20 Thread Johannes Radinger
Hello again,

No I managed to do everything correctly...

the code now looks like:

var1 -seq(1,5)
var2 -c(A,B,C,D,E)
var3 -c(00,01-1;02-3;04-1,01-2;02-1,01-0;04-2,NA)

x - data.frame(var1,var2,var3)

#create new columns and prefill with 0
x$var3_01 - 0
x$var3_02 - 0
x$var3_03 - 0
x$var3_04 - 0

a - strsplit(as.character(x$var3), split = ;, fixed = TRUE)

for (i in 1:length(a)){
A - length(a[[i]])
for (j in 1:A){
column - (unlist(strsplit((a[[i]][j]), 
split=-,fixed=TRUE))[1])
if(column!=00|is.na(column)){
value - (unlist(strsplit((a[[i]][j]), 
split=-,fixed=TRUE))[2])
if(is.na(column)) {
x$var3_01[i] - NA
x$var3_02[i] - NA
x$var3_03[i] - NA
x$var3_04[i] - NA
} else
if(column %in% c(01,02,03,04)) {
x[i,paste(var3_,column,sep=)]- 
as.numeric(value)
} else print(Problem with category)
}
}
}




 Original-Nachricht 
 Datum: Thu, 19 Jan 2012 13:42:24 +0100 (MET)
 Von: Gerrit Eichner gerrit.eich...@math.uni-giessen.de
 An: Johannes Radinger jradin...@gmx.at
 CC: R-help@r-project.org
 Betreff: Re: [R] Split values in vector

 Hi, Johannes,
 
 maybe
 
 X - unlist( strsplit( as.character( x$ART), split = ;, fixed = TRUE))
 X - strsplit( X, split = -, fixed = TRUE)
 
 X - sapply( X, function( x)
   if( length(x) == 2)
rep( x[1], as.numeric( x[2])) else x[1]
  )
 
 table(X, useNA = always)
 
 
 comes close to what you want.
 
   Hth  --  Gerrit
 
 
 On Thu, 19 Jan 2012, Johannes Radinger wrote:
 
  Hello,
 
  I have a vector which looks like
 
  x$ART
  ...
 
  [35415] 0001-1;02-1;05-1;
  [35417] 01-1; 01-1;02-1;
  [35419] 01-1; 00
  [35421] 01-1;04-1;05-1;
  [35423] 02-1; 01-1;02-1;
  [35425] 01-1;02-1;NA
  [35427] 01-1; NA
  ...
 
 
  This is a vector I got in this format. To explain it:
  there are several categories (00,01,02 etc) and its counts (values after
 -)
  So I have to split each value and create new dataframe-columns/vectors
  for each categories one column and the value should be then in the
  corresponding cell. I know that this vector has 7 categories (00-06)
  and NA values but each case (row) has not all the categories (as you can
 see).  How can do such as split?
 
  In the end I should get:
  x$ART_00, x$ART_01, x$ART_03,... with its values. In the case of NA
 all the categories should have also NA.
 
  Maybe someone can help.
 
  Thank you,
 
  Best regards
 
  Johannes
 
 
 
  -- 
  Feel free - 10 GB Mailbox, 100 FreeSMS/Monat ...
 
  __
  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.

-- 
Feel free - 10 GB Mailbox, 100 FreeSMS/Monat ...



-- 
Feel free - 10 GB Mailbox, 100 FreeSMS/Monat ...

__
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] Split values in vector

2012-01-19 Thread Johannes Radinger
Hello,

I have a vector which looks like

x$ART
...
[35415] 0001-1;02-1;05-1;  
[35417] 01-1; 01-1;02-1;   
[35419] 01-1; 00   
[35421] 01-1;04-1;05-1;
[35423] 02-1; 01-1;02-1;   
[35425] 01-1;02-1;NA 
[35427] 01-1; NA
...


This is a vector I got in this format. To explain it:
there are several categories (00,01,02 etc) and its counts (values after -)
So I have to split each value and create new dataframe-columns/vectors
for each categories one column and the value should be then in the
corresponding cell. I know that this vector has 7 categories (00-06)
and NA values but each case (row) has not all the categories (as you can see).  
How can do such as split?

In the end I should get:
x$ART_00, x$ART_01, x$ART_03,... with its values. In the case of NA all the 
categories should have also NA.

Maybe someone can help.

Thank you,

Best regards

Johannes



-- 
Feel free - 10 GB Mailbox, 100 FreeSMS/Monat ...

__
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.


Re: [R] Split values in vector

2012-01-19 Thread Johannes Radinger
Hi,

just for explaining it a little bit furhter
here a small sample dataframe (similar to that
I am working with).


var1 -seq(1,5)
var2 -c(A,B,C,D,E)
var3 -c(00,01-1;02-3;04-1,01-2;02-1,01-0;04-12,NA)

x - data.frame(var1,var2,var3)

The final dataframe should look like:
When there is the category 00 then the column 00 should
be 1 and all others 0. The other values should be according
to the input and when the category is not stated then the value
is 0. Sounds probably a little bit confusing but hopefully
the example makes it easier to understand.

var1  var2  var3_00   var3_01   var3_02   var3_04
1 A 1 0 0 0
2 B 0 1 3 1
3 C 0 2 1 0
4 D 0 0 0 12
5 E NANANANA


When I try it with the recommended approach I get an error
when I want it executes table() and I am not sure if I will
get exactly the result I want.

X - unlist(strsplit(as.character(x$var3), split = ;, fixed = TRUE))
X - strsplit( X, split = -, fixed = TRUE)

X - sapply( X, function( x)
if( length(x) == 2)
rep( x[1], as.numeric( x[2])) else x[1]
)

table(X, useNA = always)

Thank you for you help, I really don't know how this can be handled

best regards,
johannes


 Original-Nachricht 
 Datum: Thu, 19 Jan 2012 13:42:24 +0100 (MET)
 Von: Gerrit Eichner gerrit.eich...@math.uni-giessen.de
 An: Johannes Radinger jradin...@gmx.at
 CC: R-help@r-project.org
 Betreff: Re: [R] Split values in vector

 Hi, Johannes,
 
 maybe
 
 X - unlist( strsplit( as.character( x$ART), split = ;, fixed = TRUE))
 X - strsplit( X, split = -, fixed = TRUE)
 
 X - sapply( X, function( x)
   if( length(x) == 2)
rep( x[1], as.numeric( x[2])) else x[1]
  )
 
 table(X, useNA = always)
 
 
 comes close to what you want.
 
   Hth  --  Gerrit
 
 
 On Thu, 19 Jan 2012, Johannes Radinger wrote:
 
  Hello,
 
  I have a vector which looks like
 
  x$ART
  ...
 
  [35415] 0001-1;02-1;05-1;
  [35417] 01-1; 01-1;02-1;
  [35419] 01-1; 00
  [35421] 01-1;04-1;05-1;
  [35423] 02-1; 01-1;02-1;
  [35425] 01-1;02-1;NA
  [35427] 01-1; NA
  ...
 
 
  This is a vector I got in this format. To explain it:
  there are several categories (00,01,02 etc) and its counts (values after
 -)
  So I have to split each value and create new dataframe-columns/vectors
  for each categories one column and the value should be then in the
  corresponding cell. I know that this vector has 7 categories (00-06)
  and NA values but each case (row) has not all the categories (as you can
 see).  How can do such as split?
 
  In the end I should get:
  x$ART_00, x$ART_01, x$ART_03,... with its values. In the case of NA
 all the categories should have also NA.
 
  Maybe someone can help.
 
  Thank you,
 
  Best regards
 
  Johannes
 
 
 
  -- 
  Feel free - 10 GB Mailbox, 100 FreeSMS/Monat ...
 
  __
  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.

-- 
Feel free - 10 GB Mailbox, 100 FreeSMS/Monat ...

__
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.


Re: [R] multidimensional array calculation

2012-01-14 Thread Johannes Radinger
Dear Jean,

Thank you, expand.grid was the function I needed.

/johannes


 
 See 
 ?expand.grid 
 
 For example, 
 df - expand.grid(L=L, AR=AR, SO=SO, T=T) 
 df$y - fun(df$L, df$AR, df$SO, df$T) 
 
 Jean 
 
 
 Johannes Radinger wrote on 01/13/2012 12:28:46 PM:
 
  Hello,
  
  probably it is quite easy but I can get it: I have
  mulitple numeric vectors and a function using
  all of them to calculate a new value:
  
  L - c(200,400,600)
  AR - c(1.5)
  SO - c(1,3,5)
  T - c(30,365)
  
  fun - function(L,AR,SO,T){
 exp(L*AR+sqrt(SO)*log(T))
  }
  
  How can I get an array or dataframe where
  all possible combinations of the factors are listed
  and the new value is calculated.
  
  I thought about an array like:
  array(NA, dim = c(3,1,3,2), dimnames=list(c(200,400,600),c(1.5),c(1,
  3,5),c(30,365)))
  
  but how can I get the array populated according to the function?
  
  As I want to get in the end a 2D dataframe I probably will use the 
  melt.array()
  function from the reshape package or is there another way to get simple such
  a full-factorial dataframe with all possible combinations?
  
  Best regards,
  Johannes


[[alternative HTML version deleted]]

__
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] multidimensional array calculation

2012-01-13 Thread Johannes Radinger
Hello,

probably it is quite easy but I can get it: I have
mulitple numeric vectors and a function using
all of them to calculate a new value:

L - c(200,400,600)
AR - c(1.5)
SO - c(1,3,5)
T - c(30,365)

fun - function(L,AR,SO,T){
exp(L*AR+sqrt(SO)*log(T))
}

How can I get an array or dataframe where
all possible combinations of the factors are listed
and the new value is calculated.

I thought about an array like:
array(NA, dim = c(3,1,3,2), 
dimnames=list(c(200,400,600),c(1.5),c(1,3,5),c(30,365)))

but how can I get the array populated according to the function?

As I want to get in the end a 2D dataframe I probably will use the melt.array()
function from the reshape package or is there another way to get simple such
a full-factorial dataframe with all possible combinations?

Best regards,
Johannes
__
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] summary per group

2012-01-02 Thread Johannes Radinger
Hello,

I know that it'll be quite easy to do what I want but somehow I am lost as I am 
new to R. I want to get summary results arranged by groups. In detail
I'd like get the number (levels) of Species per Family like for this dataset:

SPEC - factor(c(a,a,b,b,c,c,c,d,e,e,e,e))
FAM - factor(c(A,A,A,A,B,B,B,C,C,C,C,C))
df - data.frame(SPEC,FAM)

I tried tapply(SPEC, FAM, nlevels).. but it is not the result I am looking 
for...

What is the easiest way to do that? Do I have to rearrange the dataset?

Best regards and Happy New Year!

Johannes

--

__
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.


Re: [R] summary per group

2012-01-02 Thread Johannes Radinger


 Original-Nachricht 
 Datum: Mon, 2 Jan 2012 14:29:07 +0100
 Von: Petr PIKAL petr.pi...@precheza.cz
 An: Johannes Radinger jradin...@gmx.at
 CC: r-help@r-project.org
 Betreff: Re: [R] summary per group

 Hi
 
  
  Hello,
  
  I know that it'll be quite easy to do what I want but somehow I am lost 
 as
  I am new to R. I want to get summary results arranged by groups. In 
 detail
  I'd like get the number (levels) of Species per Family like for this 
 dataset:
  
  SPEC - factor(c(a,a,b,b,c,c,c,d,e,e,e,e))
  FAM - factor(c(A,A,A,A,B,B,B,C,C,C,C,C))
  df - data.frame(SPEC,FAM)
  
  I tried tapply(SPEC, FAM, nlevels).. but it is not the result I am 
 looking for...
  
  What is the easiest way to do that? Do I have to rearrange the dataset?
 
 To do what? Do you want number of unique entries within each level of FAM?
 If yes
 
 sapply(tapply(SPEC, FAM, unique), length)
 
 can do this.
 
 Regards
 Petr

Thank you Petr,

that is exactly what I was looking for... no I played a little bit around with 
that because I want to create a summary with FAM as a grouping variable. Beside 
the number of unique SPEC per FAM also want to get their levels as text. So far 
I know I have following:

paste(unique(SPEC), collapse = ', ')

But how can I use that in combination with tapply and furthermore with cbind 
like:

SPEC - factor(c(a,a,b,b,c,c,c,d,e,e,e,e))
FAM - factor(c(A,A,A,A,B,B,B,C,C,C,C,C))
df - data.frame(SPEC,FAM)

with(df, cbind(Number of SPEC=sapply(tapply(SPEC,FAM,unique),length), 
SPECs=tapply(SPEC,FAM,unique)))

The result should look like:
Number of SPEC SPECs
A   2  a, b
B   1  c
C   2  d, e

Thank you,

/johannes


--

__
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.


Re: [R] Titelpage pdf-manual, packaging

2011-12-11 Thread Johannes Radinger

Am 10.12.2011 um 16:50 schrieb Uwe Ligges:

 
 
 On 09.12.2011 14:15, Johannes Radinger wrote:
 Hi,
 
 I am trying to get write my first own package.
 I followed the instructions in Creating R Packages: A Tutorial
 and Writing R Extensions. So far everything works really
 fine, the script works and even the man-pages don't show
 any problems during the check process.
 
 During check there is also the package-manual.pdf created.
 When I compare my manual to those at the CRAN rep, i looks different:
 I seems the other manuals have a kind of titlepage and even the
 document title is different (package 'xxx' vs. R documentation
 of ‘/Users/...’ etc.).
 
 Is that behavior simply a matter of being published at CRAN and mine is just
 a local package for myself? Or do I miss a man-page which is responsible for
 that first page and the title?
 
 Which R version are you using?
 
 
 I typically get package 'xxx' when running R CMD check but R documentation 
 of ‘...’  when runnign R CMD Rd2pdf on some Rd files with R-release.
 

Hi, I am using R 2.14.0, so I don't know what is the reason for that behavior...


 Best,
 Uwe Ligges
 
 
 
 Best regards,
 Johannes
 
 --
 
 __
 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-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] Titelpage pdf-manual, packaging

2011-12-09 Thread Johannes Radinger
Hi,

I am trying to get write my first own package.
I followed the instructions in Creating R Packages: A Tutorial
and Writing R Extensions. So far everything works really
fine, the script works and even the man-pages don't show
any problems during the check process.

During check there is also the package-manual.pdf created.
When I compare my manual to those at the CRAN rep, i looks different:
I seems the other manuals have a kind of titlepage and even the
document title is different (package 'xxx' vs. R documentation
of ‘/Users/...’ etc.).

Is that behavior simply a matter of being published at CRAN and mine is just
a local package for myself? Or do I miss a man-page which is responsible for
that first page and the title?

Best regards,
Johannes

--

__
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] Argument validation within functions

2011-12-06 Thread Johannes Radinger
Hi,

I just started with writing functions in R and so some questions popped up.
I provide some values as argument to my function such as:

function(a,b,c){}

Now i want that the function first checks if the arguments are valid for the 
function. E.g argument a has to be a number in the range 0-1. How can that 
easily done?

So far I have:

a - as.numeric(a)
if(0 = a  a = 1)

to first check if a is a number...if not the function stops and gives an error 
message. If it is a number it just continues... 

But how to check the range? 
Above there is the if-approach but then the rest of the function is exectued as 
part of if (or else). Is there a simpler way without having the if-brackets 
around the remaining code? 
Just a check if the value is between 0 and 1 and if yes continue with the next 
line if no abort the function with a error message? How can such an error 
message be created?

thank you and best regards,

/Johannes
--

__
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.


Re: [R] Argument validation within functions

2011-12-06 Thread Johannes Radinger
Hi,

thank you... I think I will go for the if-stop approach
as the stop() stops the total function... So there is just
one little other question: What is the opposite of is.numeric?
Is ther isnot.numeric? How  can that be implemented in following
function:

f - function(a){
if(is.numeric(a)) stop(a is not numeric)
if(0  a  a  1) stop(a must be a value between 0 and 1)
a
}

/Johannes

 Original-Nachricht 
 Datum: Tue, 6 Dec 2011 07:04:59 -0500
 Von: R. Michael Weylandt michael.weyla...@gmail.com
 An: Johannes Radinger jradin...@gmx.at
 CC: r-help@r-project.org
 Betreff: Re: [R] Argument validation within functions

 The quick and dirty way to do so is to use: stopifnot() in conjunction
 (if necessary with all() and any()). You can replace that first
 condition with a simple is.numeric() as well. A more helpful way (if
 this is production code) is to use if statement with the stop()
 function directly which lets you provide specific error messages.
 
 Michael
 
 On Tue, Dec 6, 2011 at 6:41 AM, Johannes Radinger jradin...@gmx.at
 wrote:
  Hi,
 
  I just started with writing functions in R and so some questions popped
 up.
  I provide some values as argument to my function such as:
 
  function(a,b,c){}
 
  Now i want that the function first checks if the arguments are valid for
 the function. E.g argument a has to be a number in the range 0-1. How
 can that easily done?
 
  So far I have:
 
         a - as.numeric(a)
         if(0 = a  a = 1)
 
  to first check if a is a number...if not the function stops and gives an
 error message. If it is a number it just continues...
 
  But how to check the range?
  Above there is the if-approach but then the rest of the function is
 exectued as part of if (or else). Is there a simpler way without having the
 if-brackets around the remaining code?
  Just a check if the value is between 0 and 1 and if yes continue with
 the next line if no abort the function with a error message? How can such an
 error message be created?
 
  thank you and best regards,
 
  /Johannes
  --
 
  __
  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-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.


Re: [R] Argument validation within functions

2011-12-06 Thread Johannes Radinger
Thank you, i didn't know that the !operator is
also working for is.numeric etc.

Anyway I want to test if an argument is set in the
function call and if not a code is executed... So 
far I tried:

f -function(a,b){
if(!exists(b)) print(exists: b is not set)
if(is.null(b)) print(is.null : b is not set)
}

f(a=1,b=2)
f(a=1)
f(b=2)

I don't really know how to do it...e.g: for f(a=1) b is not set
so it also can't be NULL (thats why is.null is not working). I
just want to test if it is set with the function call not outside
the function or before etc.

/Johannes

 Original-Nachricht 
 Datum: Tue, 6 Dec 2011 07:57:44 -0500
 Von: R. Michael Weylandt michael.weyla...@gmail.com
 An: r-help r-help@r-project.org, Johannes Radinger jradin...@gmx.at
 Betreff: Re: [R] Argument validation within functions

 Use the ! (not) operator.
 
 Not sure what you mean by  as the stop() stops the total function:
 try the following
 
 f - function(a){
    stopifnot(a  3)
    return(a^2)
 }
 
 f(2)
 f(4)
 
 Michael
 
 (PS -- It's usually asked to cc the list so that this all gets
 threaded properly in folks' mailboxes)
 
 On Tue, Dec 6, 2011 at 7:46 AM, Johannes Radinger jradin...@gmx.at
 wrote:
  Hi,
 
  thank you... I think I will go for the if-stop approach
  as the stop() stops the total function... So there is just
  one little other question: What is the opposite of is.numeric?
  Is ther isnot.numeric? How  can that be implemented in following
  function:
 
  f - function(a){
         if(is.numeric(a)) stop(a is not numeric)
         if(0  a  a  1) stop(a must be a value between 0 and 1)
         a
  }
 
  /Johannes
 
   Original-Nachricht 
  Datum: Tue, 6 Dec 2011 07:04:59 -0500
  Von: R. Michael Weylandt michael.weyla...@gmail.com
  An: Johannes Radinger jradin...@gmx.at
  CC: r-help@r-project.org
  Betreff: Re: [R] Argument validation within functions
 
  The quick and dirty way to do so is to use: stopifnot() in conjunction
  (if necessary with all() and any()). You can replace that first
  condition with a simple is.numeric() as well. A more helpful way (if
  this is production code) is to use if statement with the stop()
  function directly which lets you provide specific error messages.
 
  Michael
 
  On Tue, Dec 6, 2011 at 6:41 AM, Johannes Radinger jradin...@gmx.at
  wrote:
   Hi,
  
   I just started with writing functions in R and so some questions
 popped
  up.
   I provide some values as argument to my function such as:
  
   function(a,b,c){}
  
   Now i want that the function first checks if the arguments are valid
 for
  the function. E.g argument a has to be a number in the range 0-1. How
  can that easily done?
  
   So far I have:
  
          a - as.numeric(a)
          if(0 = a  a = 1)
  
   to first check if a is a number...if not the function stops and gives
 an
  error message. If it is a number it just continues...
  
   But how to check the range?
   Above there is the if-approach but then the rest of the function is
  exectued as part of if (or else). Is there a simpler way without having
 the
  if-brackets around the remaining code?
   Just a check if the value is between 0 and 1 and if yes continue with
  the next line if no abort the function with a error message? How can
 such an
  error message be created?
  
   thank you and best regards,
  
   /Johannes
   --
  
   __
   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.
 
  --
  NEU: FreePhone - 0ct/min Handyspartarif mit Geld-zurück-Garantie!
  Jetzt informieren: http://www.gmx.net/de/go/freephone

--

__
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] dataframe indexing by number of cases per group

2011-11-24 Thread Johannes Radinger
Hello,

assume we have following dataframe:

group -c(rep(A,5),rep(B,6),rep(C,4))
x - c(runif(5,1,5),runif(6,1,10),runif(4,2,15))
df - data.frame(group,x)

Now I want to select all cases (rows) for those groups
which have more or equal 5 cases (so I want to select
all cases of group A and B).
How can I use the indexing for such questions?

df[??]... I think it is probably quite easy but I really
don't know how to do that at the moment.

maybe someone can help me...

/johannes
--

__
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] pairs(), expression in label and color in text.panel

2011-11-24 Thread Johannes Radinger
Hello,

I'd like to add custom labels to my pair() plot. These
labels include math expression but they aren't correctly
displayed...

Further, I want that the boxes for the text.panel (diagonal)
have an other background color (grey80). Is that generally 
possible? If yes how do I have to set it?

What I've so far is:


panel.cor - function(x, y, digits=2, prefix=, cex.cor)
{
usr - par(usr); on.exit(par(usr))
par(usr = c(0, 1, 0, 1))
r - abs(cor(x, y))
txt - format(c(r, 0.123456789), digits=digits)[1]
txt - paste(prefix, txt, sep=)
if(missing(cex.cor)) cex - 0.5/strwidth(txt)

test - cor.test(x,y)
# borrowed from printCoefmat
Signif - symnum(test$p.value, corr = FALSE, na = FALSE,
cutpoints = c(0, 0.001, 0.01, 0.05, 0.1, 1),
symbols = c(***, **, *, .,  ))

text(0.5, 0.5, paste(txt,Signif), cex = 2)
}

#correlation pair plot
pairs(df, labels=c(expression(alpha),text,expression(beta)), 
lower.panel=panel.smooth, upper.panel=panel.cor)


Maybe someone knows how to do that and can give some hints...

/Johannes

--

__
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.


  1   2   >