Re: [R] encoding accentsand tildes in R Macosx

2008-08-10 Thread Kenneth Roy Cabrera Torres
Hi Carlos:

I think you got a encoding problem.
Maybe is esier to convert it.

I don't know how to convert in Mac OS, but
in linux you can use "iconv" that converts many codes
to other.

Is the original file form a windos$ OS system?
Maybe the encoding is in windows-1256 and you need
to convert to a compatible MAC enconding.

Hope this helps.

Kennneth
El dom, 10-08-2008 a las 22:14 -0700, Carlos Cuartas escribió:
> Hello,
> In R under  Mac OS X 10.5.4 I've had problems when I've tried to read a 
> data.frame with characters including tildes and accents.
> For instance Florea is changed to Flore\x96a and Ranchera is changed to 
> Rancher\x92a 
> In the code:  
> section<-read.table('Sectiondic.txt',sep='\t',header=T,stringsAsFactors=F,encoding="
>  ")
> I've changed the  "encoding" argument but I have not could find the solution.
> Any suggestion?
> 
> Thanks a lot
> 
> Carlos Cuartas
> 
> 
>   
>   [[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-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] encoding accentsand tildes in R Macosx

2008-08-10 Thread Carlos Cuartas
Hello,
In R under  Mac OS X 10.5.4 I've had problems when I've tried to read a 
data.frame with characters including tildes and accents.
For instance Floreña is changed to Flore\x96a and Ranchería is changed to 
Rancher\x92a 
In the code:  
section<-read.table('Sectiondic.txt',sep='\t',header=T,stringsAsFactors=F,encoding="
 ")
I've changed the  "encoding" argument but I have not could find the solution.
Any suggestion?

Thanks a lot

Carlos Cuartas


  
[[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] help on model selection - step()

2008-08-10 Thread Rodrigo Gazaffi
dears R-users,
I'm interested in model selection problem, and i have faced some problems
that i would like to ask for help.

well,
this is a very small example with 4 variable (just one var. is the response
- z) with 100 individuals
i would like to do a stepwise search, for the "best" model, and a use BIC
criteria.

I know when I have a lot of variables, let's say 120, I know, it's not wise,
consider the full model, so starting from "y~1", i can stop the search with
the option steps.
but when i have the IC with a negative value, is there any way that a can
stop the search?

for example: form this data set
the first step gives AIC=3.6, and the 2nd gives -9.03, IS THERE ANY WAY that
a could say, "stop here, the previous one is the best for me"... like here,
my model would be with no variable.
I know that example, looks like silly but a have bigger data, that this
happens in thirtieth iteration, what's why i would like some help

i used the step(),  is there other function that could stop this besides
step()?

cheers,
Rodrigo Gazaffi



x1 <- c( 0.3718,  0.3718,  0.3718,  0.3718,  0.3718,  0.3718,  0.3718,
0.3718, -1.,  0.3718,  0.3718,  0.3718,  0.3718,  0.3718,  0.3718,
0.3718,  0.3718,  0.3718,  0.3718,  0.3718,  0.3718,  0.3718,  0.0713,
0.1774,  0.3570,  0.3718,  0.3718,  0.3718, -1.,  0.3718, -1.,
0.1774,  0.3718,  0.3718,  0.0709,  0.1774, -1., -1.,  0.3718,
0.3718,  0.0713,  0.0709,  0.3718,  0.3718,  0.3718,  0.3718,  0.2614,
0.2614, -0.9995, -1.,  0.1774,  0.3718, -1., -1.,  0.1774,
0.3718,  0.1774,  0.3718,  0.3718, -1.,  0.3718,  0.3718,  0.3718,
0.3718,  0.3718, -1.,  0.3718,  0.3718,  0.3718,  0.3718,  0.0709,
0.0710,  0.3718,  0.3718,  0.3718,  0.3718,  0.3718,  0.0709,  0.3718,
0.0709,  0.0709,  0.3718,  0.0709,  0.3570,  0.3718,  0.3718,  0.3718,
0.0709,  0.3718,  0.3718,  0.3718, -1.,  0.3718,  0.3718,  0.3718,
-1.,  0.3718,  0.3718,  0.3718,  0.3718)

x2 <- c( 0.3898, -0.9995,  0.3898,  0.3898,  0.3898,  0.1978,  0.3898,
-0.9997, -1., -1.,  0.3898,  0.3898,  0.3898,  0.3898, -1.,
0.1978, -1.,  0.3898,  0.3898, -1.,  0.1978,  0.3898,  0.3898,
0.3898,  0.1978, -0.9995,  0.3792, -1., -1.,  0.3898,  0.0837,
0.0837,  0.0837,  0.3898,  0.0837,  0.3898,  0.3898,  0.0837,  0.3898,
0.0837,  0.0837, -1., -1.,  0.3898,  0.0841,  0.1976, -1.,
0.2467,  0.1978,  0.3842,  0.3898,  0.3848,  0.2766,  0.3898,  0.3898,
0.3898, -1., -0.9995,  0.3898,  0.3898,  0.0837,  0.3898, -1.,
0.1978,  0.3898,  0.2766,  0.3898,  0.3898,  0.3898,  0.2766,  0.3898,
0.3866,  0.1978,  0.3898, -1., -1.,  0.3898,  0.3898,  0.3898,
0.3898,  0.3898,  0.1978,  0.0841, -1.,  0.0837,  0.3898,  0.3898,
-1.,  0.3898,  0.3898, -1.,  0.3898,  0.3898,  0.0837,  0.3898,
0.3898,  0.1976,  0.3898,  0.3898,  0.3898)

x3 <- c( 0.,  0.,  0.,  1., -0.,  0., -0.,
0., -0., -1., -1., -0., -0.9980, -0., -0.,
-1., -0., -0., -0.,  1., -1.,  1., -1.,
-1., -1., -0.9980,  1., -0., -1., -1., -0.,
-0.,  0.,  1., -0., -1.,  1.,  0.,  1.,
-0.,  0., -1., -1., -0.,  0.8356,  0.8356, -0.3241,
0.8356,  0.8353,  0.8356,  1., -1., -1., -1., -1.,
-1., -0.,  0.,  1., -0.9980,  0.,  1., -1.,
1., -0.,  1.,  0., -1.,  1., -1.,  0.,
0., -1., -1.,  1., -1., -1.,  1.,  1.,
1., -0.,  1., -1.,  1., -1.,  1., -1.,
1.,  1.,  1., -1., -0., -0.8547, -1., -0.7851,
0.8356, -1., -0., -0.,  1.)

z  <- c( -0.006548414, -1.035584950, -0.006548414,  0.180549138,
0.741841793,  1.770878329, -0.848487398, -1.035584950, -2.251719037,
0.461195465,  2.051524656,  1.116036897, -0.193645966,  0.274097913,
0.180549138,  0.274097913,  0.274097913,  0.835390569,  0.928939345,
-1.316231277,  0.087000362,  0.741841793,  1.116036897,  0.180549138,
-0.193645966,  0.274097913,  0.274097913,  1.490232001, -1.222682502,
1.303134449,  0.367646689, -0.100097190, -0.006548414, -1.035584950,
1.490232001,  0.648293017, -2.064621485, -2.625914141,  1.022488121,
-0.006548414, -1.222682502, -0.567841070, -0.942036174,  0.461195465,
1.770878329,  0.461195465, -1.503328829, -1.035584950, -0.848487398,
-0.567841070,  1.396683225,  2.051524656, -0.942036174, -0.754938622,
-1.596877605,  0.648293017, -0.287194742, -0.567841070,  0.461195465,
-0.474292294, -0.100097190, 0.287194742,  0.554744241, -0.006548414,
1.209585673, -1.409780053,  0.928939345,  0.928939345, -0.006548414,
1.396683225, -0.380743518,  0.928939345,  1.490232001,  1.770878329,
-1.129133726, -0.848487398, -0.380743518,  0.274097913, -1.409780053,
-0.100097190,  0.367646689, -0.474292294,  0.554744241, -2.251719037,
0.087000362, -0.848487398,  0.741841793, -2.064621485, -0.006548414,
0.461

Re: [R] Basic data structures

2008-08-10 Thread Satoshi Takahama
Suppose I want to have a regexp match against a string, and return all
the matching substrings in a vector of strings.

   regexp <- "[ab]+"
   strlist <- c( "abc", "dbabddadd", "aaa" )
   matches <- gregexpr(regexp,strlist)

With this input, I'd want to return list( list("ab"), list("ab", "a"),
list("aaa") ).

Now the matches object prints out as

   [[1]]
   [1] 1
   attr(,"match.length")
   [1] 2

   [[2]]
   [1] 2 7
   attr(,"match.length")
   [1] 3 1

   [[3]]
   [1] 1
   attr(,"match.length")
   [1] 3

which, if I'm interpreting this correctly, means that it is a list
(not a vector, because vectors can only have atomic elements) of three
elements, each of which is a vector of integers (the matching
positions) with an attribute match.length (the length of the
corresponding match), which is in turn a vector of integers.

===
Question: is there a more compact standard print format for this? It's
a bit disconcerting that printing the 2x2 list
list(list(1,2),list(3,4)) takes 16 lines while the corresponding 2x2
array takes 2 lines! (I guess that arrays are "more native").

Here is one way:

> (mat <- t(sapply(matches,function(x)
+list(start.index=`attributes<-`(x,NULL),
+ match.length=attr(x,"match.length")
 start.index match.length
[1,] 1   2   
[2,] Integer,2   Integer,2   
[3,] 1   3  

The object returned by this function is a 3x2 matrix of mode "list" -
each element of the matrix contains a list:

> mat[2,1]
$start.index
[1] 2 7

> mat[[2,1]]
[1] 2 7

also, see below...

===
Now, matches[[1]], the first element of matches, describes the matches
in the first string.  To extract those strings, I can write

   substr( strlist[[1]],
   matches[[1]],
   attr(matches[[1]],"match.length")+matches[[1]]-1 )

which correctly gives "ab".

Question: This looks awfully clumsy; is there some more idiomatic way
to do this, in particular to refer to the match.length attribute
without using a quoted string or the attr function?
attributes(matches[[1]])$match.length and
attributes(matches[[1]])[[1]] work, but seem even clumsier.

Check out the gsubfn package - I'm still learning it myself, but it may
provide the functionality you seek. For instance, I believe what you
are trying to accomplish is 

> strapply(strlist,regexp,identity)
or 
> strapply(strlist,regexp,c)
[[1]]
[1] "ab"

[[2]]
[1] "bab" "a"  

[[3]]
[1] "aaa"

===
Question: R uses names like xxx.yyy in many places.  Is this just a
convention to represent spaces (the way most languages use "_"), or is
there some semantics attached to "."?

In many examples that I have seen , programmers have used "." in the
place of the traditional "_" because "_" used to be an assignment
operator in earlier versions of R. Now, "_" is no longer an assignment
operator and its use in variable names is permitted also.

The "." notation also plays a role in the implementation of OOP by R.
R has two object-oriented approaches: S3 and S4. For both approaches,
methods are associated with generic functions, rather than the object
itself (which I understand is similar to Lisp's CLOS). For S3 methods,
function.objectclass implies the generic "function" to be applied to
class "objectclass".

For instance, print() is a generic function:
> print
function (x, ...) 
UseMethod("print")


If you want to define a method for a particular class of objects, 
you can use the xxx.yyy syntax:
> print.regexp <- function(x)
+   for(i in seq(along=x))
+   cat(i,":", x[[i]], "| match.length =",
+   attr(x[[i]],"match.length"),"\n")

> class(matches) <- "regexp"
> print(matches)
1 : 1 | match.length = 2 
2 : 2 7 | match.length = 3 1 
3 : 1 | match.length = 3 

You can assign a class (or classes) to each object; this information
is used for making method dispatch decisions for generic
functions. For S3 there is no checking of consistency between object
classes and its attributes; S4 is a more formal implementation of OOP
in R.

Check out
(S3)
http://www-128.ibm.com/developerworks/linux/library/l-r3.html
(S4)
http://developer.r-project.org/howMethodsWork.pdf

The first reference also mentions how to implement infinite sequences
in R - which may answer part of your question below.

===
Question: Is it good practice in R to treat a string as a vector of
characters so that R's powerful vector operations can be used on it?
How would I do that?

I'm sure it can be done by defining your own objects and methods, but
it's not done out-of-the-box (that I'm aware of). I believe the most
common string operations used by R users are extraction and
concatenation; these are effectively achieved by substr(), substring()
and paste(), rather than "[", c(), or "+", as you seem to have figured
out. In my experience, R's standard objects and functions for
string-like objects are immediately convenient for manipulating file
and variable names but not necessarily for hard-core text processing.

===
Now suppose I want to list *all* the matches in matches[[2]].  

[R] how to add "arial" font in bitmap output?

2008-08-10 Thread Hyunchul Kim
Hi all,

I want to specify "arial" font in bitmap output but I found that the default
is "helvetica" and "arial" is not supported.

How can I add "arial" in my bitmap output file?

Thanks,

Hyunchul

[[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] frequency of labels in a barplot

2008-08-10 Thread R_Learner

I'm trying to control the number of labels in the x-axis of my plot. My code
is the following: 

graph1<-barplot(total_skew)
axis(1,at = graph1,labels=raw_date[1:length(total_skew)], las=2)

however, the length of my "total_skew" parameter is a few thousand elements,
and all the labels on the x-axis are overlapping and cluttered. How do I
specify the frequency or number of labels I want on the x-axis in the axis()
function? Thanks!
-- 
View this message in context: 
http://www.nabble.com/frequency-of-labels-in-a-barplot-tp18919093p18919093.html
Sent from the R help mailing list archive at Nabble.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.


[R] How to specify the type and size of font in bitmap format output?

2008-08-10 Thread Hyunchul Kim
Hi, all

I need to specify a font (for example, type=helvetica and size=10) in bitmap
output (for example, dev.print(bitmap, 'test.png').
How can I do this?

Thanks.

Hyunchul

[[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] how to add "arial" font in bitmap output?

2008-08-10 Thread Hyunchul Kim
Hi all,

I want to specify "arial" font in bitmap output but I found that the default
is "helvetica" and "arial" is not supported.

How can I add "arial" in my bitmap output file?

Thanks,

Hyunchul

[[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] How to specify the type and size of font in bitmap format output?

2008-08-10 Thread Hyunchul Kim
Hi, all

I need to specify a font (for example, type=helvetica and size=10) in bitmap
output (for example, dev.print(bitmap, 'test.png').
How can I do this?

Thanks.

Hyunchul

[[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] Basic data structures

2008-08-10 Thread Gabor Grothendieck
Try this:

  regexp <- "[ab]+"
  strlist <- c( "abc", "dbabddadd", "aaa" )

  library(gsubfn)

  s <- strapply(strlist, regexp)
  s

  # compactly show 1st few in ea component
  str(s)

See gsubfn home page at
http://gsubfn.googlecode.com


On Sun, Aug 10, 2008 at 5:00 PM, Stavros Macrakis <[EMAIL PROTECTED]> wrote:
> I'm new to R and very excited about its possibilities.  But I'm
> struggling with some very simple things, probably because I haven't
> found the correct documentation.  Here's a simple example which
> illustrates several of my problems.
>
> Suppose I want to have a regexp match against a string, and return all
> the matching substrings in a vector of strings.
>
>   regexp <- "[ab]+"
>   strlist <- c( "abc", "dbabddadd", "aaa" )
>   matches <- gregexpr(regexp,strlist)
>
> With this input, I'd want to return list( list("ab"), list("ab", "a"),
> list("aaa") ).
>
> Now the matches object prints out as
>
>   [[1]]
>   [1] 1
>   attr(,"match.length")
>   [1] 2
>
>   [[2]]
>   [1] 2 7
>   attr(,"match.length")
>   [1] 3 1
>
>   [[3]]
>   [1] 1
>   attr(,"match.length")
>   [1] 3
>
> which, if I'm interpreting this correctly, means that it is a list
> (not a vector, because vectors can only have atomic elements) of three
> elements, each of which is a vector of integers (the matching
> positions) with an attribute match.length (the length of the
> corresponding match), which is in turn a vector of integers.
>
> Question: is there a more compact standard print format for this? It's
> a bit disconcerting that printing the 2x2 list
> list(list(1,2),list(3,4)) takes 16 lines while the corresponding 2x2
> array takes 2 lines! (I guess that arrays are "more native").
>
> Now, matches[[1]], the first element of matches, describes the matches
> in the first string.  To extract those strings, I can write
>
>   substr( strlist[[1]],
>   matches[[1]],
>   attr(matches[[1]],"match.length")+matches[[1]]-1 )
>
> which correctly gives "ab".
>
> Question: This looks awfully clumsy; is there some more idiomatic way
> to do this, in particular to refer to the match.length attribute
> without using a quoted string or the attr function?
> attributes(matches[[1]])$match.length and
> attributes(matches[[1]])[[1]] work, but seem even clumsier.
>
> Question: R uses names like xxx.yyy in many places.  Is this just a
> convention to represent spaces (the way most languages use "_"), or is
> there some semantics attached to "."?
>
> Question: Is it good practice in R to treat a string as a vector of
> characters so that R's powerful vector operations can be used on it?
> How would I do that?
>
> Now suppose I want to list *all* the matches in matches[[2]].  I try:
>
>   substr( strlist[[2]],
>   matches[[2]],
>   attr(matches[[2]],"match.length")+matches[[2]]-1 )
>
> but only get the first one, so it seems that the recycling rule for
> vectors doesn't apply here (same thing with [2] instead of [[2]]).
> Where does recycling apply and not apply?
>
> Question: Is there some operator (using promises?) to make
> strlist[[2]] into a (lazy) infinite vector/list?
>
> Now suppose I want to list *all* the matches in all the strings.  How
> would I do that?  The naive way, substr(strlist,matches, ...) doesn't
> work, partly because the attr operator doesn't distribute over lists
> (I see why it can't, but...).
>
> Thanks in advance for your patience with these very elementary questions,
>
>  -s
>
> Stavros Macrakis, Cambridge, MA
>
> __
> 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] R-PLus by XLSolutions Corp

2008-08-10 Thread eugene dalt
by the way if you are interested in beta testing R-PLus,   email  [EMAIL 
PROTECTED]


--- On Sun, 8/10/08, S Ellison <[EMAIL PROTECTED]> wrote:

> From: S Ellison <[EMAIL PROTECTED]>
> Subject: Re: [R] RPro
> To: [EMAIL PROTECTED]
> Cc: r-help@r-project.org
> Date: Sunday, August 10, 2008, 12:53 PM
> >>> Stephan Kolassa <[EMAIL PROTECTED]>
> 08/10/08 8:41 PM >>>
> >I like RSeek:
> >http://www.rseek.org/
> The burning question is why an audio compay would be
> running a web
> search engine for an open source statistics package...??!
> 
> 
> ***
> This email and any attachments are confidential. Any\ ...{{dropped:14}}

__
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] R-PLus by XLSolutions Corp

2008-08-10 Thread eugene dalt
by the way if you are interested in testing R-PLus,   email  [EMAIL PROTECTED]


--- On Sun, 8/10/08, S Ellison <[EMAIL PROTECTED]> wrote:

> From: S Ellison <[EMAIL PROTECTED]>
> Subject: Re: [R] RPro
> To: [EMAIL PROTECTED]
> Cc: r-help@r-project.org
> Date: Sunday, August 10, 2008, 12:53 PM
> >>> Stephan Kolassa <[EMAIL PROTECTED]>
> 08/10/08 8:41 PM >>>
> >I like RSeek:
> >http://www.rseek.org/
> The burning question is why an audio compay would be
> running a web
> search engine for an open source statistics package...??!
> 
> 
> ***
> This email and any attachments are confidential. Any\ ...{{dropped:14}}

__
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] RPro vs R-Plus

2008-08-10 Thread eugene dalt
I am a beta tester for  R-PLus from XLSolutions Corp and it's pretty cool. I 
understand  R-PLus will be free  but let's see  - 


--- On Sun, 8/10/08, S Ellison <[EMAIL PROTECTED]> wrote:

> From: S Ellison <[EMAIL PROTECTED]>
> Subject: Re: [R] RPro
> To: [EMAIL PROTECTED]
> Cc: r-help@r-project.org
> Date: Sunday, August 10, 2008, 12:53 PM
> >>> Stephan Kolassa <[EMAIL PROTECTED]>
> 08/10/08 8:41 PM >>>
> >I like RSeek:
> >http://www.rseek.org/
> The burning question is why an audio compay would be
> running a web
> search engine for an open source statistics package...??!
> 
> 
> ***
> This email and any attachments are confidential. Any\ ...{{dropped:14}}

__
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 set operations?

2008-08-10 Thread rkevinburton
Because of machine memory restrictions I think I need to go with a vector by 
vector approach. When I concatenate I get:

> m <- melt(t, id.var=c("DayOfYear","Category","SubCategory","Sku"), 
> measure.var=c("Quantity"))
Error: cannot allocate vector of size 7.8 Mb

Kevin

 hadley wickham <[EMAIL PROTECTED]> wrote: 
> Hi Kevin,
> 
> I think easiest way would be to create a single dataset with both
> years in, and then work from that:
> 
> t2008$year <- 2008
> t2007$year <- 2007
> 
> tall <- rbind(t2007, t2008)
> mall <- melt(tall,
> id.var=c("DayOfYear","Category","SubCategory","Sku", "year"),
> measure.var=c("Quantity")
> 
> cast(mall, DayOfYear ~ variable | Sku, sum)
> cast(mall, Year + DayOfYear ~ variable | Sku, sum)
> 
> Hadley
> 
> 
> On Sat, Aug 9, 2008 at 11:44 AM,  <[EMAIL PROTECTED]> wrote:
> > I have mange to use the library reshape to give me data structures that I 
> > want. Specifically:
> >
> > m2008 <- melt(t2008, id.var=c("DayOfYear","Category","SubCategory","Sku"), 
> > measure.var=c("Quantity"))
> >  m2007 <- melt(t2007, id.var=c("DayOfYear","Category","SubCategory","Sku"), 
> > measure.var=c("Quantity"))
> >
> >  r2008 <- cast(m2008, DayOfYear ~ variable | Sku, sum)
> >  r2007 <- cast(m2007, DayOfYear ~ variable | Sku, sum)
> >
> > Now I would like to union the two lists. So I start out with an empty 
> > master list that will contain (when I am done) the merge (union) of r2008 
> > and r2007. By "union" I mean that if the Sku exists in r2007 and r2008 I 
> > would like to create a new data frame that has the lists for DayOfYear and 
> > Quantity "merged" and append it to 'master'. If the Sku is not common to 
> > both objects then just copy or append to the 'master'.
> >
> > Is it possible to come up with an expression and aggregate function that 
> > will do this? Is this better handle with aggregate functions or lapply? 
> > Being new to 'R' it is hard for me to tell.
> >
> > Thank you.
> >
> > Kevin
> >
> > __
> > 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.
> >
> 
> 
> 
> -- 
> http://had.co.nz/

__
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] ANOVA help

2008-08-10 Thread Gareth Campbell
Hi,

I'm doing anova on a matrix of multivariate data where I want to assess the
effect of each column (element).

My matrix is 86 rows x 31 columns.  I've created a grouping factor of length
86 containing group assignments of 6 types.

Then I run:

x<- aov(matrix~grouping.factor)
summary(aov.fit.raw, test="Wilks")

This is working fine enough, but I'm getting different results to someone
who I'm comparing with - am I doing what I think I am doing here??

What I think I'm doing is - take the first column (element) and then look at
that element between the 6 groups and report F, Pvalue etc..., then move
onto the 2nd column and repeat.

Thanks



-- 
Gareth Campbell
PhD Candidate
The University of Auckland

P +649 815 3670
M +6421 256 3511
E [EMAIL PROTECTED]
[EMAIL PROTECTED]

[[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] Box.test degrees of freedom

2008-08-10 Thread David Stoffer

I stand corrected.  I thought I checked this a long time ago, but apparently
not.  tsdiag.Arima DOES NOT use the fact that the series it is testing (or
diagnosing, if you will) are residuals from an ARIMA fit. 

I keep a list of R time series bloopers here: 
http://www.stat.pitt.edu/stoffer/tsa2/Rissues.htm along with some
work-arounds over here: http://www.stat.pitt.edu/stoffer/tsa2/Examples.htm




David Stoffer wrote:
> 
> I believe tsdiag() uses the correct degrees of freedom in applying
> Box.test, but the graphic shows "lag" on the horizontal axis when it
> should display "degrees of freedom".   
> 
> 
> 
> raf.rossignol wrote:
>> 
>> Hello,
>> 
>> Prof Brian Ripley wrote:
>>> 
>>> I think you are referring to its application to the residuals of an 
>>> ARMA(p, q) fit, and that is not what Box.test says it does.
>>> 
>>> It is very easy to edit the code if you want to use a different degrees
>>> of
>>> freedom.
>>> 
>> I am also new to R, but it seems to me that there is still something
>> confusing, not in Box.test but in tsdiag.Arima
>> Indeed, the help of tsdiag says "The methods for 'arima' and 'StructTS'
>> [...] use the Ljung-Box version of the portmanteau test." 
>> So we could expect the degrees of freedom 'h-p-q' to be used, but a look
>> at tsdiag.Arima shows it uses Box.test at lags h=1:gof.lag, with degrees
>> of freedom equal to h, and  not h-p-q. Do you think this is a mistake in
>> tsdiag.Arima or is there some experimental (or theoretical) reason
>> supporting this choice ?
>> Best regards
>> 
>> 
>> 
> 
> 


-
The power of accurate observation is commonly called cynicism 
by those who have not got it.  George Bernard Shaw
-- 
View this message in context: 
http://www.nabble.com/Box.test-degrees-of-freedom-tp17277964p18917747.html
Sent from the R help mailing list archive at Nabble.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.


[R] (Un-)intentional change in drop1() "Chisq" behaviour?

2008-08-10 Thread Lutz Ph. Breitling
Dear List,
recently tried to reproduce the results of some custom model selection
function after updating R, which unfortunately failed. However, I
ultimately found the issue to be that testing with pchisq() in drop1()
seems to have changed. In the below example, earlier versions (e.g. R
2.4.1) produce a missing P-value for the variable x, while newer
versions (e.g. R 2.7.1) produce 0 (2.2e-16).

I would assume that the former is more appropriate, so I was just
curious if this is an intentional change.
Kind regards-
Lutz

y<-rbinom(100,1,0.5)
x<-rep(0,100)
m<-glm(y~x, family=binomial)
summary(m)
drop1(m, test="Chisq")
#
R241> drop1(m, test="Chisq")
Single term deletions

Model:
y ~ x
   Df DevianceAICLRT Pr(Chi)
  138.59 140.59
x   0   138.59 140.59   0.00
Warning message:
NaNs produced in: pchisq(q, df, lower.tail, log.p)
##
R271> drop1(m, test="Chisq")
Single term deletions

Model:
y ~ x
   Df DevianceAICLRT   Pr(Chi)
  137.99 139.99
x   0   137.99 139.99   0.00 < 2.2e-16 ***
---
Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
###

__
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] gridBase and new.page() / grid.newpage()

2008-08-10 Thread Paul Murrell
Hi


Peter Cowan wrote:
> Paul,
> 
> The real case is a function where I'd want to allow end users to pass
> an arbitrary plotting function to be a sub plot within a larger plot
> (e.g. the code that does the density plots would actually be passed as
> a parameter.  I adapted my example to reflect this.   I expect most of
> my end users to be unfamiliar with grid, yet familiar with base
> graphics.


Ok.  Thanks for the clarification.

You may be buying yourself a fair amount of pain with that goal (base
graphics functions are NOT generally written to play nicely with even
other base graphics functions, let alone other graphics systems), but
for your particular example, here's a possible fix:

- remove the grid.newpage() call (the plot.new() takes care of starting
a new page)

- add 'clip="off"' to the first pushViewport() call in myplot();  the
problem with the bottom-right subplot is due to clipping regions not
being reset correctly.

myplot() becomes ...

myplot <- function(subplot) {
   plot.new()
   n <- 10
   datalayout <- grid.layout(ncol = 2, width = unit(c(1, 1/n),
c('null', 'null')))

   pushViewport(viewport(width = .8, height = .8, layout = datalayout,
clip="off"))
   grid.rect(gp=gpar(col="grey"))

   for(i in 1:n) {
   pushViewport(viewport(
   y = i/n - 0.5 / n, x = 1,
   height = unit(1/n, 'npc'),
   width = unit(1/n, 'npc')))
   subplot()
   upViewport()
   }
   pushViewport(viewport(xscale = c(0, 1), layout.pos.col = 1))
   grid.rect(gp=gpar(fill="grey"))
   grid.points()
   upViewport()
   upViewport()
}

... does that fix things for you ?

Paul


> Thanks,
> 
> Peter
> 
> Aplot <- function(){
> par(plt = gridPLT(), new = TRUE)
> grid.rect(gp=gpar(fill="light grey"))
> dens <- density(rnorm(10))
> plot.density(dens, axes = FALSE,
> mar = c(0,0,0,0), main = "", xlab = "", ylab = "")
> }
> 
> myplot <- function(subplot) {
>grid.newpage()
>plot.new()
>n <- 10
>datalayout <- grid.layout(ncol = 2, width = unit(c(1, 1/n),
> c('null', 'null')))
> 
>pushViewport(viewport(width = .8, height = .8, layout = datalayout))
>grid.rect(gp=gpar(col="grey"))
> 
>for(i in 1:n) {
>pushViewport(viewport(
>y = i/n - 0.5 / n, x = 1,
>height = unit(1/n, 'npc'),
>width = unit(1/n, 'npc')))
>subplot()
>upViewport()
>}
>pushViewport(viewport(xscale = c(0, 1), layout.pos.col = 1))
>grid.rect(gp=gpar(fill="grey"))
>grid.points()
>upViewport()
>upViewport()
> }
> 
> myplot(Aplot)
> myplot(Aplot)
> 
> pdf()
> myplot(Aplot)
> myplot(Aplot)
> dev.off()
> 
> 
> On Sun, Aug 10, 2008 at 1:48 PM, Paul Murrell <[EMAIL PROTECTED]> wrote:
>> Hi
>>
>>
>> Peter Cowan wrote:
>>> Hello all,
>>>
>>> I'm trying to write a function using the gridBase package.  I'd like
>>> to push several base subplots to a larger plot constructed with grid.
>>> However, I'm having trouble getting consistent results when running
>>> the function when the plotting window (quartz) is closed, when it is
>>> left open and the plot function is repeated to the same window, and
>>> when the output is saved to a pdf, see the example below.  In the case
>>> of the pdf plot pages are preceded by a blank page.  However, leaving
>>> out either plot.new() or grid.newpage() each presents different
>>> problems.  I looked through the R Graphics book and package vignette
>>> but didn't see this particular issue addressed.
>>
>> There can be complications when both the 'graphics' package and the
>> 'grid' package try to start a new page.
>>
>> Before trying to untangle this particular example, is it possible to
>> side step the problem by drawing those density plots using a
>> grid-compatible system such as either lattice or ggplot ?
>>
>> Or, if the "real" case is as simple as this, perhaps even just
>> grid.lines() will do the job (?)
>>
>> Paul
>>
>>
>>> Thanks in advance,
>>>
>>> Peter
>>>
>>> myplot <- function() {
>>> grid.newpage()
>>> plot.new()
>>> n <- 10
>>> datalayout <- grid.layout(ncol = 2, width = unit(c(1, 1/n),
>>> c('null', 'null')))
>>>
>>> pushViewport(viewport(width = .8, height = .8, layout = datalayout))
>>> grid.rect(gp=gpar(col="grey"))
>>>
>>> for(i in 1:n) {
>>> pushViewport(viewport(
>>> y = i/n - 0.5 / n, x = 1,
>>> height = unit(1/n, 'npc'),
>>> width = unit(1/n, 'npc')))
>>> par(plt = gridPLT(), new = TRUE)
>>> grid.rect(gp=gpar(fill="light grey"))
>>> dens <- density(rnorm(10))
>>> plot.density(dens, axes = FALSE,
>>> mar = c(0,0,0,0), main = "", xlab = "", ylab = "")
>>> upViewport()
>>> }
>>> pushViewport(viewport(xscale = c(0, 1), layout.pos.col = 1))
>>> grid.rect(gp=gpar(fill="grey"))
>>> grid.points()
>>> upViewport()
>>> upViewport()
>>> }
>>>
>>> myplot()
>>> myplot()
>>

Re: [R] grid layout scaling viewport width based solely on height

2008-08-10 Thread Paul Murrell
Hi


Peter Cowan wrote:
> Paul,
> 
> On Wed, Aug 6, 2008 at 1:40 PM, Paul Murrell <[EMAIL PROTECTED]> wrote:
>>> I'm trying to write a function that produces a main plotting region
>>> with several square plots along the right side.  Ideally the size of
>>> right side plots will scale only with the height of the entire plot,
>>> yet never overlap with another secondary plot.  The following two
>>> snippets get close, however, as I resize the plot horizontally the
>>> right side plots (green squares) get smaller whereas I'd like them to
>>> remain the same size.  It seems the answer lies in setting the layout
>>> width for the side plot column in a clever way that I haven't been
>>> able to discover.  Any suggestions on how to achieve that effect or
>>> other improvements to the below code are most welcome.
>>>
>>> Hopefully, my explanation makes my goal clear.  Also note, the real
>>> application is a function that will have arbitrary numbers of side
>>> plots.
> 
>> Sorry, I'm not completely sure what you want to end up with, but do
>> either of the following come close ?
> 
> Thanks for the response.  Of the two suggestions the latter is close
> to what I was hoping four.  However, ideally there would be no gap
> between the side plots when the plot is 'tall'.  Phrased another way,
> as the total plot gets larger, I would like the second column of the
> lay1 to take up a greater proportion of the figure. So that a resize
> in the Y, changes the allocation of column space in the X.  I don't
> suppose that is possible, is it?


It is, with a little more work ...

# Side plots square and take up as much room as they are allowed
# A special grob that is not drawn, but has the required height for the
# side plots
squareGrob <- grob(height=unit(.1, "npc"),
   cl="squareGrob")
# A method for determining the width of the special grob based
# on its height.
# The important point is that this calculation will get redone
# every time the squareGrob is asked for its width.
widthDetails.squareGrob <- function(x) {
  convertUnit(unit(.1, "npc"),
  "npc",
  "y", "dimension",
  "x", "dimension")
}
# A layout where the width of the second column is based
# on the width of the special grob (first column width
# takes up whatever width is left over)
lay1 <- grid.layout(10, 2,
widths=unit.c(unit(1, "null"),
  grobWidth(squareGrob)),
heights=unit(.1, "npc"))

... Once that squareGrob is defined, you can use it anywhere, so that's
a one-off cost.  The following code shows the resulting layout ...

# grid.newpage()
pushViewport(viewport(layout=lay1))

pushViewport(viewport(layout.pos.col=1))
grid.rect(gp=gpar(fill="grey"))
popViewport()

for (i in 1:10) {
pushViewport(viewport(layout.pos.col=2,
  layout.pos.row=i))
grid.rect(gp=gpar(fill="light grey"))
popViewport()
}

... does that do the job ?

Paul


> Cheers
> 
> Peter
> 
>> # Side plots square and attached to each other
>> # With "tall" plot, get gaps top and bottom
>> # With "wide" plot, get gap on the right
>> lay1 <- grid.layout(1, 2, widths=c(10, 1))
>> lay2 <- grid.layout(10, 1, respect=TRUE, just="left")
>>
>> # grid.newpage()
>> pushViewport(viewport(width=.8, height=.8, layout=lay1))
>> grid.rect(gp=gpar(col="grey"))
>>
>> pushViewport(viewport(layout.pos.col=1))
>> grid.rect(gp=gpar(fill="grey"))
>> popViewport()
>>
>> pushViewport(viewport(layout.pos.col=2,
>>  layout=lay2))
>> for (i in 1:10) {
>>pushViewport(viewport(layout.pos.row=i))
>>grid.rect(gp=gpar(fill="light grey"))
>>popViewport()
>> }
>> popViewport()
>>
>>
>> # Side plots square and separate from each other
>> # With "tall" plot, get gaps between vertically
>> # With "wide" plot, get gap on the right
>> lay1 <- grid.layout(10, 2, widths=c(10, 1))
>>
>> # grid.newpage()
>> pushViewport(viewport(width=.8, height=.8, layout=lay1))
>> grid.rect(gp=gpar(col="grey"))
>>
>> pushViewport(viewport(layout.pos.col=1))
>> grid.rect(gp=gpar(fill="grey"))
>> popViewport()
>>
>> for (i in 1:10) {
>>pushViewport(viewport(layout.pos.col=2,
>>  layout.pos.row=i))
>>pushViewport(viewport(x=0, width=unit(1, "snpc"),
>>  height=unit(1, "snpc"), just="left"))
>>grid.rect(gp=gpar(fill="light grey"))
>>popViewport(2)
>> }
>>
>> Paul
>>

-- 
Dr Paul Murrell
Department of Statistics
The University of Auckland
Private Bag 92019
Auckland
New Zealand
64 9 3737599 x85392
[EMAIL PROTECTED]
http://www.stat.auckland.ac.nz/~paul/

__
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] gridBase and new.page() / grid.newpage()

2008-08-10 Thread Paul Murrell
Hi


Peter Cowan wrote:
> Hello all,
> 
> I'm trying to write a function using the gridBase package.  I'd like
> to push several base subplots to a larger plot constructed with grid.
> However, I'm having trouble getting consistent results when running
> the function when the plotting window (quartz) is closed, when it is
> left open and the plot function is repeated to the same window, and
> when the output is saved to a pdf, see the example below.  In the case
> of the pdf plot pages are preceded by a blank page.  However, leaving
> out either plot.new() or grid.newpage() each presents different
> problems.  I looked through the R Graphics book and package vignette
> but didn't see this particular issue addressed.


There can be complications when both the 'graphics' package and the
'grid' package try to start a new page.

Before trying to untangle this particular example, is it possible to
side step the problem by drawing those density plots using a
grid-compatible system such as either lattice or ggplot ?

Or, if the "real" case is as simple as this, perhaps even just
grid.lines() will do the job (?)

Paul


> Thanks in advance,
> 
> Peter
> 
> myplot <- function() {
> grid.newpage()
> plot.new()
> n <- 10
> datalayout <- grid.layout(ncol = 2, width = unit(c(1, 1/n),
> c('null', 'null')))
> 
> pushViewport(viewport(width = .8, height = .8, layout = datalayout))
> grid.rect(gp=gpar(col="grey"))
> 
> for(i in 1:n) {
> pushViewport(viewport(
> y = i/n - 0.5 / n, x = 1,
> height = unit(1/n, 'npc'),
> width = unit(1/n, 'npc')))
> par(plt = gridPLT(), new = TRUE)
> grid.rect(gp=gpar(fill="light grey"))
> dens <- density(rnorm(10))
> plot.density(dens, axes = FALSE,
> mar = c(0,0,0,0), main = "", xlab = "", ylab = "")
> upViewport()
> }
> pushViewport(viewport(xscale = c(0, 1), layout.pos.col = 1))
> grid.rect(gp=gpar(fill="grey"))
> grid.points()
> upViewport()
> upViewport()
> }
> 
> myplot()
> myplot()
> 
> pdf()
> myplot()
> myplot()
> dev.off()
> 
> __
> 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.

-- 
Dr Paul Murrell
Department of Statistics
The University of Auckland
Private Bag 92019
Auckland
New Zealand
64 9 3737599 x85392
[EMAIL PROTECTED]
http://www.stat.auckland.ac.nz/~paul/

__
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] using IF command

2008-08-10 Thread Dan Davison
On Mon, Aug 11, 2008 at 08:23:19AM +1200, Gareth Campbell wrote:
> Hey team,
> 
> If I have a matrix:
> 
> 1, 2,
> 3, 4,
> 4, 0,
> 1, 3,
> 0, 3
> 
> 2 columns.
> 
> I want to write an if command that looks at (in this case) row 3 and looks
> to see if either [3,1] or [3,2] has a zero in it.  IF it does have a zero I
> want the zero to be placed in another matrix in the same position.  I know
> how to do the latter part, I just can't get the if command to look at both
> cells and deal with them separately.

I think you want to be using ifelse():

> a
 [,1] [,2]
[1,]12
[2,]34
[3,]40
[4,]13
[5,]03
> b
 [,1] [,2]
[1,]99
[2,]99
[3,]99
[4,]99
[5,]99
> ifelse(a == 0, a, b) ## do the whole thing
 [,1] [,2]
[1,]99
[2,]99
[3,]90
[4,]99
[5,]09
> b[3,] <- ifelse(a[3,] == 0, a[3,], b[3,]) ## just row 3
> b
 [,1] [,2]
[1,]99
[2,]99
[3,]90
[4,]99
[5,]99

Dan


> 
> Thanks
> 
> -- 
> Gareth Campbell
> PhD Candidate
> The University of Auckland
> 
> P +649 815 3670
> M +6421 256 3511
> E [EMAIL PROTECTED]
> [EMAIL PROTECTED]
> 
>   [[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-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] Basic data structures

2008-08-10 Thread Stavros Macrakis
I'm new to R and very excited about its possibilities.  But I'm
struggling with some very simple things, probably because I haven't
found the correct documentation.  Here's a simple example which
illustrates several of my problems.

Suppose I want to have a regexp match against a string, and return all
the matching substrings in a vector of strings.

   regexp <- "[ab]+"
   strlist <- c( "abc", "dbabddadd", "aaa" )
   matches <- gregexpr(regexp,strlist)

With this input, I'd want to return list( list("ab"), list("ab", "a"),
list("aaa") ).

Now the matches object prints out as

   [[1]]
   [1] 1
   attr(,"match.length")
   [1] 2

   [[2]]
   [1] 2 7
   attr(,"match.length")
   [1] 3 1

   [[3]]
   [1] 1
   attr(,"match.length")
   [1] 3

which, if I'm interpreting this correctly, means that it is a list
(not a vector, because vectors can only have atomic elements) of three
elements, each of which is a vector of integers (the matching
positions) with an attribute match.length (the length of the
corresponding match), which is in turn a vector of integers.

Question: is there a more compact standard print format for this? It's
a bit disconcerting that printing the 2x2 list
list(list(1,2),list(3,4)) takes 16 lines while the corresponding 2x2
array takes 2 lines! (I guess that arrays are "more native").

Now, matches[[1]], the first element of matches, describes the matches
in the first string.  To extract those strings, I can write

   substr( strlist[[1]],
   matches[[1]],
   attr(matches[[1]],"match.length")+matches[[1]]-1 )

which correctly gives "ab".

Question: This looks awfully clumsy; is there some more idiomatic way
to do this, in particular to refer to the match.length attribute
without using a quoted string or the attr function?
attributes(matches[[1]])$match.length and
attributes(matches[[1]])[[1]] work, but seem even clumsier.

Question: R uses names like xxx.yyy in many places.  Is this just a
convention to represent spaces (the way most languages use "_"), or is
there some semantics attached to "."?

Question: Is it good practice in R to treat a string as a vector of
characters so that R's powerful vector operations can be used on it?
How would I do that?

Now suppose I want to list *all* the matches in matches[[2]].  I try:

   substr( strlist[[2]],
   matches[[2]],
   attr(matches[[2]],"match.length")+matches[[2]]-1 )

but only get the first one, so it seems that the recycling rule for
vectors doesn't apply here (same thing with [2] instead of [[2]]).
Where does recycling apply and not apply?

Question: Is there some operator (using promises?) to make
strlist[[2]] into a (lazy) infinite vector/list?

Now suppose I want to list *all* the matches in all the strings.  How
would I do that?  The naive way, substr(strlist,matches, ...) doesn't
work, partly because the attr operator doesn't distribute over lists
(I see why it can't, but...).

Thanks in advance for your patience with these very elementary questions,

  -s

Stavros Macrakis, Cambridge, MA

__
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] gridBase and new.page() / grid.newpage()

2008-08-10 Thread Peter Cowan
Paul,

The real case is a function where I'd want to allow end users to pass
an arbitrary plotting function to be a sub plot within a larger plot
(e.g. the code that does the density plots would actually be passed as
a parameter.  I adapted my example to reflect this.   I expect most of
my end users to be unfamiliar with grid, yet familiar with base
graphics.

Thanks,

Peter

Aplot <- function(){
par(plt = gridPLT(), new = TRUE)
grid.rect(gp=gpar(fill="light grey"))
dens <- density(rnorm(10))
plot.density(dens, axes = FALSE,
mar = c(0,0,0,0), main = "", xlab = "", ylab = "")
}

myplot <- function(subplot) {
   grid.newpage()
   plot.new()
   n <- 10
   datalayout <- grid.layout(ncol = 2, width = unit(c(1, 1/n),
c('null', 'null')))

   pushViewport(viewport(width = .8, height = .8, layout = datalayout))
   grid.rect(gp=gpar(col="grey"))

   for(i in 1:n) {
   pushViewport(viewport(
   y = i/n - 0.5 / n, x = 1,
   height = unit(1/n, 'npc'),
   width = unit(1/n, 'npc')))
   subplot()
   upViewport()
   }
   pushViewport(viewport(xscale = c(0, 1), layout.pos.col = 1))
   grid.rect(gp=gpar(fill="grey"))
   grid.points()
   upViewport()
   upViewport()
}

myplot(Aplot)
myplot(Aplot)

pdf()
myplot(Aplot)
myplot(Aplot)
dev.off()


On Sun, Aug 10, 2008 at 1:48 PM, Paul Murrell <[EMAIL PROTECTED]> wrote:
> Hi
>
>
> Peter Cowan wrote:
>> Hello all,
>>
>> I'm trying to write a function using the gridBase package.  I'd like
>> to push several base subplots to a larger plot constructed with grid.
>> However, I'm having trouble getting consistent results when running
>> the function when the plotting window (quartz) is closed, when it is
>> left open and the plot function is repeated to the same window, and
>> when the output is saved to a pdf, see the example below.  In the case
>> of the pdf plot pages are preceded by a blank page.  However, leaving
>> out either plot.new() or grid.newpage() each presents different
>> problems.  I looked through the R Graphics book and package vignette
>> but didn't see this particular issue addressed.
>
>
> There can be complications when both the 'graphics' package and the
> 'grid' package try to start a new page.
>
> Before trying to untangle this particular example, is it possible to
> side step the problem by drawing those density plots using a
> grid-compatible system such as either lattice or ggplot ?
>
> Or, if the "real" case is as simple as this, perhaps even just
> grid.lines() will do the job (?)
>
> Paul
>
>
>> Thanks in advance,
>>
>> Peter
>>
>> myplot <- function() {
>> grid.newpage()
>> plot.new()
>> n <- 10
>> datalayout <- grid.layout(ncol = 2, width = unit(c(1, 1/n),
>> c('null', 'null')))
>>
>> pushViewport(viewport(width = .8, height = .8, layout = datalayout))
>> grid.rect(gp=gpar(col="grey"))
>>
>> for(i in 1:n) {
>> pushViewport(viewport(
>> y = i/n - 0.5 / n, x = 1,
>> height = unit(1/n, 'npc'),
>> width = unit(1/n, 'npc')))
>> par(plt = gridPLT(), new = TRUE)
>> grid.rect(gp=gpar(fill="light grey"))
>> dens <- density(rnorm(10))
>> plot.density(dens, axes = FALSE,
>> mar = c(0,0,0,0), main = "", xlab = "", ylab = "")
>> upViewport()
>> }
>> pushViewport(viewport(xscale = c(0, 1), layout.pos.col = 1))
>> grid.rect(gp=gpar(fill="grey"))
>> grid.points()
>> upViewport()
>> upViewport()
>> }
>>
>> myplot()
>> myplot()
>>
>> pdf()
>> myplot()
>> myplot()
>> dev.off()
>>
>> __
>> 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.
>
> --
> Dr Paul Murrell
> Department of Statistics
> The University of Auckland
> Private Bag 92019
> Auckland
> New Zealand
> 64 9 3737599 x85392
> [EMAIL PROTECTED]
> http://www.stat.auckland.ac.nz/~paul/
>

__
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] detect if data is normal or skewed (without a boxplot)

2008-08-10 Thread Felipe Carrillo
Hello all:
Is there a way to detect in R if a dataset is normally distributed or skewed 
without graphically seeing it? The reason I want to be able to do this is 
because I have developed and application with Visual Basic where Word,Access 
and Excel "talk" to each other and I want to integrate R to this application to 
estimate confidence intervals on fish sizes (mm). I basically want to automate 
the process from Excel by detecting if my data has a normal distribution then 
use t.test, but if my data is skewed then use wilcox.test. Something like the 
pseudo code below:

fishlength <- c(35,32,37,39,42,45,37,36,35,34,40,42,41,50)
   if fishlength= "normally distributed" then
 t.test(fishlength)
else
wilcox.text(fishlength)

I hope this isn't very confussing
 

Felipe D. Carrillo  
Supervisory Fishery Biologist  
Department of the Interior  
US Fish & Wildlife Service  
California, USA

__
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] grid layout scaling viewport width based solely on height

2008-08-10 Thread Peter Cowan
Paul,

That is exactly what I was looking for.  Thank you!

Peter

On Sun, Aug 10, 2008 at 1:41 PM, Paul Murrell <[EMAIL PROTECTED]> wrote:
> Hi
>
>
> Peter Cowan wrote:
>> Paul,
>>
>> On Wed, Aug 6, 2008 at 1:40 PM, Paul Murrell <[EMAIL PROTECTED]> wrote:
 I'm trying to write a function that produces a main plotting region
 with several square plots along the right side.  Ideally the size of
 right side plots will scale only with the height of the entire plot,
 yet never overlap with another secondary plot.  The following two
 snippets get close, however, as I resize the plot horizontally the
 right side plots (green squares) get smaller whereas I'd like them to
 remain the same size.  It seems the answer lies in setting the layout
 width for the side plot column in a clever way that I haven't been
 able to discover.  Any suggestions on how to achieve that effect or
 other improvements to the below code are most welcome.

 Hopefully, my explanation makes my goal clear.  Also note, the real
 application is a function that will have arbitrary numbers of side
 plots.
>>
>>> Sorry, I'm not completely sure what you want to end up with, but do
>>> either of the following come close ?
>>
>> Thanks for the response.  Of the two suggestions the latter is close
>> to what I was hoping four.  However, ideally there would be no gap
>> between the side plots when the plot is 'tall'.  Phrased another way,
>> as the total plot gets larger, I would like the second column of the
>> lay1 to take up a greater proportion of the figure. So that a resize
>> in the Y, changes the allocation of column space in the X.  I don't
>> suppose that is possible, is it?
>
>
> It is, with a little more work ...
>
> # Side plots square and take up as much room as they are allowed
> # A special grob that is not drawn, but has the required height for the
> # side plots
> squareGrob <- grob(height=unit(.1, "npc"),
>   cl="squareGrob")
> # A method for determining the width of the special grob based
> # on its height.
> # The important point is that this calculation will get redone
> # every time the squareGrob is asked for its width.
> widthDetails.squareGrob <- function(x) {
>  convertUnit(unit(.1, "npc"),
>  "npc",
>  "y", "dimension",
>  "x", "dimension")
> }
> # A layout where the width of the second column is based
> # on the width of the special grob (first column width
> # takes up whatever width is left over)
> lay1 <- grid.layout(10, 2,
>widths=unit.c(unit(1, "null"),
>  grobWidth(squareGrob)),
>heights=unit(.1, "npc"))
>
> ... Once that squareGrob is defined, you can use it anywhere, so that's
> a one-off cost.  The following code shows the resulting layout ...
>
> # grid.newpage()
> pushViewport(viewport(layout=lay1))
>
> pushViewport(viewport(layout.pos.col=1))
> grid.rect(gp=gpar(fill="grey"))
> popViewport()
>
> for (i in 1:10) {
>pushViewport(viewport(layout.pos.col=2,
>  layout.pos.row=i))
>grid.rect(gp=gpar(fill="light grey"))
>popViewport()
> }
>
> ... does that do the job ?
>
> Paul
>
>
>> Cheers
>>
>> Peter
>>
>>> # Side plots square and attached to each other
>>> # With "tall" plot, get gaps top and bottom
>>> # With "wide" plot, get gap on the right
>>> lay1 <- grid.layout(1, 2, widths=c(10, 1))
>>> lay2 <- grid.layout(10, 1, respect=TRUE, just="left")
>>>
>>> # grid.newpage()
>>> pushViewport(viewport(width=.8, height=.8, layout=lay1))
>>> grid.rect(gp=gpar(col="grey"))
>>>
>>> pushViewport(viewport(layout.pos.col=1))
>>> grid.rect(gp=gpar(fill="grey"))
>>> popViewport()
>>>
>>> pushViewport(viewport(layout.pos.col=2,
>>>  layout=lay2))
>>> for (i in 1:10) {
>>>pushViewport(viewport(layout.pos.row=i))
>>>grid.rect(gp=gpar(fill="light grey"))
>>>popViewport()
>>> }
>>> popViewport()
>>>
>>>
>>> # Side plots square and separate from each other
>>> # With "tall" plot, get gaps between vertically
>>> # With "wide" plot, get gap on the right
>>> lay1 <- grid.layout(10, 2, widths=c(10, 1))
>>>
>>> # grid.newpage()
>>> pushViewport(viewport(width=.8, height=.8, layout=lay1))
>>> grid.rect(gp=gpar(col="grey"))
>>>
>>> pushViewport(viewport(layout.pos.col=1))
>>> grid.rect(gp=gpar(fill="grey"))
>>> popViewport()
>>>
>>> for (i in 1:10) {
>>>pushViewport(viewport(layout.pos.col=2,
>>>  layout.pos.row=i))
>>>pushViewport(viewport(x=0, width=unit(1, "snpc"),
>>>  height=unit(1, "snpc"), just="left"))
>>>grid.rect(gp=gpar(fill="light grey"))
>>>popViewport(2)
>>> }
>>>
>>> Paul
>>>
>
> --
> Dr Paul Murrell
> Department of Statistics
> The University of Auckland
> Private Bag 92019
> Auckland
> New Zealand
> 64 9 3737599 x85392
> [EMAIL PROTECTED]
> http://www.stat.auckland.ac.nz/~paul/
>

__

[R] using IF command

2008-08-10 Thread Gareth Campbell
Hey team,

If I have a matrix:

1, 2,
3, 4,
4, 0,
1, 3,
0, 3

2 columns.

I want to write an if command that looks at (in this case) row 3 and looks
to see if either [3,1] or [3,2] has a zero in it.  IF it does have a zero I
want the zero to be placed in another matrix in the same position.  I know
how to do the latter part, I just can't get the if command to look at both
cells and deal with them separately.

Thanks

-- 
Gareth Campbell
PhD Candidate
The University of Auckland

P +649 815 3670
M +6421 256 3511
E [EMAIL PROTECTED]
[EMAIL PROTECTED]

[[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] Reshape set operations?

2008-08-10 Thread hadley wickham
Hi Kevin,

I think easiest way would be to create a single dataset with both
years in, and then work from that:

t2008$year <- 2008
t2007$year <- 2007

tall <- rbind(t2007, t2008)
mall <- melt(tall,
id.var=c("DayOfYear","Category","SubCategory","Sku", "year"),
measure.var=c("Quantity")

cast(mall, DayOfYear ~ variable | Sku, sum)
cast(mall, Year + DayOfYear ~ variable | Sku, sum)

Hadley


On Sat, Aug 9, 2008 at 11:44 AM,  <[EMAIL PROTECTED]> wrote:
> I have mange to use the library reshape to give me data structures that I 
> want. Specifically:
>
> m2008 <- melt(t2008, id.var=c("DayOfYear","Category","SubCategory","Sku"), 
> measure.var=c("Quantity"))
>  m2007 <- melt(t2007, id.var=c("DayOfYear","Category","SubCategory","Sku"), 
> measure.var=c("Quantity"))
>
>  r2008 <- cast(m2008, DayOfYear ~ variable | Sku, sum)
>  r2007 <- cast(m2007, DayOfYear ~ variable | Sku, sum)
>
> Now I would like to union the two lists. So I start out with an empty master 
> list that will contain (when I am done) the merge (union) of r2008 and r2007. 
> By "union" I mean that if the Sku exists in r2007 and r2008 I would like to 
> create a new data frame that has the lists for DayOfYear and Quantity 
> "merged" and append it to 'master'. If the Sku is not common to both objects 
> then just copy or append to the 'master'.
>
> Is it possible to come up with an expression and aggregate function that will 
> do this? Is this better handle with aggregate functions or lapply? Being new 
> to 'R' it is hard for me to tell.
>
> Thank you.
>
> Kevin
>
> __
> 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.
>



-- 
http://had.co.nz/

__
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] R 2,7.2 is scheduled for August 25

2008-08-10 Thread Peter Dalgaard

This is to announce that we plan to release R version 2.7.2 on Monday,
August 25, 2008.

Release procedures start Friday August 15 (when we get back from useR).

The source tarballs will be made available daily (barring build
troubles) and the tarballs can be picked up at

http://cran.r-project.org/src/base-prerelease/

a little later.

Binary builds are expected to appear starting Monday 18 at the latest.

For the Core Team
Peter Dalgaard


--
  O__   Peter Dalgaard Øster Farimagsgade 5, Entr.B
 c/ /'_ --- Dept. of Biostatistics PO Box 2099, 1014 Cph. K
(*) \(*) -- University of Copenhagen   Denmark  Ph:  (+45) 35327918
~~ - ([EMAIL PROTECTED])  FAX: (+45) 35327907

___
[EMAIL PROTECTED] mailing list
https://stat.ethz.ch/mailman/listinfo/r-announce

__
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] Converting nested "for" loops to an "apply" function(s)

2008-08-10 Thread Kurt Newman

Dan,

Thank you very much for your comments and function definition code!!  Responses 
like yours make the r-help community amazing!!

Kurt 





> Date: Sun, 10 Aug 2008 12:08:42 +0100
> From: [EMAIL PROTECTED]
> To: [EMAIL PROTECTED]
> CC: r-help@r-project.org
> Subject: Re: [R] Converting nested "for" loops to an "apply" function(s)
> 
> On Sat, Aug 09, 2008 at 08:53:00PM -0400, Kurt Newman wrote:
>> 
>> Resending.  Previous message was truncated.  Sorry for possible confusion.
>> 
>> 
>>> From: [EMAIL PROTECTED]
>>> To: r-help@r-project.org
>>> Date: Sat, 9 Aug 2008 18:25:47 -0400
>>> Subject: [R] Converting nested "for" loops to an "apply" function(s)
>>> 
>>> 
>>> Hello,
>>> 
> 
>>> I would like to know more about how to use the "apply" family and
>>> have attempted to convert nested "for" loops in example code from
>>> Contributed Documentation ("The Friendly Beginners' R Course? by
>>> Toby Marthews (ZIP, 2007-03-01)") to an "apply" function(s).  The
>>> relevant code is:
> 
>>> 
>>> distances=c(51,65,175,196,197,125,10,56)#distances of 8 houses from the 
>>> town centre in m
>>> bearings=c(10,8,210,25,74,128,235,335)  #bearings of the houses in 
>>> degrees
>>> 
>>> xpos=distances*sin(bearings*pi/180) #in sin and cos the argument 
>>> MUST be in radians
>>> ypos=distances*cos(bearings*pi/180) 
>>> 
>>> numpoints=length(distances)
>>> nnd=rep(sqrt(2*400*400),times=numpoints)#start with the maximum 
>>> possible distance
>>> for (i in 1:numpoints) {
>>>  for (j in 1:numpoints) {
>>>   if (i!=j) {   
>>>diffx=abs(xpos[i]-xpos[j])
>>>diffy=abs(ypos[i]-ypos[j])
>>>nd=sqrt((diffx^2)+(diffy^2))
>>>if (nd < nnd[i]) {nnd[i]=nd}
>>   }
>>  }
>> }
>> print(data.frame(xpos,ypos,nnd))
>> 
> 
>> My attempts to convert the nested "for" loops to an "apply"
>>  function(s) have not been successful.  I would like to know how to
>>  convert the code to increase my knowledge of R programming and to
>>  evaluate operational efficiency of the different strategies.
> 
> Hi Kurt,
> 
> It's not just the apply() family that help in vectorising problems. In
> this case, outer() is also going to be helpful, as well as remembering
> that all the standard arithmetical operators automatically
> vectorise. I would use something like this:
> 
> nearest.neighbour.distance <- function(xpos, ypos) {
> xdist <- abs(outer(xpos, xpos, "-"))
> ydist <- abs(outer(ypos, ypos, "-"))
> dist <- sqrt(xdist^2 + ydist^2)
> diag(dist) <- NA
> apply(dist, 1, min, na.rm=TRUE)
> }
> 
> Dan
> 
> 
>> 
>> Thank you in advance for your comments / suggestions.
>> 
>> Kurt Newman
>> 
>> 
>> 
>>> __
>>> 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-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] RPro

2008-08-10 Thread S Ellison
>>> Stephan Kolassa <[EMAIL PROTECTED]> 08/10/08 8:41 PM >>>
>I like RSeek:
>http://www.rseek.org/
The burning question is why an audio compay would be running a web
search engine for an open source statistics package...??!


***
This email and any attachments are confidential. Any use...{{dropped:8}}

__
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] RPro

2008-08-10 Thread Stephan Kolassa

Hi,

I like RSeek:
http://www.rseek.org/

And of course searching the R-help list archives, e.g., via
http://www.nabble.com/R-f13819.html

Good hunting!
Stephan


Carl Witthoft schrieb:
One thing I'll say:  it's going to be much easier to Google for 
references to "Rstat" than to "R" .
I've been tempted to start a movement to rename "R" something like 
"Ratistics" (or "RatStatPack" :-) ) just so it's locatable via search 
engines.


That said, does anyone have any techniques for Googling for info on some 
particular R functionality?  I've had some luck with the term "R-help" 
or "R-sig" but that leaves out an awful lot of websites.



Carl

__
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] Differential Equations there use in R (population modeling)

2008-08-10 Thread stephen sefick
e1 <- function(x,b,t){
d<-(x)*(b^t)
plot(d)
}

e1(2, 2,seq(from=0, to=6, by=1))

Is there a way to do this with a change in time.  I would like to use
differential equations.  I am trying to model
a population with an initial value, fecundity per time step, and a
death rate.  The above simply shows an exponential growth rate.  I
would like to model species response like the famous exponential
growth rate leveling off at a carrying capacity with all of the three
input variables being on a slider from TeachingDemos package
population# = (initialvalue @ t) - (death rate) + (fecundtity per individual) dt
any ideas

Stephen
-- 
Let's not spend our time and resources thinking about things that are
so little or so large that all they really do for us is puff us up and
make us feel like gods. We are mammals, and have not exhausted the
annoying little problems of being mammals.

-K. Mullis

__
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] Again question about filter()

2008-08-10 Thread Gabor Grothendieck
The first three values are:

> filter <- c(0.1, 0.5, 1, 0.5)
> init <- 1:4
> filter %*% init + 1
 [,1]
[1,]  7.1
> filter %*% c(7.1, init[1:3]) + 2
 [,1]
[1,] 6.71
> filter %*% c(6.71, 7.1, init[1:2]) + 3
  [,1]
[1,] 9.221


On Sun, Aug 10, 2008 at 12:47 PM, Sergey Goriatchev <[EMAIL PROTECTED]> wrote:
> Hello,
>
> I thought I understood filter() with the help from Prof. Grothendieck,
> but I guess I did not.
> For example, how does this work:
>
>  filter(1:10, c(0.1, 0.5, 1, 0.5), "recursive", init=c(1,2,3,4))
> Time Series:
> Start = 1
> End = 10
> Frequency = 1
>  [1]   7.1   6.71000   9.22100  15.87710  21.45821  28.66037
> 41.08274  55.83522  74.51437 100.78197
>
> If I understand it correctly, the time series, together with initial
> values, looks like
> 1,2,3,4,1,2,3,4,5,6,7,8,9,10
>
> The first value is calculated as 1*0.1+2*0.5+3*1+4*0.5+1=7.1,
> where the first four arguments are initial values times coefficients,
> and the last argument is the first value
> of the timeseries, that is 1.
> But how are the consecutive values calculated?
> Totally at a loss. Please, help.
>
> /Sergey
>
> --
> I'm not young enough to know everything. /Oscar Wilde
> Experience is one thing you can't get for nothing. /Oscar Wilde
> When you are finished changing, you're finished. /Benjamin Franklin
> Tell me and I forget, teach me and I remember, involve me and I learn.
> /Benjamin Franklin
> Luck is where preparation meets opportunity. /George Patten
>
> __
> 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] help using outer function

2008-08-10 Thread warthog29


Thanks Dan. You did much more than just answer my question. 

Sincerely,


Dan Davison wrote:
> 
> On Sun, Aug 10, 2008 at 06:00:21PM +0100, Dan Davison wrote:
>> On Sun, Aug 10, 2008 at 09:02:59AM -0700, warthog29 wrote:
>> > 
>> > Hi,
>> > I would like to use the R's outer function on y below so that I can
>> subtract
>> > elements from each other. The resulting dataframe is symmetric, save
>> for the
>>^^
>> outer() returns a matrix, not a data frame.
>> 
>> > negative signs on the other half of the numbers. I would like to get
>> only
>> > half of the dataframe. Here is the code I wrote (it is returning only
>> the
>> > first line of the all elements I want. Please help). 
>> > y<-c(4,4,3.9,3.8,3.7,3.6,3.5,3.5,3.5,3.3,3.2,3.2)
>> > 
>> > b<-outer(y,y,"-")
>> 
>> > b<-as.matrix(by)
>> 
>> I assume that line was supposed to be b<-as.matrix(by). In any case
>  
> Hmm, I didn't really clarify things there. I meant
> b<-as.matrix(b). But anyway, not needed.
> 
>> you don't need it; b is a matrix already.
>> 
>> > # I want to keep the elements:
>> > #b[1,2:12],
>> > #b[2,3:12],
>> > #.until
>> > #b[11,12:12].
>> 
>> Use upper.tri() to get the upper-triangle:
>> 
>>  b[upper.tri(b, diag=FALSE)]
>>  [1] 0.0 0.1 0.1 0.2 0.2 0.1 0.3 0.3 0.2 0.1 0.4 0.4 0.3 0.2 0.1 0.5 0.5
>> 0.4 0.3
>> [20] 0.2 0.1 0.5 0.5 0.4 0.3 0.2 0.1 0.0 0.5 0.5 0.4 0.3 0.2 0.1 0.0 0.0
>> 0.7 0.7
>> [39] 0.6 0.5 0.4 0.3 0.2 0.2 0.2 0.8 0.8 0.7 0.6 0.5 0.4 0.3 0.3 0.3 0.1
>> 0.8 0.8
>> [58] 0.7 0.6 0.5 0.4 0.3 0.3 0.3 0.1 0.0
>> 
>> Or perhaps you want to knock out the negative entries, but still keep the
>> matrix structure:
>> 
>>  b[lower.tri(b)] <- NA
>> 
>> or perhaps you wanted 
>> 
>> b <- abs(outer(y,y,"-"))
>> 
>> in the first place?
>> 
>> > #Here is the function I wrote to get half of matrix:
>> > 
>> > wk<-function(p){
>> > for (i in 2:p){
>> > ri<-b[i-1,i:p]
>> > return(ri)
>> > }
>> > }
>> > wk(12)
>> > #[1] 0.0 0.1 0.2 0.3 0.4 0.5 0.5 0.5 0.7 0.8 0.8
>> 
>> I think you were intending this function to be something like this
>> 
>> wk<-function(p){
>> ri <- NULL
>> for (i in 2:p){
>> ri<-c(ri, b[i-1,i:p])
>> }
>> return(ri)
>> }
>> 
>> Note that this function will give a different result from upper.tri(),
>> because you are concatenating elements in the *rows* of the matrix,
>> whereas the way matrices are represented in R has consecutive elements
>> running down the columns. I.e. look at
>> 
>> > A <- matrix(nrow=2,ncol=2)
>> > A
>>  [,1] [,2]
>> [1,]   NA   NA
>> [2,]   NA   NA
>> > A[] <- 1:4
>> > A
>>  [,1] [,2]
>> [1,]13
>> [2,]24
>> 
>> Dan
>> 
>> > 
>> > As you can see, it is only returning the first line. I would like other
>> > corresponding elements too, to be found in row 2 to 12. Thanks. 
>> > -- 
>> > View this message in context:
>> http://www.nabble.com/help-using-outer-function-tp18914432p18914432.html
>> > Sent from the R help mailing list archive at Nabble.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.
> 
> __
> 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.
> 
> 

-- 
View this message in context: 
http://www.nabble.com/help-using-outer-function-tp18914432p18915298.html
Sent from the R help mailing list archive at Nabble.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] customizing the axis (adding labels)

2008-08-10 Thread Jörg Groß


Am 10.08.2008 um 18:53 schrieb stephen sefick:


the xaxt="n" needs to be inside of the plot command otherwise you can
never plot the x axis- I think.


Ah, ok, thanks!
Now it works fine.

Here a complete example of what I wanted to plot:


par(bty="n", mar=c(10, 10, 3, 3))
plot(c(1,2), c(50,60), ylim=c(40,70), xlim=c(0,3), xaxt="n")
dispbars(1,50,5)
dispbars(2,60,5)
axis(1, at=c(1,2), labels=c("group 1","group 2"))





On Sun, Aug 10, 2008 at 12:51 PM, stephen sefick <[EMAIL PROTECTED]>  
wrote:

j = c(5,6)
f = c(1,2)
plot(f,j, xaxt="n")
axis(1, at=c(1,2), labels=c("group1", "group2"))

On Sun, Aug 10, 2008 at 12:09 PM, Jörg Groß <[EMAIL PROTECTED] 
malerei.de> wrote:


Am 10.08.2008 um 17:46 schrieb stephen sefick:

Would you provide reproducible code because form your example it  
looks
like you are trying to label a scatterplot with just two lables -  
this
is your boxplot from yesterday?  If so look into the ?boxplot and  
it

will tell you some answers


No, what I want is to plot the mean for two different groups.
So that I get group 1 and 2 on the x-axis and also label it like  
that.






On Sun, Aug 10, 2008 at 11:29 AM, Jörg Groß <[EMAIL PROTECTED] 
malerei.de>

wrote:


Hi,

I want to customize the x-axis.

I tried that:
par(bty="n", xaxt="n")
so that the x-axis is supressed.

then I tried to plot two variables and add a customized x-axis:
plot(x, y)
axis(1, at=c(1,2), labels=c("group1", "group2"))

but the axis is not added to the plot.

I don't understand why..
And how then can I customize the axis?
[[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.





--
Let's not spend our time and resources thinking about things that  
are
so little or so large that all they really do for us is puff us  
up and

make us feel like gods. We are mammals, and have not exhausted the
annoying little problems of being mammals.

  -K. Mullis


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





--
Let's not spend our time and resources thinking about things that are
so little or so large that all they really do for us is puff us up  
and

make us feel like gods. We are mammals, and have not exhausted the
annoying little problems of being mammals.

  -K. Mullis





--
Let's not spend our time and resources thinking about things that are
so little or so large that all they really do for us is puff us up and
make us feel like gods. We are mammals, and have not exhausted the
annoying little problems of being mammals.

-K. Mullis


__
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] help using outer function

2008-08-10 Thread Dan Davison
On Sun, Aug 10, 2008 at 06:00:21PM +0100, Dan Davison wrote:
> On Sun, Aug 10, 2008 at 09:02:59AM -0700, warthog29 wrote:
> > 
> > Hi,
> > I would like to use the R's outer function on y below so that I can subtract
> > elements from each other. The resulting dataframe is symmetric, save for the
>^^
> outer() returns a matrix, not a data frame.
> 
> > negative signs on the other half of the numbers. I would like to get only
> > half of the dataframe. Here is the code I wrote (it is returning only the
> > first line of the all elements I want. Please help). 
> > y<-c(4,4,3.9,3.8,3.7,3.6,3.5,3.5,3.5,3.3,3.2,3.2)
> > 
> > b<-outer(y,y,"-")
> 
> > b<-as.matrix(by)
> 
> I assume that line was supposed to be b<-as.matrix(by). In any case
 
Hmm, I didn't really clarify things there. I meant
b<-as.matrix(b). But anyway, not needed.

> you don't need it; b is a matrix already.
> 
> > # I want to keep the elements:
> > #b[1,2:12],
> > #b[2,3:12],
> > #.until
> > #b[11,12:12].
> 
> Use upper.tri() to get the upper-triangle:
> 
>  b[upper.tri(b, diag=FALSE)]
>  [1] 0.0 0.1 0.1 0.2 0.2 0.1 0.3 0.3 0.2 0.1 0.4 0.4 0.3 0.2 0.1 0.5 0.5 0.4 
> 0.3
> [20] 0.2 0.1 0.5 0.5 0.4 0.3 0.2 0.1 0.0 0.5 0.5 0.4 0.3 0.2 0.1 0.0 0.0 0.7 
> 0.7
> [39] 0.6 0.5 0.4 0.3 0.2 0.2 0.2 0.8 0.8 0.7 0.6 0.5 0.4 0.3 0.3 0.3 0.1 0.8 
> 0.8
> [58] 0.7 0.6 0.5 0.4 0.3 0.3 0.3 0.1 0.0
> 
> Or perhaps you want to knock out the negative entries, but still keep the 
> matrix structure:
> 
>  b[lower.tri(b)] <- NA
> 
> or perhaps you wanted 
> 
> b <- abs(outer(y,y,"-"))
> 
> in the first place?
> 
> > #Here is the function I wrote to get half of matrix:
> > 
> > wk<-function(p){
> > for (i in 2:p){
> > ri<-b[i-1,i:p]
> > return(ri)
> > }
> > }
> > wk(12)
> > #[1] 0.0 0.1 0.2 0.3 0.4 0.5 0.5 0.5 0.7 0.8 0.8
> 
> I think you were intending this function to be something like this
> 
> wk<-function(p){
> ri <- NULL
> for (i in 2:p){
> ri<-c(ri, b[i-1,i:p])
> }
> return(ri)
> }
> 
> Note that this function will give a different result from upper.tri(),
> because you are concatenating elements in the *rows* of the matrix,
> whereas the way matrices are represented in R has consecutive elements
> running down the columns. I.e. look at
> 
> > A <- matrix(nrow=2,ncol=2)
> > A
>  [,1] [,2]
> [1,]   NA   NA
> [2,]   NA   NA
> > A[] <- 1:4
> > A
>  [,1] [,2]
> [1,]13
> [2,]24
> 
> Dan
> 
> > 
> > As you can see, it is only returning the first line. I would like other
> > corresponding elements too, to be found in row 2 to 12. Thanks. 
> > -- 
> > View this message in context: 
> > http://www.nabble.com/help-using-outer-function-tp18914432p18914432.html
> > Sent from the R help mailing list archive at Nabble.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.

__
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] RPro

2008-08-10 Thread Jonathan Baron
On 08/10/08 12:57, Carl Witthoft wrote:
> One thing I'll say:  it's going to be much easier to Google for 
> references to "Rstat" than to "R" .
> I've been tempted to start a movement to rename "R" something like 
> "Ratistics" (or "RatStatPack" :-) ) just so it's locatable via search 
> engines.

If you type R in the Google search box, with nothing else, it takes
you right to R's main page.  This was pointed out to me in 2000 by a
math professor colleague, who said that it was a result of Google's
extremely clever algorithm.

> That said, does anyone have any techniques for Googling for info on some 
> particular R functionality?  I've had some luck with the term "R-help" 
> or "R-sig" but that leaves out an awful lot of websites.

RSiteSearch()

is one.  This is a function that mimics what happens at:
http://finzi.psych.upenn.edu/nmz.html

-- 
Jonathan Baron, Professor of Psychology, University of Pennsylvania
Home page: http://www.sas.upenn.edu/~baron

__
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] help using outer function

2008-08-10 Thread Dan Davison
On Sun, Aug 10, 2008 at 09:02:59AM -0700, warthog29 wrote:
> 
> Hi,
> I would like to use the R's outer function on y below so that I can subtract
> elements from each other. The resulting dataframe is symmetric, save for the
   ^^
outer() returns a matrix, not a data frame.

> negative signs on the other half of the numbers. I would like to get only
> half of the dataframe. Here is the code I wrote (it is returning only the
> first line of the all elements I want. Please help). 
> y<-c(4,4,3.9,3.8,3.7,3.6,3.5,3.5,3.5,3.3,3.2,3.2)
> 
> b<-outer(y,y,"-")

> b<-as.matrix(by)

I assume that line was supposed to be b<-as.matrix(by). In any case
you don't need it; b is a matrix already.

> # I want to keep the elements:
> #b[1,2:12],
> #b[2,3:12],
> #.until
> #b[11,12:12].

Use upper.tri() to get the upper-triangle:

 b[upper.tri(b, diag=FALSE)]
 [1] 0.0 0.1 0.1 0.2 0.2 0.1 0.3 0.3 0.2 0.1 0.4 0.4 0.3 0.2 0.1 0.5 0.5 0.4 0.3
[20] 0.2 0.1 0.5 0.5 0.4 0.3 0.2 0.1 0.0 0.5 0.5 0.4 0.3 0.2 0.1 0.0 0.0 0.7 0.7
[39] 0.6 0.5 0.4 0.3 0.2 0.2 0.2 0.8 0.8 0.7 0.6 0.5 0.4 0.3 0.3 0.3 0.1 0.8 0.8
[58] 0.7 0.6 0.5 0.4 0.3 0.3 0.3 0.1 0.0

Or perhaps you want to knock out the negative entries, but still keep the 
matrix structure:

 b[lower.tri(b)] <- NA

or perhaps you wanted 

b <- abs(outer(y,y,"-"))

in the first place?

> #Here is the function I wrote to get half of matrix:
> 
> wk<-function(p){
> for (i in 2:p){
> ri<-b[i-1,i:p]
> return(ri)
> }
> }
> wk(12)
> #[1] 0.0 0.1 0.2 0.3 0.4 0.5 0.5 0.5 0.7 0.8 0.8

I think you were intending this function to be something like this

wk<-function(p){
ri <- NULL
for (i in 2:p){
ri<-c(ri, b[i-1,i:p])
}
return(ri)
}

Note that this function will give a different result from upper.tri(),
because you are concatenating elements in the *rows* of the matrix,
whereas the way matrices are represented in R has consecutive elements
running down the columns. I.e. look at

> A <- matrix(nrow=2,ncol=2)
> A
 [,1] [,2]
[1,]   NA   NA
[2,]   NA   NA
> A[] <- 1:4
> A
 [,1] [,2]
[1,]13
[2,]24

Dan

> 
> As you can see, it is only returning the first line. I would like other
> corresponding elements too, to be found in row 2 to 12. Thanks. 
> -- 
> View this message in context: 
> http://www.nabble.com/help-using-outer-function-tp18914432p18914432.html
> Sent from the R help mailing list archive at Nabble.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.

__
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] customizing the axis (adding labels)

2008-08-10 Thread stephen sefick
the xaxt="n" needs to be inside of the plot command otherwise you can
never plot the x axis- I think.

On Sun, Aug 10, 2008 at 12:51 PM, stephen sefick <[EMAIL PROTECTED]> wrote:
> j = c(5,6)
> f = c(1,2)
> plot(f,j, xaxt="n")
> axis(1, at=c(1,2), labels=c("group1", "group2"))
>
> On Sun, Aug 10, 2008 at 12:09 PM, Jörg Groß <[EMAIL PROTECTED]> wrote:
>>
>> Am 10.08.2008 um 17:46 schrieb stephen sefick:
>>
>>> Would you provide reproducible code because form your example it looks
>>> like you are trying to label a scatterplot with just two lables - this
>>> is your boxplot from yesterday?  If so look into the ?boxplot and it
>>> will tell you some answers
>>
>> No, what I want is to plot the mean for two different groups.
>> So that I get group 1 and 2 on the x-axis and also label it like that.
>>
>>
>>>
>>>
>>> On Sun, Aug 10, 2008 at 11:29 AM, Jörg Groß <[EMAIL PROTECTED]>
>>> wrote:

 Hi,

 I want to customize the x-axis.

 I tried that:
 par(bty="n", xaxt="n")
 so that the x-axis is supressed.

 then I tried to plot two variables and add a customized x-axis:
 plot(x, y)
 axis(1, at=c(1,2), labels=c("group1", "group2"))

 but the axis is not added to the plot.

 I don't understand why..
 And how then can I customize the axis?
  [[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.

>>>
>>>
>>>
>>> --
>>> Let's not spend our time and resources thinking about things that are
>>> so little or so large that all they really do for us is puff us up and
>>> make us feel like gods. We are mammals, and have not exhausted the
>>> annoying little problems of being mammals.
>>>
>>>-K. Mullis
>>
>> __
>> 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.
>>
>
>
>
> --
> Let's not spend our time and resources thinking about things that are
> so little or so large that all they really do for us is puff us up and
> make us feel like gods. We are mammals, and have not exhausted the
> annoying little problems of being mammals.
>
>-K. Mullis
>



-- 
Let's not spend our time and resources thinking about things that are
so little or so large that all they really do for us is puff us up and
make us feel like gods. We are mammals, and have not exhausted the
annoying little problems of being mammals.

-K. Mullis

__
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] RPro

2008-08-10 Thread Carl Witthoft
One thing I'll say:  it's going to be much easier to Google for 
references to "Rstat" than to "R" .
I've been tempted to start a movement to rename "R" something like 
"Ratistics" (or "RatStatPack" :-) ) just so it's locatable via search 
engines.


That said, does anyone have any techniques for Googling for info on some 
particular R functionality?  I've had some luck with the term "R-help" 
or "R-sig" but that leaves out an awful lot of websites.



Carl

__
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] customizing the axis (adding labels)

2008-08-10 Thread stephen sefick
j = c(5,6)
f = c(1,2)
plot(f,j, xaxt="n")
axis(1, at=c(1,2), labels=c("group1", "group2"))

On Sun, Aug 10, 2008 at 12:09 PM, Jörg Groß <[EMAIL PROTECTED]> wrote:
>
> Am 10.08.2008 um 17:46 schrieb stephen sefick:
>
>> Would you provide reproducible code because form your example it looks
>> like you are trying to label a scatterplot with just two lables - this
>> is your boxplot from yesterday?  If so look into the ?boxplot and it
>> will tell you some answers
>
> No, what I want is to plot the mean for two different groups.
> So that I get group 1 and 2 on the x-axis and also label it like that.
>
>
>>
>>
>> On Sun, Aug 10, 2008 at 11:29 AM, Jörg Groß <[EMAIL PROTECTED]>
>> wrote:
>>>
>>> Hi,
>>>
>>> I want to customize the x-axis.
>>>
>>> I tried that:
>>> par(bty="n", xaxt="n")
>>> so that the x-axis is supressed.
>>>
>>> then I tried to plot two variables and add a customized x-axis:
>>> plot(x, y)
>>> axis(1, at=c(1,2), labels=c("group1", "group2"))
>>>
>>> but the axis is not added to the plot.
>>>
>>> I don't understand why..
>>> And how then can I customize the axis?
>>>  [[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.
>>>
>>
>>
>>
>> --
>> Let's not spend our time and resources thinking about things that are
>> so little or so large that all they really do for us is puff us up and
>> make us feel like gods. We are mammals, and have not exhausted the
>> annoying little problems of being mammals.
>>
>>-K. Mullis
>
> __
> 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.
>



-- 
Let's not spend our time and resources thinking about things that are
so little or so large that all they really do for us is puff us up and
make us feel like gods. We are mammals, and have not exhausted the
annoying little problems of being mammals.

-K. Mullis

__
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] Again question about filter()

2008-08-10 Thread Sergey Goriatchev
Hello,

I thought I understood filter() with the help from Prof. Grothendieck,
but I guess I did not.
For example, how does this work:

 filter(1:10, c(0.1, 0.5, 1, 0.5), "recursive", init=c(1,2,3,4))
Time Series:
Start = 1
End = 10
Frequency = 1
 [1]   7.1   6.71000   9.22100  15.87710  21.45821  28.66037
41.08274  55.83522  74.51437 100.78197

If I understand it correctly, the time series, together with initial
values, looks like
1,2,3,4,1,2,3,4,5,6,7,8,9,10

The first value is calculated as 1*0.1+2*0.5+3*1+4*0.5+1=7.1,
where the first four arguments are initial values times coefficients,
and the last argument is the first value
of the timeseries, that is 1.
But how are the consecutive values calculated?
Totally at a loss. Please, help.

/Sergey

-- 
I'm not young enough to know everything. /Oscar Wilde
Experience is one thing you can't get for nothing. /Oscar Wilde
When you are finished changing, you're finished. /Benjamin Franklin
Tell me and I forget, teach me and I remember, involve me and I learn.
/Benjamin Franklin
Luck is where preparation meets opportunity. /George Patten

__
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 using outer function

2008-08-10 Thread warthog29

Hi,
I would like to use the R's outer function on y below so that I can subtract
elements from each other. The resulting dataframe is symmetric, save for the
negative signs on the other half of the numbers. I would like to get only
half of the dataframe. Here is the code I wrote (it is returning only the
first line of the all elements I want. Please help). 
y<-c(4,4,3.9,3.8,3.7,3.6,3.5,3.5,3.5,3.3,3.2,3.2)

b<-outer(y,y,"-")
b<-as.matrix(by)
# I want to keep the elements:
#b[1,2:12],
#b[2,3:12],
#.until
#b[11,12:12].
#Here is the function I wrote to get half of matrix:

wk<-function(p){
for (i in 2:p){
ri<-b[i-1,i:p]
return(ri)
}
}
wk(12)
#[1] 0.0 0.1 0.2 0.3 0.4 0.5 0.5 0.5 0.7 0.8 0.8

As you can see, it is only returning the first line. I would like other
corresponding elements too, to be found in row 2 to 12. Thanks. 
-- 
View this message in context: 
http://www.nabble.com/help-using-outer-function-tp18914432p18914432.html
Sent from the R help mailing list archive at Nabble.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] customizing the axis (adding labels)

2008-08-10 Thread Jörg Groß


Am 10.08.2008 um 17:46 schrieb stephen sefick:


Would you provide reproducible code because form your example it looks
like you are trying to label a scatterplot with just two lables - this
is your boxplot from yesterday?  If so look into the ?boxplot and it
will tell you some answers


No, what I want is to plot the mean for two different groups.
So that I get group 1 and 2 on the x-axis and also label it like that.





On Sun, Aug 10, 2008 at 11:29 AM, Jörg Groß <[EMAIL PROTECTED]>  
wrote:

Hi,

I want to customize the x-axis.

I tried that:
par(bty="n", xaxt="n")
so that the x-axis is supressed.

then I tried to plot two variables and add a customized x-axis:
plot(x, y)
axis(1, at=c(1,2), labels=c("group1", "group2"))

but the axis is not added to the plot.

I don't understand why..
And how then can I customize the axis?
  [[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.





--
Let's not spend our time and resources thinking about things that are
so little or so large that all they really do for us is puff us up and
make us feel like gods. We are mammals, and have not exhausted the
annoying little problems of being mammals.

-K. Mullis


__
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] ANOVA

2008-08-10 Thread Chuck Cleland

On 8/10/2008 11:35 AM, Angelo Scozzarella wrote:

Hi,

How can I make an  ANOVA if I haven't got all data set but I  know the 
numbers of subjects for each group, the mean and di standard deviation 
for each group?


  See anova.mean() in the HH package:

http://finzi.psych.upenn.edu/R/library/HH/html/anova.mean.html


Thanks

Angelo Scozzarella

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


--
Chuck Cleland, Ph.D.
NDRI, Inc. (www.ndri.org)
71 West 23rd Street, 8th floor
New York, NY 10010
tel: (212) 845-4495 (Tu, Th)
tel: (732) 512-0171 (M, W, F)
fax: (917) 438-0894

__
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] R function, sink() and empty file

2008-08-10 Thread Prof Brian Ripley

This is what Rscript and R CMD BATCH are for.

Your problem is that you forgot to print the objects in your function: 
auto-printing only occurs at the top level.


On Sun, 10 Aug 2008, Laura Poggio wrote:


Dear all,
I wrote a simple script in order to put together some functions and method
to be executed on various files
I am trying to have to possibility to call the script changing few
parameters in order to use the different files.
I succeeded partly using the function method.
However in my script I call the sink() function in order to output the
results to a .txt file. When using the function the file is empty, when
running the script manually the file is fine. How can I solve that?
Is there any other way to run a R script on different files with different
names?

Thank you very much in advance

Laura

=
EXAMPLE OF CODE
=
km = function(a,o) {

fld <- system.file("G:/ALRPC/JRC/IMG/", package="rgdal")
filename = as.name(paste (a, "-", o, sep=""))
file <- read.table(paste("R_out/", filename, ".txt", sep=""))

obj <- kmenas(file, 5)

sink(paste("R_out/res", filename, ".txt", sep=""))
"Kluster centers"
obj$centers
"Within size for clusters"
obj$withinss
"Cluster size"
obj$size
sink()
}

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



--
Brian D. Ripley,  [EMAIL PROTECTED]
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.


Re: [R] What is filter() function doing?

2008-08-10 Thread Gabor Grothendieck
For each time point is sums the value prior to it, the
value at the time point itself and the value at the next
time point.   For the first timepoint there is no prior
value so its NA.   For the second timepoint we have
1+2+3=6.  For the third timepoint we have 2+3+4=9 and
so on.

> filter(1:10, c(1, 1, 1))
Time Series:
Start = 1
End = 10
Frequency = 1
 [1] NA  6  9 12 15 18 21 24 27 NA


On Sun, Aug 10, 2008 at 11:32 AM, Sergey Goriatchev <[EMAIL PROTECTED]> wrote:
> Hello,
>
> I cannot understand what filter() function in package stat is doing.
> For example, what does filter(1:100, c(1,1,1)) mean?
> Could someone please explain? Help file is not enough for me.
>
> Thanks in advance.
> Sergey
>
> __
> 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] customizing the axis (adding labels)

2008-08-10 Thread stephen sefick
Would you provide reproducible code because form your example it looks
like you are trying to label a scatterplot with just two lables - this
is your boxplot from yesterday?  If so look into the ?boxplot and it
will tell you some answers

On Sun, Aug 10, 2008 at 11:29 AM, Jörg Groß <[EMAIL PROTECTED]> wrote:
> Hi,
>
> I want to customize the x-axis.
>
> I tried that:
> par(bty="n", xaxt="n")
> so that the x-axis is supressed.
>
> then I tried to plot two variables and add a customized x-axis:
> plot(x, y)
> axis(1, at=c(1,2), labels=c("group1", "group2"))
>
> but the axis is not added to the plot.
>
> I don't understand why..
> And how then can I customize the axis?
>[[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.
>



-- 
Let's not spend our time and resources thinking about things that are
so little or so large that all they really do for us is puff us up and
make us feel like gods. We are mammals, and have not exhausted the
annoying little problems of being mammals.

-K. Mullis

__
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] ANOVA

2008-08-10 Thread stephen sefick
I don't know of a way to do it without the data

On Sun, Aug 10, 2008 at 11:35 AM, Angelo Scozzarella
<[EMAIL PROTECTED]> wrote:
> Hi,
>
> How can I make an  ANOVA if I haven't got all data set but I  know the
> numbers of subjects for each group, the mean and di standard deviation for
> each group?
>
> Thanks
>
>
> Angelo Scozzarella
>
> __
> 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.
>



-- 
Let's not spend our time and resources thinking about things that are
so little or so large that all they really do for us is puff us up and
make us feel like gods. We are mammals, and have not exhausted the
annoying little problems of being mammals.

-K. Mullis

__
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] ANOVA

2008-08-10 Thread Angelo Scozzarella

Hi,

How can I make an  ANOVA if I haven't got all data set but I  know the  
numbers of subjects for each group, the mean and di standard deviation  
for each group?


Thanks


Angelo Scozzarella

__
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] What is filter() function doing?

2008-08-10 Thread Sergey Goriatchev
Hello,

I cannot understand what filter() function in package stat is doing.
For example, what does filter(1:100, c(1,1,1)) mean?
Could someone please explain? Help file is not enough for me.

Thanks in advance.
Sergey

__
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] customizing the axis (adding labels)

2008-08-10 Thread Jörg Groß
Hi,

I want to customize the x-axis.

I tried that:
par(bty="n", xaxt="n")
so that the x-axis is supressed.

then I tried to plot two variables and add a customized x-axis:
plot(x, y)
axis(1, at=c(1,2), labels=c("group1", "group2"))

but the axis is not added to the plot.

I don't understand why..
And how then can I customize the axis?
[[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] [lme4]Coef output with binomial lmer

2008-08-10 Thread Doran, Harold
I don't think the %in% works at all. It's non-standard and I think an
incorrect model specification. Here is an example where we can see that
the transpose of the model matrix for the random effects is different
when we compare what would be the same model if it "worked". 

I don't think there is an extractor function so I pull out the slot
directly. There is some "danger" in this because extractor functions
should be used rather than directly accessing the slots, but I think it
works OK.

library(lme4)
data(egsingle, package='mlmRev')

fm1 <- lmer(math ~ 1 + (1|schoolid/childid), egsingle, control =
list(grad = 0, nit = 0, msV = 1))
fm2 <- lmer(math ~ 1 + (1|childid%in%schoolid), egsingle, control =
list(grad = 0, nit = 0, msV = 1))

z1 <- [EMAIL PROTECTED]
z2 <- [EMAIL PROTECTED]
identical(z1,z2)
[1] FALSE

fm1 is the correct specification as it properly denotes that children
are nested in schools. When we compare the model matrices, we can see
that they are not identical; hence the model specification is not the
same. I have no clue what %in% does and am not sure it even works with
lmer, but could be wrong. 

Note in this case

fm3 <- lmer(math ~ 1 + (1|schoolid) + (1|childid), egsingle, control =
list(grad = 0, nit = 0, msV = 1))
z3 <- [EMAIL PROTECTED]
identical(z1,z3)
[1] TRUE

Is exactly the same as fm1 because the IDs are always nested.

Harold

> -Original Message-
> From: [EMAIL PROTECTED] 
> [mailto:[EMAIL PROTECTED] On Behalf Of Mark Difford
> Sent: Saturday, August 09, 2008 8:32 AM
> To: r-help@r-project.org
> Subject: Re: [R] [lme4]Coef output with binomial lmer
> 
> 
> Hi Tom,
> 
> >> 1|ass%in%pop%in%fam
> 
> This is "non-standard," but as you have found, it works. The 
> correct translation is in fact
> 
> 1|fam/pop/ass
> 
> and not 1|ass/pop/fam as suggested by Harold Doran. Dropping 
> %, ass%in%pop%in%fam reads [means] as: nest ass in pop [= 
> pop/ass], and then nest this in fam == fam/pop/ass
> 
> HTH, Mark.
> 
> 
> T.C. Cameron wrote:
> > 
> > Dear R users
> >  
> > I have built the following model
> >  
> > m1<-lmer(y~harn+foodn+(1|ass%in%pop%in%fam),family = 
> "quasibinomial")
> >  
> > where y<-cbind(alive,dead)
> >  
> > where harn and foodn are categorical factors and the random 
> effect is 
> > a nested term to represent experimental structure e.g.  
> > Day/Block/Replicate ass= 5 level factor, pop= 2 populations per 
> > treatment factor in each assay, 7 reps per population
> >  
> > The model can be family = quasibinomial or binomial
> >  
> > My complete lack of understanding is in retrieving the coefficients 
> > for the fixed effects to back-transform the effects of my 
> factors on 
> > proportional survival
> >  
> > I get the following output:
> >> coef(m1)
> > $`ass %in% pop %in% fam`
> >   (Intercept)  harn1 harn2   foodn2
> > FALSE   1.0322375 -0.1939521 0.0310434 0.810084
> > TRUE0.5997679 -0.1939521 0.0310434 0.810084
> >  
> > Where FALSE and TRUE refer to some attribute of the random effect
> >  
> > My hunch is that it refers to the Coefficients with (=TRUE) and 
> > without
> > (=FALSE) the random effects?
> >  
> > Any help appreciated
> >  
> > 
> > 
> ..
> ..
> > 
> > Dr Tom C Cameron
> > Genetics, Ecology and Evolution
> > IICB, University of Leeds
> > Leeds, UK
> > Office: +44 (0)113 343 2837
> > Lab:+44 (0)113 343 2854
> > Fax:+44 (0)113 343 2835
> > 
> > 
> > Email: [EMAIL PROTECTED]
> > Webpage: click here
> > 
> > 
> >  
> > 
> > [[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.
> > 
> > 
> 
> --
> View this message in context: 
> http://www.nabble.com/-lme4-Coef-output-with-binomial-lmer-tp1
> 8894407p18904468.html
> Sent from the R help mailing list archive at Nabble.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.
> 

__
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] RPro

2008-08-10 Thread Ajay ohri
and I think the WPS to R bridge is doing quite well, and the SAS to R bridge
is likely to debut very very soon. Phil Rack from www.minequest.com is
leading this.

WPS is an ideal mix for R because it is great for data mining ,cleaning and
manipulation thus leaving R for the cleaned, data for the stats
procedures.At 600 bucks an annual license its way way cheaper than any other
software (apart from..)

I don't see SAS official support to R anytime soon given historic behavior.

I myself have proposed R to be in a cloud computing network  so as to cope
with the relative inefficiency in processing bigger files as compared to
other "mainstream "and expensive softwares. Bigger corporate users are the
way R will beak in and commercial deployment will help some initial pains
that all R transitions feel (especially the ones working on a live corporate
projects and have to learn on their own time on break neck speed, because
the annual license budget just got cut).however the R stats packages do seem
much more robust than the GIGO click and point softwares.

http://decisionstats.com/2008/the-ohri-framework-data-mining-on-demand/





On 8/9/08, Marc Schwartz <[EMAIL PROTECTED]> wrote:
>
> on 08/09/2008 12:45 PM Marc Schwartz wrote:
>
>> on 08/09/2008 12:13 PM Charles C. Berry wrote:
>>
>>> On Fri, 8 Aug 2008, Kenn Konstabel wrote:
>>>
>>>  There's more to this trend: SPSS and Statistica now advertise "R
 language
 support" :

 http://www.statsoft.com/industries/Rlanguage.htm
 http://www.spss.com/spssdirections/na/sessions.cfm?sessionType=2

>>>
>>>
>>> If you can't beat R, join R.
>>>
>>
>> "Resistance is futile. You will be assimilated."
>>
>> ;-)
>>
>>
>>  Should someone start a pool on when SAS will offer 'R language support'
>>> ??
>>>
>>
>> It is already in place, albeit not from Cary:
>>
>>  http://www.minequest.com/
>>
>> See the link for "A Bridge to R for SAS Users".
>>
>> That product might put an interesting spin on:
>>
>>  > fortune(28)
>>
>> Jim Gustafsson: I would like to put my SAS-code into R. Could I do
>> that, if yes, how?
>> Frank Harrell: Just reverse the procedure you use when you put R code
>> into SAS. ;)
>>   -- Jim Gustafsson and Frank Harrell
>>  R-help (February 2004)
>>
>>
>> Their WPS product has been getting a fair amount of attention, at least
>> for those needing mostly "Base" and not "Stat" functionality at
>> substantially less cost than the SAS commercial license pricing.
>>
>
> Correction. WPS is actually a product of "Word Programming", which is at:
>
>  http://www.teamwpc.co.uk/products/wps
>
> though at the moment, I am having trouble getting to their web page. There
> is a Wikipedia page here:
>
>  http://en.wikipedia.org/wiki/World_Programming_System
>
> Minequest is providing SAS to WPS related consulting services.
>
> Marc
>
> __
> 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] R function, sink() and empty file

2008-08-10 Thread Laura Poggio
Dear all,
I wrote a simple script in order to put together some functions and method
to be executed on various files
I am trying to have to possibility to call the script changing few
parameters in order to use the different files.
I succeeded partly using the function method.
However in my script I call the sink() function in order to output the
results to a .txt file. When using the function the file is empty, when
running the script manually the file is fine. How can I solve that?
Is there any other way to run a R script on different files with different
names?

Thank you very much in advance

Laura

=
EXAMPLE OF CODE
=
km = function(a,o) {

fld <- system.file("G:/ALRPC/JRC/IMG/", package="rgdal")
filename = as.name(paste (a, "-", o, sep=""))
file <- read.table(paste("R_out/", filename, ".txt", sep=""))

obj <- kmenas(file, 5)

sink(paste("R_out/res", filename, ".txt", sep=""))
"Kluster centers"
obj$centers
"Within size for clusters"
obj$withinss
"Cluster size"
obj$size
sink()
}

[[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] predicted survival curves from a Cox time dep model

2008-08-10 Thread phguardiol

 Dear R users,

is there a way to plot "predicted" curves from a Cox model with a time 
dependent covariates using "predict", in which other significant covariates 
are included with specific values ?

I use cluster(id) in this time-dep. Cox model for rows belonging to the same 
patient, and this seems to be a problem...


Thanks for your help


 


Philippe Guardiola








[[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] print data frames without row names (within a list)

2008-08-10 Thread Prof Brian Ripley

Try auto-printing, e.g.


three

[[1]]
 a b
 1 x
 2 y
 3 z

[[2]]
 a b
 4 q
 5 r
 6 s

or change print.data.frame *in the base namespace* by fixInNamespace.

When you said you 'reloaded that function' I suspect that in fact you 
source()-d it into a different place, your workspace.



On Sun, 10 Aug 2008, Daniel Ezra Johnson wrote:


This should be an easy one, but I could not find the answer in the
obvious places.

one <- data.frame(a=c(1,2,3),b=c("x","y","z"))
two <- data.frame(a=c(4,5,6),b=c("q","r","s"))


print(one)

a b
1 1 x
2 2 y
3 3 z


print(one,row.names=F)

a b
1 x
2 y
3 z

So far, so good, but how do I do this if the data frames are bound into 
a list?



three <- list(one,two)
print(three,row.names=F)  #same as print(three,row.names=T)


[[1]]
a b
1 1 x
2 2 y
3 3 z

[[2]]
a b
1 4 q
2 5 r
3 6 s

Is there any way to stop the row (or column) names from printing in a
case like this?
I just thought of one way - change the default in print.data.frame()
and reload that function.

Surprisingly, that does not work. I have successfully changed the
behavior of:


print(one)
one


These now print without row names, but


print(three)


continues to print the row names, even though


class(three[[1]])


is "data.frame", so I'm not clear why it doesn't take the print
defaults from print.data.frame!

Any advice would be appreciated. I can live with the row names, but
there are cases where I want to suppress them within a list.

Thanks,
Daniel

__
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,  [EMAIL PROTECTED]
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] print data frames without row names (within a list)

2008-08-10 Thread Daniel Ezra Johnson
This should be an easy one, but I could not find the answer in the
obvious places.

one <- data.frame(a=c(1,2,3),b=c("x","y","z"))
two <- data.frame(a=c(4,5,6),b=c("q","r","s"))

> print(one)
 a b
1 1 x
2 2 y
3 3 z

> print(one,row.names=F)
 a b
 1 x
 2 y
 3 z

So far, so good, but how do I do this if the data frames are bound into a list?

> three <- list(one,two)
> print(three,row.names=F)  #same as print(three,row.names=T)

[[1]]
 a b
1 1 x
2 2 y
3 3 z

[[2]]
 a b
1 4 q
2 5 r
3 6 s

Is there any way to stop the row (or column) names from printing in a
case like this?
I just thought of one way - change the default in print.data.frame()
and reload that function.

Surprisingly, that does not work. I have successfully changed the
behavior of:

> print(one)
> one

These now print without row names, but

> print(three)

continues to print the row names, even though

> class(three[[1]])

is "data.frame", so I'm not clear why it doesn't take the print
defaults from print.data.frame!

Any advice would be appreciated. I can live with the row names, but
there are cases where I want to suppress them within a list.

Thanks,
Daniel

__
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] Converting nested "for" loops to an "apply" function(s)

2008-08-10 Thread Dan Davison
On Sat, Aug 09, 2008 at 08:53:00PM -0400, Kurt Newman wrote:
> 
> Resending.  Previous message was truncated.  Sorry for possible confusion.
> 
> 
> > From: [EMAIL PROTECTED]
> > To: r-help@r-project.org
> > Date: Sat, 9 Aug 2008 18:25:47 -0400
> > Subject: [R] Converting nested "for" loops to an "apply" function(s)
> > 
> > 
> > Hello,
> > 

> > I would like to know more about how to use the "apply" family and
> > have attempted to convert nested "for" loops in example code from
> > Contributed Documentation ("The Friendly Beginners' R Course? by
> > Toby Marthews (ZIP, 2007-03-01)") to an "apply" function(s).  The
> > relevant code is:

> > 
> > distances=c(51,65,175,196,197,125,10,56)#distances of 8 houses from the 
> > town centre in m
> > bearings=c(10,8,210,25,74,128,235,335)  #bearings of the houses in 
> > degrees
> > 
> > xpos=distances*sin(bearings*pi/180) #in sin and cos the argument 
> > MUST be in radians
> > ypos=distances*cos(bearings*pi/180) 
> > 
> > numpoints=length(distances)
> > nnd=rep(sqrt(2*400*400),times=numpoints)#start with the maximum 
> > possible distance
> > for (i in 1:numpoints) {
> >  for (j in 1:numpoints) {
> >   if (i!=j) {   
> >diffx=abs(xpos[i]-xpos[j])
> >diffy=abs(ypos[i]-ypos[j])
> >nd=sqrt((diffx^2)+(diffy^2))
> >if (nd < nnd[i]) {nnd[i]=nd}
>   }
>  }
> }
> print(data.frame(xpos,ypos,nnd))
> 

> My attempts to convert the nested "for" loops to an "apply"
>  function(s) have not been successful.  I would like to know how to
>  convert the code to increase my knowledge of R programming and to
>  evaluate operational efficiency of the different strategies.

Hi Kurt,

It's not just the apply() family that help in vectorising problems. In
this case, outer() is also going to be helpful, as well as remembering
that all the standard arithmetical operators automatically
vectorise. I would use something like this:

nearest.neighbour.distance <- function(xpos, ypos) {
xdist <- abs(outer(xpos, xpos, "-"))
ydist <- abs(outer(ypos, ypos, "-"))
dist <- sqrt(xdist^2 + ydist^2)
diag(dist) <- NA
apply(dist, 1, min, na.rm=TRUE)
}

Dan


> 
> Thank you in advance for your comments / suggestions.
> 
> Kurt Newman
> 
> 
> 
> > __
> > 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-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] Scripting - query

2008-08-10 Thread Dan Davison
On Sun, Aug 10, 2008 at 02:44:00PM +1200, Gareth Campbell wrote:
> I have a vector:
> alleles.present<-c("D3", "D16", ... )
> 
> The alleles present changes given the case I'm dealing with - i.e. either
> all of the alleles I use for my calculations are present, or some of them.
> 
> Depending on what alleles are present, I need to make matrices and do
> calculations on those alleles present and completely disregard any formula
> or other use of the alleles not present.
> 
> I'm trying to figure out the best way to do this.
> 
> Basically I'm trying to do if() commands (with no success so far) to allow
> me to query the alleles.present for the presence of each allele I use and
> then let dictate which formula to use etc...
> 
> Does anyone have a good way to do this?  I've been fiddling with grep()
> etc... but I can't get it to do what I need!!  Very frustrating.

It's going to be hard for people to make good suggestions here without
a concrete example. Can you provide a toy example that is as simple as
possible, while illustrating (some of) the problems you are trying to
solve?

Dan

p.s. Are you familiar with %in% ? E.g.

if("D3" %in% alleles.present) do.something()
else do.something.else()

See help("%in%")


> 
> Thanks very much
> 
> -- 
> Gareth Campbell
> PhD Candidate
> The University of Auckland
> 
> P +649 815 3670
> M +6421 256 3511
> E [EMAIL PROTECTED]
> [EMAIL PROTECTED]
> 
>   [[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-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] effective matrix subset

2008-08-10 Thread jgarcia
Patrick, you have misundertood me, I mean that Dan's solution (which is
also your solution) are both:
a) more clear and elegant
b) more time efficient. I've checked it with my working 1*3000 element
matrixes. The improvement in speed with your solution is evident.

I do not advise at all to use my solution. At the contrary, you have
solved my problem.

Thanks, and regards.
Javier
--


> That may be a better solution, but I don't think
> it is clearly a better solution.
>
> I presume you mean that your computation is the
> most time efficient.  That seems believable to me.
> It is not the most human efficient -- it will take
> some one reading the code non-trivial effort to
> understand it.
>
> Whether time or code clarity are more important
> depends on the particular application.
>
> Patrick Burns
> [EMAIL PROTECTED]
> +44 (0)20 8525 0696
> http://www.burns-stat.com
> (home of S Poetry and "A Guide for the Unwilling S User")
>
> [EMAIL PROTECTED] wrote:
>> It seems that this solution provided by Dan (and also available in
>> SPoetry; I'm sorry I didn't notice it) is the fastest and simplest. I
>> was
>> using a more standard approach:
>>
>> V <- t(A)[(0:(nrow(A)-1))*ncol(A)+X],
>>
>> That wasn't bad, but I was confident that you, R gurus, could outperform
>> this. This is clearly a much better solution.
>>
>> Thanks all, and best wishes,
>> Javier
>> --
>>
>>
>>
>>
>>
>>> on 08/09/2008 06:52 AM Dan Davison wrote:
>>>
 On Sat, Aug 09, 2008 at 06:29:59AM -0500, Marc Schwartz wrote:

> on 08/09/2008 06:01 AM [EMAIL PROTECTED] wrote:
>
>> Hi;
>> If we have a matrix A, and a vector X, where length(X)=nrow(A), and
>> X
>> contains a wanted column for each row in A, in row ascending order.
>> How
>> would be the most effective way to extract the desired vector V
>> (with
>> length(V)=nrow(A))?
>>
> A <- matrix(1:20, 4, 5)
>
>
>> A
>>
>  [,1] [,2] [,3] [,4] [,5]
> [1,]159   13   17
> [2,]26   10   14   18
> [3,]37   11   15   19
> [4,]48   12   16   20
>
>
> # Create an arbitrary set of indices, one for each row in A
> X <- c(2, 5, 1, 4)
>
>
>> X
>>
> [1] 2 5 1 4
>
>
> Presumably you want:
>
> V <- c(A[1, 2], A[2, 5], A[3, 1], A[4, 4])
>
>
>> V
>>
> [1]  5 18  3 16
>
>
> If so, then:
>
>
>> sapply(seq(nrow(A)), function(i) A[i, X[i]])
>>
> [1]  5 18  3 16
>
 Or


> A[cbind(seq(nrow(A)), X)]
>
 [1]  5 18  3 16

 Dan

>>> Better (and faster) solution Dan.
>>>
>>> I can't blame the lack of coffee on missing that one this morning. I
>>> have had a full pot already over the past 6 hours, working on shifting
>>> my internal clock and getting ready to begin my journey to Dortmund
>>> later tonight...
>>>
>>> Safe travels to all who are going.
>>>
>>> Marc
>>>
>>>
>>>
>>
>> __
>> 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] mean-plot (add residuals)

2008-08-10 Thread glaporta

Try with plotmeans in gplots
Regards,
Gianandrea


Jörg Groß wrote:
> 
> Hi,
> 
> I want to plot the mean of a variable and add the standard deviation  
> as a line going above and below the mean (like the whiskers in a  
> boxplot) but I don't know how to add these residual-lines.
> 
> Is there an easy way to do that or do I have to use the line()- 
> function to create them on my own?
> 
> 
> Thanks for help!
> 
> __
> 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.
> 
> 

-- 
View this message in context: 
http://www.nabble.com/mean-plot-%28add-residuals%29-tp18910522p18911651.html
Sent from the R help mailing list archive at Nabble.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] effective matrix subset

2008-08-10 Thread Patrick Burns

That may be a better solution, but I don't think
it is clearly a better solution.

I presume you mean that your computation is the
most time efficient.  That seems believable to me.
It is not the most human efficient -- it will take
some one reading the code non-trivial effort to
understand it.

Whether time or code clarity are more important
depends on the particular application.

Patrick Burns
[EMAIL PROTECTED]
+44 (0)20 8525 0696
http://www.burns-stat.com
(home of S Poetry and "A Guide for the Unwilling S User")

[EMAIL PROTECTED] wrote:

It seems that this solution provided by Dan (and also available in
SPoetry; I'm sorry I didn't notice it) is the fastest and simplest. I was
using a more standard approach:

V <- t(A)[(0:(nrow(A)-1))*ncol(A)+X],

That wasn't bad, but I was confident that you, R gurus, could outperform
this. This is clearly a much better solution.

Thanks all, and best wishes,
Javier
--




  

on 08/09/2008 06:52 AM Dan Davison wrote:


On Sat, Aug 09, 2008 at 06:29:59AM -0500, Marc Schwartz wrote:
  

on 08/09/2008 06:01 AM [EMAIL PROTECTED] wrote:


Hi;
If we have a matrix A, and a vector X, where length(X)=nrow(A), and X
contains a wanted column for each row in A, in row ascending order.
How
would be the most effective way to extract the desired vector V (with
length(V)=nrow(A))?
  

A <- matrix(1:20, 4, 5)



A
  

 [,1] [,2] [,3] [,4] [,5]
[1,]159   13   17
[2,]26   10   14   18
[3,]37   11   15   19
[4,]48   12   16   20


# Create an arbitrary set of indices, one for each row in A
X <- c(2, 5, 1, 4)



X
  

[1] 2 5 1 4


Presumably you want:

V <- c(A[1, 2], A[2, 5], A[3, 1], A[4, 4])



V
  

[1]  5 18  3 16


If so, then:



sapply(seq(nrow(A)), function(i) A[i, X[i]])
  

[1]  5 18  3 16


Or

  

A[cbind(seq(nrow(A)), X)]


[1]  5 18  3 16

Dan
  

Better (and faster) solution Dan.

I can't blame the lack of coffee on missing that one this morning. I
have had a full pot already over the past 6 hours, working on shifting
my internal clock and getting ready to begin my journey to Dortmund
later tonight...

Safe travels to all who are going.

Marc





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