[R] Filled contour in a irregular map (shapefile)

2009-09-19 Thread Zhongkui.Luo
Hello All,

I want to draw a figure with filled contour in a irregular map.

But I found that the contours overlap the boundaries of the map, and also some 
regions in the map were not filled.


I have following data:

data1. A shapefile (i.e., a map with boundary, for example, the whole Australia 
map);

data2. A text file with three columns: x, latitude; y,longitude;z,variable 
(e.g., rainfall);

and use following R code:

Map-readShapeSpatial(data1)
plot(Map)
data2.li-interp(data2$x,data2$y,data2$z)
filled.contour(data2.li, color=topo.colors, add=TRUE)

How can I limits the filled contours just inside the map?

Thank very much for that!

Zachary









[[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] Why don't formulas that work for lm() work for plotmeans?

2009-09-19 Thread jrflanders

I know that simple line plots showing a point representing the mean + an
error bar are difficult in R, but I  am clearly missing something.  I simply
want to show how a the mean and 95% CI of a chemical concentration (y) vary
over space (x) under four temperature regimes (T; a categorical factor).
plotmeans, in the gplots library, should allow for such a figure, right?
After all, it invokes lm() in the help file for the formula, so any formula
that works in lm() (e.g., y~x | T) should work in plotmeans.  Obviously this
is not so - can anyone suggest an alternative  command or help me understand
how  the syntac differs? Thanks...
-- 
View this message in context: 
http://www.nabble.com/Why-don%27t-formulas-that-work-for-lm%28%29-work-for-plotmeans--tp25517081p25517081.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] Emacs and ESS help

2009-09-19 Thread jaropis

 Any and all help is deeply appreciated.

If you do not want to learn all the inns and outs of Emacs, just download 
the Emacs distribution provided by Vincent Goulet - it has ESS. Uninstall 
your present Emacs, go to http://vgoulet.act.ulaval.ca/en/ressources/emacs/
download Vincent's distribution, install it, and your are set!

Jarek

__
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 avoid copy-paste when copying code from this list?

2009-09-19 Thread johannes rara
Hi,

How do you people avoid copy-pasting and manual editing of the code
posted in this list? I mean that if some one post a solution for an
answer like this:

 a - 1:10
 a
 [1]  1  2  3  4  5  6  7  8  9 10
 a[1:5]
[1] 1 2 3 4 5


I have to copy-paste it to e.g. Tinn-R and remove   part of the
line to try it in my R. When you keep doing this it gets quite
annoying. How do you people avoid this (search and replace, perhaps?).
The best way would be to able to send this straight from your e-mail
reader into R (e.g. from gmail).

-Johannes

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


Re: [R] How to avoid copy-paste when copying code from this list?

2009-09-19 Thread Cedrick W. Johnson
At least in windows, if you right click directly in the r console, 
there's a command for 'Paste commands only' which may be one solution... 
Not sure about other platforms..


hth
c

johannes rara wrote:

Hi,

How do you people avoid copy-pasting and manual editing of the code
posted in this list? I mean that if some one post a solution for an
answer like this:

  

a - 1:10
a


 [1]  1  2  3  4  5  6  7  8  9 10
  

a[1:5]


[1] 1 2 3 4 5
  


I have to copy-paste it to e.g. Tinn-R and remove   part of the
line to try it in my R. When you keep doing this it gets quite
annoying. How do you people avoid this (search and replace, perhaps?).
The best way would be to able to send this straight from your e-mail
reader into R (e.g. from gmail).

-Johannes

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



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


Re: [R] How to avoid copy-paste when copying code from this list

2009-09-19 Thread Ted Harding
On 19-Sep-09 08:00:18, Cedrick W. Johnson wrote:
 At least in windows, if you right click directly in the r console, 
 there's a command for 'Paste commands only' which may be one
 solution... 
 Not sure about other platforms..
 
 hth
 c

It was precisely for this kind of reason that, when including
R code in postings to the list, I took to formatting it in the
following kind of way:

  a - 1:10
  a
  # [1]  1  2  3  4  5  6  7  8  9 10
  
  a[1:5]
  # [1] 1 2 3 4 5

In this way, any R commands copy-pasted into R will work as-is,
anything else is a comment and will not interfere. I notice that
some other people also post their code in this way.

I recommend it to all! If the code has been copy-pasted into the
email from an R console, then of course the  prompts will be
there. But then I just edit these out of the email. A bit more
trouble for me, but a lot less trouble for others.

For instance, if someone had posted the above as copied from the
R console in its original form

 a - 1:10
 a
 [1]  1  2  3  4  5  6  7  8  9 10

 a[1:5]
[1] 1 2 3 4 5

and I wanted to try it out, then I would either have to re-open the
email in edit mode so as to edit the email itself, or else copy-paste
the above into a text-edit window[*] and pre-edit it there before
copying into R.

[*] I would be using 'vim' in a Linux xterm. Removal of the  
prompts (or +  continuation prompts) from a long series of commands
is relatively easy: Just higlight a column-block of the first two
columns, then press d to delete them. But you would first need to
enter   #  for other stuff by hand.

Best wishes to all,
Ted.

 
 johannes rara wrote:
 Hi,

 How do you people avoid copy-pasting and manual editing of the code
 posted in this list? I mean that if some one post a solution for an
 answer like this:

   
 a - 1:10
 a
 
  [1]  1  2  3  4  5  6  7  8  9 10
   
 a[1:5]
 
 [1] 1 2 3 4 5
   

 I have to copy-paste it to e.g. Tinn-R and remove   part of the
 line to try it in my R. When you keep doing this it gets quite
 annoying. How do you people avoid this (search and replace, perhaps?).
 The best way would be to able to send this straight from your e-mail
 reader into R (e.g. from gmail).

 -Johannes


E-Mail: (Ted Harding) ted.hard...@manchester.ac.uk
Fax-to-email: +44 (0)870 094 0861
Date: 19-Sep-09   Time: 09:33:48
-- XFMail --

__
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] How to avoid copy-paste when copying code from this list

2009-09-19 Thread johannes rara
The R help mailing list posting guide

http://www.r-project.org/posting-guide.html

suggests to give an example in this form

...snip...
f I have a matrix x as follows:
   x - matrix(1:8, nrow=4, ncol=2,
dimnames=list(c(A,B,C,D), c(x,y))
   x
x y
  A 1 5
  B 2 6
  C 3 7
  D 4 8
  
...snip...

Would it be reasonable to consider changing this guide about this matter?



2009/9/19 Ted Harding ted.hard...@manchester.ac.uk:
 On 19-Sep-09 08:00:18, Cedrick W. Johnson wrote:
 At least in windows, if you right click directly in the r console,
 there's a command for 'Paste commands only' which may be one
 solution...
 Not sure about other platforms..

 hth
 c

 It was precisely for this kind of reason that, when including
 R code in postings to the list, I took to formatting it in the
 following kind of way:

  a - 1:10
  a
  # [1]  1  2  3  4  5  6  7  8  9 10

  a[1:5]
  # [1] 1 2 3 4 5

 In this way, any R commands copy-pasted into R will work as-is,
 anything else is a comment and will not interfere. I notice that
 some other people also post their code in this way.

 I recommend it to all! If the code has been copy-pasted into the
 email from an R console, then of course the  prompts will be
 there. But then I just edit these out of the email. A bit more
 trouble for me, but a lot less trouble for others.

 For instance, if someone had posted the above as copied from the
 R console in its original form

 a - 1:10
 a
  [1]  1  2  3  4  5  6  7  8  9 10

 a[1:5]
 [1] 1 2 3 4 5

 and I wanted to try it out, then I would either have to re-open the
 email in edit mode so as to edit the email itself, or else copy-paste
 the above into a text-edit window[*] and pre-edit it there before
 copying into R.

 [*] I would be using 'vim' in a Linux xterm. Removal of the  
 prompts (or +  continuation prompts) from a long series of commands
 is relatively easy: Just higlight a column-block of the first two
 columns, then press d to delete them. But you would first need to
 enter   #  for other stuff by hand.

 Best wishes to all,
 Ted.


 johannes rara wrote:
 Hi,

 How do you people avoid copy-pasting and manual editing of the code
 posted in this list? I mean that if some one post a solution for an
 answer like this:


 a - 1:10
 a

  [1]  1  2  3  4  5  6  7  8  9 10

 a[1:5]

 [1] 1 2 3 4 5


 I have to copy-paste it to e.g. Tinn-R and remove   part of the
 line to try it in my R. When you keep doing this it gets quite
 annoying. How do you people avoid this (search and replace, perhaps?).
 The best way would be to able to send this straight from your e-mail
 reader into R (e.g. from gmail).

 -Johannes

 
 E-Mail: (Ted Harding) ted.hard...@manchester.ac.uk
 Fax-to-email: +44 (0)870 094 0861
 Date: 19-Sep-09                                       Time: 09:33:48
 -- XFMail --

 __
 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] Creating histograms from factors using a for loop

2009-09-19 Thread Sam Player

# I have a dataframe with data and factors similar to the following:

a - rep(c(a, b), c(6,6))
df - data.frame(f=a, d=rnorm(12))
df

# I am trying to write a 'for' loop which will produce a jpeg histogram 
for each factor. I can individually isolate the data from a factor and 
produce a jpeg histogram like so:


fnc - function(x){
x - df[df$f==a, d]
}

y - fnc(df[df$f==a, d])

jpeg(filename=foo.jpeg)
hist(y)
dev.off()

# I'm having trouble creating a loop repeating the process for all the 
other factors. The following is the best I could come up with. It 
produces a single jpeg histogram of the first factor titled with a list 
of all the factors.


a - rep(c(a, b), c(6,6))
df - data.frame(f=a, d=rnorm(12))
df

for (i in levels(df[,f])){
y - df[df$f==i, 2]
jpeg(filename=(levels(df[i,f])))
hist(y, main=levels(df[i,f]))
dev.off()
}

# I'm obviously not understanding how loops work with factors. Can 
anybody point me in the right direction?


--
Sam Player, B.Sc.(Hons.) B.A.
Ph.D. Candidate, Faculty of Agriculture, Food  Natural Resources, University 
of Sydney

Email: spla...@usyd.edu.au

Agroecosystems Research Group
Room 214 J.R.A. McMillan Building A05
University of Sydney NSW 2006, Australia

Angkor Research Program
Room 305 Old Teachers College A22
University of Sydney NSW 2006, Australia

__
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] Counting observations of a combined factor

2009-09-19 Thread Sam Player
#I have a dataset with two factor. I want to combine those factors into 
a single factor and count the number of data values for each new factor. 
The following gives a comparable dataframe:


a - rep(c(a, b), c(6,6))
b - rep(c(c, d), c(6,6))
df - data.frame(f1=a, f2=b, d=rnorm(12))
df

# I use the 'interaction' function to combine factors f1 and f2:

df2 - data.frame(f3=interaction(df[,f1], df[,f2]), d=df[,d])
df2

# A count of the first data.frame using factor f1 returns the kind of 
results I am looking for:


count - as.data.frame(table(df$f1))
count

#  Var1 Freq
#1a6
#2b6

# As does a count using factor2:

count2 - as.data.frame(table(df$f2))
count2

#  Var1 Freq
#1a6
#2b6

# The same procedure on the second dataframe does not treat the levels 
of factor f3 discreetly, instead giving all possible combinations of f1 
and f2.


count3 - as.data.frame(table(df2$f3))
count3

#  Var1 Freq
#1  a.c6
#2  b.c0
#3  a.d0
#4  b.d6

I need the results to be:

#  Var1 Freq
#1a6
#2b6

# Any suggestions?

--
Sam Player, B.Sc.(Hons.) B.A.
Ph.D. Candidate, Faculty of Agriculture, Food  Natural Resources, University 
of Sydney

Email: spla...@usyd.edu.au

Agroecosystems Research Group
Room 214 J.R.A. McMillan Building A05
University of Sydney NSW 2006, Australia

Angkor Research Program
Room 305 Old Teachers College A22
University of Sydney NSW 2006, Australia

__
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] How to avoid copy-paste when copying code from this list

2009-09-19 Thread Ted Harding
On 19-Sep-09 08:48:45, johannes rara wrote:
 The R help mailing list posting guide
 
 http://www.r-project.org/posting-guide.html
 
 suggests to give an example in this form
 
 ...snip...
 f I have a matrix x as follows:
x - matrix(1:8, nrow=4, ncol=2,
 dimnames=list(c(A,B,C,D), c(x,y))
x
 x y
   A 1 5
   B 2 6
   C 3 7
   D 4 8
   
 ...snip...
 
 Would it be reasonable to consider changing this guide about this
 matter?

Yes, I think there is a case for a change. I must have read the
above myself, once, but ignored it later for the reasons I gave
below. In any case, that citation is not in the context of advice
about how to format R code when posting (there is no such advice
explicitly given in the posting-guide), but in the context that it
can be helpful to provide an example:

  Examples: Sometimes it helps to provide a small example that
   someone can actually run. For example:

(then the example above). Possibly, people may tend to read that
example as if it were advice on formatting the code.

So maybe the change which could be helpful in the present context
would be to follow the above example with a section which advised
on how to format the code for examples which someone can actually
run (they cannot actually run the code as given in the example).

In other words, on the lines of

  When posting R code for examples, when this is copied from an R
  console remove any command prompts  and continuation prompts
  + from the code as it appears on the R console, and precede
  each line of R output, messages, etc., with # (to make it a
  comment, so that if the code is copy-pasted from R-help into an
  R console it will work as-is without the need for further editing.
  Example:
  [...]

What do other people (in particular the maintainers of the posting
guide) think?

Some might argue that the  and + prompts serve to mark the
presence of R code and distinguish it from message text. But then
the result is something that nobody can actually run. I think,
myself, that (especially with indenting of the code by a couple
of spaces) the format I describe is clearly enough distinguished.

Ted.

 2009/9/19 Ted Harding ted.hard...@manchester.ac.uk:
 On 19-Sep-09 08:00:18, Cedrick W. Johnson wrote:
 At least in windows, if you right click directly in the r console,
 there's a command for 'Paste commands only' which may be one
 solution...
 Not sure about other platforms..

 hth
 c

 It was precisely for this kind of reason that, when including
 R code in postings to the list, I took to formatting it in the
 following kind of way:

 _a - 1:10
 _a
 _# [1] _1 _2 _3 _4 _5 _6 _7 _8 _9 10

 _a[1:5]
 _# [1] 1 2 3 4 5

 In this way, any R commands copy-pasted into R will work as-is,
 anything else is a comment and will not interfere. I notice that
 some other people also post their code in this way.

 I recommend it to all! If the code has been copy-pasted into the
 email from an R console, then of course the  prompts will be
 there. But then I just edit these out of the email. A bit more
 trouble for me, but a lot less trouble for others.

 For instance, if someone had posted the above as copied from the
 R console in its original form

 a - 1:10
 a
 _[1] _1 _2 _3 _4 _5 _6 _7 _8 _9 10

 a[1:5]
 [1] 1 2 3 4 5

 and I wanted to try it out, then I would either have to re-open the
 email in edit mode so as to edit the email itself, or else
 copy-paste
 the above into a text-edit window[*] and pre-edit it there before
 copying into R.

 [*] I would be using 'vim' in a Linux xterm. Removal of the  
 prompts (or +  continuation prompts) from a long series of commands
 is relatively easy: Just higlight a column-block of the first two
 columns, then press d to delete them. But you would first need to
 enter  _#  for other stuff by hand.

 Best wishes to all,
 Ted.


 johannes rara wrote:
 Hi,

 How do you people avoid copy-pasting and manual editing of the code
 posted in this list? I mean that if some one post a solution for an
 answer like this:


 a - 1:10
 a

 _[1] _1 _2 _3 _4 _5 _6 _7 _8 _9 10

 a[1:5]

 [1] 1 2 3 4 5


 I have to copy-paste it to e.g. Tinn-R and remove   part of the
 line to try it in my R. When you keep doing this it gets quite
 annoying. How do you people avoid this (search and replace,
 perhaps?).
 The best way would be to able to send this straight from your e-mail
 reader into R (e.g. from gmail).

 -Johannes

 
 E-Mail: (Ted Harding) ted.hard...@manchester.ac.uk
 Fax-to-email: +44 (0)870 094 0861
 Date: 19-Sep-09 _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ Time: 09:33:48
 -- XFMail --

 __
 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] How to avoid copy-paste when copying code from this list

2009-09-19 Thread baptiste auguie
it might be possible to set up a particular mode before copying the history,

### start example ###

email = function(op){
 if(!missing(op)) {
  options(op) } else {
  op - options()
  options(prompt =  )
  options(continue =  )
  op
 }
}

op  = email()

a = 1:10
a

email(op)

a = 1:10
a

### end example ###

I'm not sure how one would add # to the result lines.

Best,

baptiste


2009/9/19 Ted Harding ted.hard...@manchester.ac.uk:
 On 19-Sep-09 08:48:45, johannes rara wrote:
 The R help mailing list posting guide

 http://www.r-project.org/posting-guide.html

 suggests to give an example in this form

 ...snip...
 f I have a matrix x as follows:
    x - matrix(1:8, nrow=4, ncol=2,
                 dimnames=list(c(A,B,C,D), c(x,y))
    x
     x y
   A 1 5
   B 2 6
   C 3 7
   D 4 8
   
 ...snip...

 Would it be reasonable to consider changing this guide about this
 matter?

 Yes, I think there is a case for a change. I must have read the
 above myself, once, but ignored it later for the reasons I gave
 below. In any case, that citation is not in the context of advice
 about how to format R code when posting (there is no such advice
 explicitly given in the posting-guide), but in the context that it
 can be helpful to provide an example:

  Examples: Sometimes it helps to provide a small example that
   someone can actually run. For example:

 (then the example above). Possibly, people may tend to read that
 example as if it were advice on formatting the code.

 So maybe the change which could be helpful in the present context
 would be to follow the above example with a section which advised
 on how to format the code for examples which someone can actually
 run (they cannot actually run the code as given in the example).

 In other words, on the lines of

  When posting R code for examples, when this is copied from an R
  console remove any command prompts  and continuation prompts
  + from the code as it appears on the R console, and precede
  each line of R output, messages, etc., with # (to make it a
  comment, so that if the code is copy-pasted from R-help into an
  R console it will work as-is without the need for further editing.
  Example:
  [...]

 What do other people (in particular the maintainers of the posting
 guide) think?

 Some might argue that the  and + prompts serve to mark the
 presence of R code and distinguish it from message text. But then
 the result is something that nobody can actually run. I think,
 myself, that (especially with indenting of the code by a couple
 of spaces) the format I describe is clearly enough distinguished.

 Ted.

 2009/9/19 Ted Harding ted.hard...@manchester.ac.uk:
 On 19-Sep-09 08:00:18, Cedrick W. Johnson wrote:
 At least in windows, if you right click directly in the r console,
 there's a command for 'Paste commands only' which may be one
 solution...
 Not sure about other platforms..

 hth
 c

 It was precisely for this kind of reason that, when including
 R code in postings to the list, I took to formatting it in the
 following kind of way:

 _a - 1:10
 _a
 _# [1] _1 _2 _3 _4 _5 _6 _7 _8 _9 10

 _a[1:5]
 _# [1] 1 2 3 4 5

 In this way, any R commands copy-pasted into R will work as-is,
 anything else is a comment and will not interfere. I notice that
 some other people also post their code in this way.

 I recommend it to all! If the code has been copy-pasted into the
 email from an R console, then of course the  prompts will be
 there. But then I just edit these out of the email. A bit more
 trouble for me, but a lot less trouble for others.

 For instance, if someone had posted the above as copied from the
 R console in its original form

 a - 1:10
 a
 _[1] _1 _2 _3 _4 _5 _6 _7 _8 _9 10

 a[1:5]
 [1] 1 2 3 4 5

 and I wanted to try it out, then I would either have to re-open the
 email in edit mode so as to edit the email itself, or else
 copy-paste
 the above into a text-edit window[*] and pre-edit it there before
 copying into R.

 [*] I would be using 'vim' in a Linux xterm. Removal of the  
 prompts (or +  continuation prompts) from a long series of commands
 is relatively easy: Just higlight a column-block of the first two
 columns, then press d to delete them. But you would first need to
 enter  _#  for other stuff by hand.

 Best wishes to all,
 Ted.


 johannes rara wrote:
 Hi,

 How do you people avoid copy-pasting and manual editing of the code
 posted in this list? I mean that if some one post a solution for an
 answer like this:


 a - 1:10
 a

 _[1] _1 _2 _3 _4 _5 _6 _7 _8 _9 10

 a[1:5]

 [1] 1 2 3 4 5


 I have to copy-paste it to e.g. Tinn-R and remove   part of the
 line to try it in my R. When you keep doing this it gets quite
 annoying. How do you people avoid this (search and replace,
 perhaps?).
 The best way would be to able to send this straight from your e-mail
 reader into R (e.g. from gmail).

 -Johannes

 
 E-Mail: (Ted Harding) 

[R] graphing help

2009-09-19 Thread Mag Gam
Hello:

I am very new to R, and I am trying to plot a large data set. I
would like to get a line graph. My data looks like this in a csv file
(no header):

07/03/23,05:00,23
07/03/23,06:00,32
07/03/23,07:00,33
07/03/23,08:00,25
07/03/23,09:00,26
07/03/23,10:00,21
07/03/23,11:00,23
07/03/23,12:00,24
07/03/23,13:00,25
07/03/23,14:00,29
07/03/23,15:00,23
07/03/23,16:00,23


TIA

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

2009-09-19 Thread Stefan Grosse
stephen sefick wrote:
 ?read.csv
 ?paste
 ?as.Date
 ?as.dataframe
 library(ggplot2)
 ?qplot
   

Also:
library(zoo)
?zoo

Stefan

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

2009-09-19 Thread Peter Dalgaard

Mag Gam wrote:

Hello:

I am very new to R, and I am trying to plot a large data set. I
would like to get a line graph. My data looks like this in a csv file
(no header):

07/03/23,05:00,23
07/03/23,06:00,32
07/03/23,07:00,33
07/03/23,08:00,25
07/03/23,09:00,26
07/03/23,10:00,21
07/03/23,11:00,23
07/03/23,12:00,24
07/03/23,13:00,25
07/03/23,14:00,29
07/03/23,15:00,23
07/03/23,16:00,23


TIA

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

dd - read.csv(clipboard, header=F)
dd
names(dd)- c(D,TOD,Y)
dd$T - as.POSIXct(paste(dd$D, dd$TOD), format=%y/%m/%d %H:%M)
plot(Y~T,data=dd, type=b)


--
   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
~~ - (p.dalga...@biostat.ku.dk)  FAX: (+45) 35327907

__
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] Why don't formulas that work for lm() work for plotmeans?

2009-09-19 Thread Peter Ehlers

Did lm(y ~ x | T) work for you? Let's see a reproducible example.

Peter

jrflanders wrote:

I know that simple line plots showing a point representing the mean + an
error bar are difficult in R, but I  am clearly missing something.  I simply
want to show how a the mean and 95% CI of a chemical concentration (y) vary
over space (x) under four temperature regimes (T; a categorical factor).
plotmeans, in the gplots library, should allow for such a figure, right?
After all, it invokes lm() in the help file for the formula, so any formula
that works in lm() (e.g., y~x | T) should work in plotmeans.  Obviously this
is not so - can anyone suggest an alternative  command or help me understand
how  the syntac differs? Thanks...


__
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] Use of R in Schools

2009-09-19 Thread Michael Knudsen
On Sat, Sep 19, 2009 at 6:28 AM, John Maindonald
john.maindon...@anu.edu.au wrote:

 I am looking for information on experimentation with the use
 of R in the teaching of statistics and science in schools.  Any
 leads would be very welcome.  I am certain that there is such
 experimentation.

I read this paper

http://www.ploscompbiol.org/article/info%3Adoi%2F10.1371%2Fjournal.pcbi.1000482

some days ago. It's quite interesting, and it links to some excellent
slides that look great as templates for making your own R course.

Best,
Michael

-- 
Michael Knudsen
micknud...@gmail.com
http://lifeofknudsen.blogspot.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] Replacing values in dataframes

2009-09-19 Thread Schalk Heunis
I think this is what you want
NAD$Sample.Id - t(Prot.amount[NAD$Sample.Id])

HTH
Schalk Heunis



On Sat, Sep 19, 2009 at 12:18 PM, Monna Nygård monn...@hotmail.com wrote:


 Hi,



 This is a question of a newbie getting into the exciting world of R.



 I have several dataframes in the same format as NAD:





  NAD[1:3,1:3]

Sample.Id Main.abs..1 Main.abs..2
 148   10a 0.04836 0.04994
 167  11a_1109 0.32245 0.36541
 173  11b_1109 0.29293 0.32815


 What I want to do is to replace the Sample.Id with a corresponding
 number.The number i have in another file,called Prot.amount



  Prot.amount[1:3,1]
 10a 11a_1109 11b_1109
  15.516   38.248   42.297





  row.names(NAD)-(NAD[,1])
  NAD$Sample.Id - replace(NAD$Sample.Id,
 NAD$Sample.Id==10a,Prot.amount[10a,1])

  NAD[1:3,1:3]
 Sample.Id Main.abs..1 Main.abs..2
 10a 15.516 0.04836 0.04994
 11a_1109  11a_1109 0.32245 0.36541
 11b_1109  11b_1109 0.29293 0.32815



 So what I have tried to do is to write a function that would allow me to
 replace the values automatically of all dataframes. This I just can't get to
 work.



 Thank you so much in advance!

 _
 [[elided Hotmail spam]]

[[alternative HTML version deleted]]

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


[[alternative HTML version deleted]]

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


Re: [R] Use of R in Schools

2009-09-19 Thread Erich Neuwirth
I cannot offer direct experience with schools,
but perhaps you are interested in having a look at RExcel
(I am the author) which makes R accessible within Excel
on Windows. One of the reasons of writing it was to make R
more easily accessible for statistics education.

rcom.univie.ac.at

has more information




John Maindonald wrote:
 I am looking for information on experimentation with the use
 of R in the teaching of statistics and science in schools.  Any
 leads would be very welcome.  I am certain that there is such
 experimentation.
 
 I've made this inquiry on r-sig-teaching, with no response.
 John.
 
 John Maindonald email: john.maindon...@anu.edu.au
 phone : +61 2 (6125)3473fax  : +61 2(6125)5549
 Centre for Mathematics  Its Applications, Room 1194,
 John Dedman Mathematical Sciences Building (Building 27)
 Australian National University, Canberra ACT 0200.
 
 __
 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.
 
 

-- 
Erich Neuwirth, University of Vienna
Faculty of Computer Science
Computer Supported Didactics Working Group
Visit our SunSITE at http://sunsite.univie.ac.at
Phone: +43-1-4277-39464 Fax: +43-1-4277-39459

__
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] Creating histograms from factors using a for loop

2009-09-19 Thread Peter Ehlers

Sam,

Your loop produces two jpegs but the second overwrites the first.
What do you expect

  levels(df[i,f])

to produce? (Think about it.)

Try

 jpeg(filename=paste(i,.jpg,sep=))

and you may want to fix the titles as well.

Peter

Sam Player wrote:

# I have a dataframe with data and factors similar to the following:

a - rep(c(a, b), c(6,6))
df - data.frame(f=a, d=rnorm(12))
df

# I am trying to write a 'for' loop which will produce a jpeg histogram 
for each factor. I can individually isolate the data from a factor and 
produce a jpeg histogram like so:


fnc - function(x){
x - df[df$f==a, d]
}

y - fnc(df[df$f==a, d])

jpeg(filename=foo.jpeg)
hist(y)
dev.off()

# I'm having trouble creating a loop repeating the process for all the 
other factors. The following is the best I could come up with. It 
produces a single jpeg histogram of the first factor titled with a list 
of all the factors.


a - rep(c(a, b), c(6,6))
df - data.frame(f=a, d=rnorm(12))
df

for (i in levels(df[,f])){
y - df[df$f==i, 2]
jpeg(filename=(levels(df[i,f])))
hist(y, main=levels(df[i,f]))
dev.off()
}

# I'm obviously not understanding how loops work with factors. Can 
anybody point me in the right direction?




__
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] How to avoid copy-paste when copying code from this list

2009-09-19 Thread Gabor Grothendieck
One solution would be to have a portable version of the
Windows

   Edit | Paste commands only

functionality that works on all platforms.

For example if a command such as this were available:

source.commands - function(echo = TRUE, ...) {
L - readLines(clipboard)
L - grep(^[+] , L, value = TRUE)
L - gsub(^.., , L)
source(textConnection(L), echo = echo, ...)
}

one could just copy the email snippet and the issue this command in
the R session:

source.commands()

Building this directly into source as an option might be nice.


On Sat, Sep 19, 2009 at 5:46 AM, Ted Harding
ted.hard...@manchester.ac.uk wrote:
 On 19-Sep-09 08:48:45, johannes rara wrote:
 The R help mailing list posting guide

 http://www.r-project.org/posting-guide.html

 suggests to give an example in this form

 ...snip...
 f I have a matrix x as follows:
    x - matrix(1:8, nrow=4, ncol=2,
                 dimnames=list(c(A,B,C,D), c(x,y))
    x
     x y
   A 1 5
   B 2 6
   C 3 7
   D 4 8
   
 ...snip...

 Would it be reasonable to consider changing this guide about this
 matter?

 Yes, I think there is a case for a change. I must have read the
 above myself, once, but ignored it later for the reasons I gave
 below. In any case, that citation is not in the context of advice
 about how to format R code when posting (there is no such advice
 explicitly given in the posting-guide), but in the context that it
 can be helpful to provide an example:

  Examples: Sometimes it helps to provide a small example that
   someone can actually run. For example:

 (then the example above). Possibly, people may tend to read that
 example as if it were advice on formatting the code.

 So maybe the change which could be helpful in the present context
 would be to follow the above example with a section which advised
 on how to format the code for examples which someone can actually
 run (they cannot actually run the code as given in the example).

 In other words, on the lines of

  When posting R code for examples, when this is copied from an R
  console remove any command prompts  and continuation prompts
  + from the code as it appears on the R console, and precede
  each line of R output, messages, etc., with # (to make it a
  comment, so that if the code is copy-pasted from R-help into an
  R console it will work as-is without the need for further editing.
  Example:
  [...]

 What do other people (in particular the maintainers of the posting
 guide) think?

 Some might argue that the  and + prompts serve to mark the
 presence of R code and distinguish it from message text. But then
 the result is something that nobody can actually run. I think,
 myself, that (especially with indenting of the code by a couple
 of spaces) the format I describe is clearly enough distinguished.

 Ted.

 2009/9/19 Ted Harding ted.hard...@manchester.ac.uk:
 On 19-Sep-09 08:00:18, Cedrick W. Johnson wrote:
 At least in windows, if you right click directly in the r console,
 there's a command for 'Paste commands only' which may be one
 solution...
 Not sure about other platforms..

 hth
 c

 It was precisely for this kind of reason that, when including
 R code in postings to the list, I took to formatting it in the
 following kind of way:

 _a - 1:10
 _a
 _# [1] _1 _2 _3 _4 _5 _6 _7 _8 _9 10

 _a[1:5]
 _# [1] 1 2 3 4 5

 In this way, any R commands copy-pasted into R will work as-is,
 anything else is a comment and will not interfere. I notice that
 some other people also post their code in this way.

 I recommend it to all! If the code has been copy-pasted into the
 email from an R console, then of course the  prompts will be
 there. But then I just edit these out of the email. A bit more
 trouble for me, but a lot less trouble for others.

 For instance, if someone had posted the above as copied from the
 R console in its original form

 a - 1:10
 a
 _[1] _1 _2 _3 _4 _5 _6 _7 _8 _9 10

 a[1:5]
 [1] 1 2 3 4 5

 and I wanted to try it out, then I would either have to re-open the
 email in edit mode so as to edit the email itself, or else
 copy-paste
 the above into a text-edit window[*] and pre-edit it there before
 copying into R.

 [*] I would be using 'vim' in a Linux xterm. Removal of the  
 prompts (or +  continuation prompts) from a long series of commands
 is relatively easy: Just higlight a column-block of the first two
 columns, then press d to delete them. But you would first need to
 enter  _#  for other stuff by hand.

 Best wishes to all,
 Ted.


 johannes rara wrote:
 Hi,

 How do you people avoid copy-pasting and manual editing of the code
 posted in this list? I mean that if some one post a solution for an
 answer like this:


 a - 1:10
 a

 _[1] _1 _2 _3 _4 _5 _6 _7 _8 _9 10

 a[1:5]

 [1] 1 2 3 4 5


 I have to copy-paste it to e.g. Tinn-R and remove   part of the
 line to try it in my R. When you keep doing this it gets quite
 annoying. How do you people avoid this (search and replace,
 perhaps?).
 The best way would be to able to send 

Re: [R] Creating histograms from factors using a for loop

2009-09-19 Thread David Winsemius


On Sep 19, 2009, at 5:37 AM, Sam Player wrote:


# I have a dataframe with data and factors similar to the following:

a - rep(c(a, b), c(6,6))
df - data.frame(f=a, d=rnorm(12))
df

# I am trying to write a 'for' loop which will produce a jpeg  
histogram for each factor. I can individually isolate the data from  
a factor and produce a jpeg histogram like so:


fnc - function(x){
   x - df[df$f==a, d]
}

y - fnc(df[df$f==a, d])

jpeg(filename=foo.jpeg)
hist(y)
dev.off()

# I'm having trouble creating a loop repeating the process for all  
the other factors. The following is the best I could come up with.  
It produces a single jpeg histogram of the first factor titled with  
a list of all the factors.


a - rep(c(a, b), c(6,6))
df - data.frame(f=a, d=rnorm(12))
df

for (i in levels(df[,f])){
   y - df[df$f==i, 2]
   jpeg(filename=(levels(df[i,f])))
   hist(y, main=levels(df[i,f]))
   dev.off()
   }


You are a bit unclear about what you are seeking but if you want  
separate file names and titles that are factor-specifich, then why not  
use i inside the loop as itself?


for (i in levels(df[,f])){
   y - df[df$f==i, 2]
   jpeg(filename=paste(file_,i,sep=))
   hist(y, main=paste(Factor =,i,sep=))
   dev.off()
   }


# I'm obviously not understanding how loops work with factors.


It seems that you are unclear about loop indices. You are not really  
passing factors anyway, but rather elements of a character vector,  
levels(df[,f]).



Can anybody point me in the right direction?

--
Sam Player, B.Sc.(Hons.) B.A.
Ph.D. Candidate, Faculty of Agriculture, Food  Natural Resources,  
University of Sydney


Email: spla...@usyd.edu.au

Agroecosystems Research Group
Room 214 J.R.A. McMillan Building A05
University of Sydney NSW 2006, Australia

Angkor Research Program
Room 305 Old Teachers College A22
University of Sydney NSW 2006, Australia

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


David Winsemius, MD
Heritage Laboratories
West Hartford, CT

__
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] Counting observations of a combined factor

2009-09-19 Thread Peter Ehlers

Sam,

Depending on what your ultimate aim is, perhaps you just want to add
the 'drop=TRUE' argument to your interaction call.

Peter

Sam Player wrote:
#I have a dataset with two factor. I want to combine those factors into 
a single factor and count the number of data values for each new factor. 
The following gives a comparable dataframe:


a - rep(c(a, b), c(6,6))
b - rep(c(c, d), c(6,6))
df - data.frame(f1=a, f2=b, d=rnorm(12))
df

# I use the 'interaction' function to combine factors f1 and f2:

df2 - data.frame(f3=interaction(df[,f1], df[,f2]), d=df[,d])
df2

# A count of the first data.frame using factor f1 returns the kind of 
results I am looking for:


count - as.data.frame(table(df$f1))
count

#  Var1 Freq
#1a6
#2b6

# As does a count using factor2:

count2 - as.data.frame(table(df$f2))
count2

#  Var1 Freq
#1a6
#2b6

# The same procedure on the second dataframe does not treat the levels 
of factor f3 discreetly, instead giving all possible combinations of f1 
and f2.


count3 - as.data.frame(table(df2$f3))
count3

#  Var1 Freq
#1  a.c6
#2  b.c0
#3  a.d0
#4  b.d6

I need the results to be:

#  Var1 Freq
#1a6
#2b6

# Any suggestions?



__
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] Creating histograms from factors using a for loop

2009-09-19 Thread Schalk Heunis
You could plot both histograms into the same file using this:
library(lattice)
jpeg(filename=combined.jpeg)
histogram(~d|f, data = df)
dev.off()

Schalk Heunis


On Sat, Sep 19, 2009 at 11:37 AM, Sam Player samtpla...@gmail.com wrote:

 # I have a dataframe with data and factors similar to the following:

 a - rep(c(a, b), c(6,6))
 df - data.frame(f=a, d=rnorm(12))
 df

 # I am trying to write a 'for' loop which will produce a jpeg histogram for
 each factor. I can individually isolate the data from a factor and produce a
 jpeg histogram like so:

 fnc - function(x){
x - df[df$f==a, d]
 }

 y - fnc(df[df$f==a, d])

 jpeg(filename=foo.jpeg)
 hist(y)
 dev.off()

 # I'm having trouble creating a loop repeating the process for all the
 other factors. The following is the best I could come up with. It produces a
 single jpeg histogram of the first factor titled with a list of all the
 factors.

 a - rep(c(a, b), c(6,6))
 df - data.frame(f=a, d=rnorm(12))
 df

 for (i in levels(df[,f])){
y - df[df$f==i, 2]
jpeg(filename=(levels(df[i,f])))
hist(y, main=levels(df[i,f]))
dev.off()
}

 # I'm obviously not understanding how loops work with factors. Can anybody
 point me in the right direction?

 --
 Sam Player, B.Sc.(Hons.) B.A.
 Ph.D. Candidate, Faculty of Agriculture, Food  Natural Resources,
 University of Sydney

 Email: spla...@usyd.edu.au

 Agroecosystems Research Group
 Room 214 J.R.A. McMillan Building A05
 University of Sydney NSW 2006, Australia

 Angkor Research Program
 Room 305 Old Teachers College A22
 University of Sydney NSW 2006, Australia

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


[[alternative HTML version deleted]]

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


Re: [R] Counting observations of a combined factor

2009-09-19 Thread David Winsemius


On Sep 19, 2009, at 5:39 AM, Sam Player wrote:

#I have a dataset with two factor. I want to combine those factors  
into a single factor and count the number of data values for each  
new factor. The following gives a comparable dataframe:


a - rep(c(a, b), c(6,6))
b - rep(c(c, d), c(6,6))
df - data.frame(f1=a, f2=b, d=rnorm(12))
df

# I use the 'interaction' function to combine factors f1 and f2:

df2 - data.frame(f3=interaction(df[,f1], df[,f2]), d=df[,d])
df2

# A count of the first data.frame using factor f1 returns the kind  
of results I am looking for:


count - as.data.frame(table(df$f1))
count

#  Var1 Freq
#1a6
#2b6

# As does a count using factor2:

count2 - as.data.frame(table(df$f2))
count2

#  Var1 Freq
#1a6
#2b6

# The same procedure on the second dataframe does not treat the  
levels of factor f3 discreetly, instead giving all possible  
combinations of f1 and f2.


We appear to have a different understanding of the term discrete.  
The interaction function produces all possible combinations of factors  
and then table() counts the occurrences of such.




count3 - as.data.frame(table(df2$f3))
count3

#  Var1 Freq
#1  a.c6
#2  b.c0
#3  a.d0
#4  b.d6

I need the results to be:

#  Var1 Freq
#1a6
#2b6


Puzzled. You already have such. Why would you want the interaction  
function to behave differently?
Did you just want to create a label from f1 and f2? That can be  
achieved:


 df2 - df
 df2$f12 - with( df2, paste(f1,f2,sep=.) )
 df2
   f1 f2   d f12
1   a  c -0.52902802 a.c
2   a  c -1.07351118 a.c
3   a  c  0.63463011 a.c
4   a  c  0.26857599 a.c
5   a  c  1.57677999 a.c
6   a  c  1.08645153 a.c
7   b  d -0.60400852 b.d
8   b  d -0.06611533 b.d
9   b  d  1.00787048 b.d
10  b  d  1.48289305 b.d
11  b  d  0.5465 b.d
12  b  d -0.67630052 b.d

 count3 - as.data.frame(table(df2$f12))
 count3
  Var1 Freq
1  a.c6
2  b.d6







# Any suggestions?

--
Sam Player, B.Sc.(Hons.) B.A.
Ph.D. Candidate, Faculty of Agriculture, Food  Natural Resources,  
University of Sydney


Email: spla...@usyd.edu.au

Agroecosystems Research Group
Room 214 J.R.A. McMillan Building A05
University of Sydney NSW 2006, Australia

Angkor Research Program
Room 305 Old Teachers College A22
University of Sydney NSW 2006, Australia

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


David Winsemius, MD
Heritage Laboratories
West Hartford, CT

__
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] How to avoid copy-paste when copying code from this list

2009-09-19 Thread Ted Harding
On 19-Sep-09 14:12:08, Gabor Grothendieck wrote:
 One solution would be to have a portable version of the
 Windows
 
Edit | Paste commands only
 
 functionality that works on all platforms.
 
 For example if a command such as this were available:
 
 source.commands - function(echo = TRUE, ...) {
 L - readLines(clipboard)
 L - grep(^[+] , L, value = TRUE)
 L - gsub(^.., , L)
 source(textConnection(L), echo = echo, ...)
 }
 
 one could just copy the email snippet and the issue this command in
 the R session:
 
 source.commands()
 
 Building this directly into source as an option might be nice.

Neat, Gabor! I just tried it out on the following:

 TP - function(x){
+   L - length(x)
+   which( ((x[1:(L-2)]x[2:(N-1)])(x[2:(L-1)]x[3:L]))
+ |((x[1:(L-2)]x[2:(N-1)])(x[2:(L-1)]x[3:L])) ) + 1
+ }
 y-c(93,93,93,93,93,93,93,93,93,93,93,
+  93,93,93,93,93,93,93,93,93,93,93)
 m-c(02,02,02,02,02,02,02,02,02,02,02,
+  02,02,02,02,02,02,02,02,02,02,02)
 d-c(07,08,09,10,11,12,13,14,15,16,17,
+  18,19,20,21,22,23,24,25,26,27,28)
 
 ix - TP(count)
 rbind(d[ix],count[ix])
   [,1] [,2]   [,3] [,4] [,5]   [,6]   [,7]   [,8]   [,9]
[1,]8.0   10   12.0   13   15   17.0   20.0   23.0   27.0
[2,] 3976.7 3955 3972.8 3961 4008 3981.2 4029.5 3848.3 3936.7

(which was the basis of my response on 17 Sept 2009 to Ogbos Okike's
query about turning-points, though then I edited out the prompts, etc.).

After entering the definition of your function source.commands(),
with the above already executed in an R session running in a Linux
xterm, I highlighted all the above with the mouse (which puts it in
the clipboard) and then, leaving it highlighted, entered the
command souce.commands().
This was the result (as it appeared on-screen):

 source.commands()

 TP - function(x){
+   L - length(x)
+   which( ((x[1:(L-2)]x[2:(N-1)])(x[2:(L-1)]x[3:L]))
+ |((x[1:(L-2)]x[2:(N-1)])(x[2:(L-1)]x[3:L  [TRUNCATED] 

 y - c(93, 93, 93, 93, 93, 93, 93, 93, 93, 93, 93, 
+ 93, 93, 93, 93, 93, 93, 93, 93, 93, 93, 93)

 m - c(2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 
+ 2, 2, 2, 2, 2, 2, 2)

 d - c(7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 
+ 19, 20, 21, 22, 23, 24, 25, 26, 27, 28)

 ix - TP(count)

 rbind(d[ix], count[ix])
   [,1] [,2]   [,3] [,4] [,5]   [,6]   [,7]   [,8]   [,9]
[1,]8.0   10   12.0   13   15   17.0   20.0   23.0   27.0
[2,] 3976.7 3955 3972.8 3961 4008 3981.2 4029.5 3848.3 3936.7

To check again, I opened Jens Oehlschlägel'e query on 18 Sept.
about basename, which contains the lines:

 dirname(./.)
[1] .
 basename(./.)
[1] .
 dirname(./)
[1] .
 basename(./)
[1] .

I highlighted these, went back to the R window, and again issued
your command. Result:

 source.commands()

 dirname(./.)
[1] .

 basename(./.)
[1] .

 dirname(./)
[1] .

 basename(./)
[1] .

So it seems to work fine!

At any rate for basic use. I think it could have problems in some
cases, such as if the user had executed

cat( rbind(d[ix], count[ix]))
8 3976.7 10 3955 12 3972.8 13 3961 15 4008 17 3981.2 20 4029.5 23 3848.3
27 3936.7 

But, most of the time, it should just work.

Thanks for the tip. One for my .Rprofile, I think!
Ted.






 On Sat, Sep 19, 2009 at 5:46 AM, Ted Harding
 ted.hard...@manchester.ac.uk wrote:
 On 19-Sep-09 08:48:45, johannes rara wrote:
 The R help mailing list posting guide

 http://www.r-project.org/posting-guide.html

 suggests to give an example in this form

 ...snip...
 f I have a matrix x as follows:
 _  x - matrix(1:8, nrow=4, ncol=2,
 _ _ _ _ _ _ _ _ dimnames=list(c(A,B,C,D), c(x,y))
 _  x
 _ _ x y
 _ A 1 5
 _ B 2 6
 _ C 3 7
 _ D 4 8
 _ 
 ...snip...

 Would it be reasonable to consider changing this guide about this
 matter?

 Yes, I think there is a case for a change. I must have read the
 above myself, once, but ignored it later for the reasons I gave
 below. In any case, that citation is not in the context of advice
 about how to format R code when posting (there is no such advice
 explicitly given in the posting-guide), but in the context that it
 can be helpful to provide an example:

 _Examples: Sometimes it helps to provide a small example that
 _ someone can actually run. For example:

 (then the example above). Possibly, people may tend to read that
 example as if it were advice on formatting the code.

 So maybe the change which could be helpful in the present context
 would be to follow the above example with a section which advised
 on how to format the code for examples which someone can actually
 run (they cannot actually run the code as given in the example).

 In other words, on the lines of

 _When posting R code for examples, when this is copied from an R
 _console remove any command prompts  and continuation prompts
 _+ from the code as it appears on the R console, and precede
 _each line of R output, messages, etc., with # (to make it a
 _comment, so that if the code is copy-pasted from R-help into an
 _R console it will work as-is without 

Re: [R] How to avoid copy-paste when copying code from this list

2009-09-19 Thread Duncan Murdoch

On 19/09/2009 10:12 AM, Gabor Grothendieck wrote:

One solution would be to have a portable version of the
Windows

   Edit | Paste commands only

functionality that works on all platforms.

For example if a command such as this were available:

source.commands - function(echo = TRUE, ...) {
L - readLines(clipboard)
L - grep(^[+] , L, value = TRUE)
L - gsub(^.., , L)
source(textConnection(L), echo = echo, ...)
}

one could just copy the email snippet and the issue this command in
the R session:

source.commands()

Building this directly into source as an option might be nice.


The Windows Rgui is uses slightly more general patterns than those so it 
can take output from running examples, e.g.


 example(mean)

mean x - c(0:10, 50)

mean xm - mean(x)

m
[1] 8.75 5.50

mean mean(USArrests, trim = 0.2)
  Murder  Assault UrbanPop Rape
7.42   167.6066.2020.16

(and does it in C code, not using grep/gsub; see CleanTranscript in 
https://svn.r-project.org/R/trunk/src/gnuwin32/console.c), but that's 
basically what it does.


However, it's hard to do this in a portable way, because not all systems 
support clipboard as the name of the clipboard for cut and paste.  I 
think Unix/Linux systems need to be running X11, and OSX systems don't 
normally support it in the GUI.  So it might makes sense to have a 
portable version of the CleanTranscript function available, but it's 
really up to each different system to connect it up to cut and paste.


Here's a quick version of CleanTranscript, translated to R:

CleanTranscript - function(lines) {
  lines - grep(^[[:blank:]]*[^+[:blank:]]*[+], lines, value = TRUE)
  lines - sub(^[[:blank:]]*[^+[:blank:]]*[+] ?, , lines)
}

So on systems where clipboard is supported, executing

source(textConnection(CleanTranscript(readLines(clipboard))),
echo = TRUE, max.deparse.length=Inf)

will do something similar to what the Windows Paste commands only menu 
option does, but you'd need a different incantation on other systems. 
And even this will sometimes mess up, e.g. it will sometimes 
misinterpret output that contains  or + as input.


Duncan Murdoch




On Sat, Sep 19, 2009 at 5:46 AM, Ted Harding
ted.hard...@manchester.ac.uk wrote:

On 19-Sep-09 08:48:45, johannes rara wrote:

The R help mailing list posting guide

http://www.r-project.org/posting-guide.html

suggests to give an example in this form

...snip...
f I have a matrix x as follows:
   x - matrix(1:8, nrow=4, ncol=2,
dimnames=list(c(A,B,C,D), c(x,y))
   x
x y
  A 1 5
  B 2 6
  C 3 7
  D 4 8
  
...snip...

Would it be reasonable to consider changing this guide about this
matter?

Yes, I think there is a case for a change. I must have read the
above myself, once, but ignored it later for the reasons I gave
below. In any case, that citation is not in the context of advice
about how to format R code when posting (there is no such advice
explicitly given in the posting-guide), but in the context that it
can be helpful to provide an example:

 Examples: Sometimes it helps to provide a small example that
  someone can actually run. For example:

(then the example above). Possibly, people may tend to read that
example as if it were advice on formatting the code.

So maybe the change which could be helpful in the present context
would be to follow the above example with a section which advised
on how to format the code for examples which someone can actually
run (they cannot actually run the code as given in the example).

In other words, on the lines of

 When posting R code for examples, when this is copied from an R
 console remove any command prompts  and continuation prompts
 + from the code as it appears on the R console, and precede
 each line of R output, messages, etc., with # (to make it a
 comment, so that if the code is copy-pasted from R-help into an
 R console it will work as-is without the need for further editing.
 Example:
 [...]

What do other people (in particular the maintainers of the posting
guide) think?

Some might argue that the  and + prompts serve to mark the
presence of R code and distinguish it from message text. But then
the result is something that nobody can actually run. I think,
myself, that (especially with indenting of the code by a couple
of spaces) the format I describe is clearly enough distinguished.

Ted.


2009/9/19 Ted Harding ted.hard...@manchester.ac.uk:

On 19-Sep-09 08:00:18, Cedrick W. Johnson wrote:

At least in windows, if you right click directly in the r console,
there's a command for 'Paste commands only' which may be one
solution...
Not sure about other platforms..

hth
c

It was precisely for this kind of reason that, when including
R code in postings to the list, I took to formatting it in the
following kind of way:

_a - 1:10
_a
_# [1] _1 _2 _3 _4 _5 _6 _7 _8 _9 10

_a[1:5]
_# [1] 1 2 3 4 5

In this way, any R commands copy-pasted into R will work as-is,
anything else is a comment and will not interfere. I 

Re: [R] How to avoid copy-paste when copying code from this list

2009-09-19 Thread David Winsemius


On Sep 19, 2009, at 10:58 AM, Duncan Murdoch wrote:


On 19/09/2009 10:12 AM, Gabor Grothendieck wrote:

One solution would be to have a portable version of the
Windows
  Edit | Paste commands only
functionality that works on all platforms.
For example if a command such as this were available:
source.commands - function(echo = TRUE, ...) {
   L - readLines(clipboard)
   L - grep(^[+] , L, value = TRUE)
   L - gsub(^.., , L)
   source(textConnection(L), echo = echo, ...)
}
one could just copy the email snippet and the issue this command in
the R session:
source.commands()
Building this directly into source as an option might be nice.


The Windows Rgui is uses slightly more general patterns than those  
so it can take output from running examples, e.g.


 example(mean)

mean x - c(0:10, 50)

mean xm - mean(x)

m
[1] 8.75 5.50

mean mean(USArrests, trim = 0.2)
 Murder  Assault UrbanPop Rape
   7.42   167.6066.2020.16

(and does it in C code, not using grep/gsub; see CleanTranscript in https://svn.r-project.org/R/trunk/src/gnuwin32/console.c) 
, but that's basically what it does.


However, it's hard to do this in a portable way, because not all  
systems support clipboard as the name of the clipboard for cut and  
paste.  I think Unix/Linux systems need to be running X11, and OSX  
systems don't normally support it in the GUI.  So it might makes  
sense to have a portable version of the CleanTranscript function  
available, but it's really up to each different system to connect it  
up to cut and paste.


Here's a quick version of CleanTranscript, translated to R:

CleanTranscript - function(lines) {
 lines - grep(^[[:blank:]]*[^+[:blank:]]*[+], lines, value =  
TRUE)

 lines - sub(^[[:blank:]]*[^+[:blank:]]*[+] ?, , lines)
}

So on systems where clipboard is supported, executing

source(textConnection(CleanTranscript(readLines(clipboard))),
   echo = TRUE, max.deparse.length=Inf)

will do something similar to what the Windows Paste commands only  
menu option does, but you'd need a different incantation on other  
systems. And even this will sometimes mess up, e.g. it will  
sometimes misinterpret output that contains  or + as input.


Duncan Murdoch


On Macs (and possibly other *NIXen) the equivalent to reading from the  
clipboard is: pipe(pbpaste)


Testing shows that a simple modification after defining  
CleanTranscript produces no error on the example above:


 source(textConnection(CleanTranscript(readLines(pipe(pbpaste,
+echo = TRUE, max.deparse.length=Inf)

 example(mean)

mean x - c(0:10, 50)

mean xm - mean(x)

mean c(xm, mean(x, trim = 0.10))
[1] 8.75 5.50

mean mean(USArrests, trim = 0.2)
  Murder  Assault UrbanPop Rape
7.42   167.6066.2020.16

 x - c(0:10, 50)

--

David Winsemius, MD
Heritage Laboratories
West Hartford, CT

__
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] matrix operations on grobs and grid units

2009-09-19 Thread baptiste auguie
Dear list,

As a minimal test of a more complex grid layout, I'm trying to find a
clean and efficient way to arrange text grobs in a rectangular layout.
The labels may be expressions, or text with a fontsize different of
the default, which means that the cell sizes should probably be
calculated using grobWidth() and grobHeight() as opposed to simpler
stringWidth() and stringHeight(). (Correct?).

The input of this function is a vector of labels, which are arranged
into a matrix layout. Below is my current version, followed by a few
questions.

e = expression(alpha,testing very large width, hat(beta),
integral(f(x)*dx, a, b))

rowMax.units - function(u, nrow){ # rowMax with a fake matrix of units
 matrix.indices - matrix(seq_along(u), nrow=nrow)
 do.call(unit.c, lapply(seq(1, nrow), function(ii) {
  max(u[matrix.indices[ii, ]])
 }))
}

colMax.units - function(u, ncol){ # colMax with a fake matrix of units
 matrix.indices - matrix(seq_along(u), ncol=ncol)
 do.call(unit.c, lapply(seq(1, ncol), function(ii) {
  max(u[matrix.indices[, ii]])
 }))
}


makeTableGrobs - function(e, ncol, nrow,
   just = c(center, center),
   gpar.text = gpar(col=black, cex=1),
   gpar.fill = gpar(fill = grey95, col=white, lwd=1.5)) {

 n - length(e) # number of labels

stopifnot(!n%%2) # only rectangular layouts

 if(missing(ncol)  missing(nrow)){
 nm - n2mfrow(n)  # pretty default layout
 ncol = nm[1]
 nrow = nm[2]
}

makeOneLabel - function(label.ind){
textGrob(label=e[label.ind], gp=gpar.text,
name=paste(cells-label-,label.ind, sep=))
}

lg - lapply(seq_along(e), makeOneLabel) # list of grobs
wg - lapply(lg, grobWidth) # list of grob widths
hg - lapply(lg, grobHeight) # list of grob heights

widths.all - do.call(unit.c, wg)
heights.all - do.call(unit.c, hg)

widths - colMax.units(widths.all, ncol)
heights - rowMax.units(heights.all, nrow)

   gcells = frameGrob(name=table.cells, vp = cells,
   layout = grid.layout(nrow, ncol, just=just,
   widths = widths,
   heights = heights) )

   label.ind - 1 # index running for the vector of labels

   for (ii in seq(1, ncol, 1)) {
   for (jj in seq(1, nrow, 1)) {

   gcells = placeGrob(gcells, rectGrob(gp=gpar.fill,
name=paste(cells-fill-r,ii, -c,jj,sep=)),
row=jj, col=ii)

  text.grob.ij = textGrob(label=e[label.ind],
gp=gpar.text, name=paste(cells-label-r,ii,
-c,jj,sep=))

   gcells = placeGrob(gcells, text.grob.ij, row=jj, col=ii)

   label.ind - label.ind + 1
   }
   }

gList( gcells)
}

# tests
vp = viewport(name=cells)
grid.draw(gTree(children=makeTableGrobs(e), childrenvp=vp))
grid.newpage()
grid.draw(gTree(children=makeTableGrobs(e, 1, 4), childrenvp=vp))
grid.newpage()
grid.draw(gTree(children=makeTableGrobs(e, 4, 1), childrenvp=vp))

This works as expected, however I would like some advice before going
any further,

- because this layout seems quite common, would it make sense to
provide methods for the following objects? (i) a matrix of grobs; (ii)
a matrix of units; (iii) cbind, rbind, rowMax, colMax methods for a
matrix of units.

- is there a better, recommended way to achieve the same thing?
(examples would be great)

Any other comments are very welcome.

Best regards,

baptiste

__
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] Re-order columns

2009-09-19 Thread Santosh
Dear R'sians,
Would really appreciate if you could suggest a more efficient way to order
the columns of a dataset. The column names of the dataset contain indices
separated by a period. Following are examples of my code and the dataset.

oC - function(tg=x2) {
lth- length(grep(T,names(tg)))
thix   - match(paste(T,seq(lth),sep=),names(tg))
soi- c(grep(O,names(tg),fixed=T),grep(S,names(tg),fixed=T))
oi -
data.frame(t(data.frame(strsplit(names(tg)[soi],\\.),stringsAsFactors=F)),stringsAsFactors=F)
names(oi) - c(par,ix1,ix2);row.names(oi) - NULL
oi$cnm - sub(^\\s+((.*\\S)\\s+)?$, \\2, paste(
,paste(oi$par,oi$ix1,oi$ix2, ,sep=.),sep=))
oi1- oi[order(oi$par,as.integer(oi$ix1),as.integer(oi$ix2)),]
return(list(oi1=oi1,thix=thix))
 }

x1 - c(TABLE NO. 1: Gold ,
 RT2   T1   O.4.1.   O.3.1.
S.1.1.   ,
0  3.68000E+01  1.41000E+03  4.94000E+03  2.33000E+01
4.9E+01,
   43  3.77870E+01  2.46260E+03  4.44227E+03  2.31390E+01
4.84272E+01,
   -1  3.67870E+01  1.46260E+03  4.44227E+03  2.31390E+01
4.84271E+01)
x2 - read.table(textConnection(x1),as.is=T,head=T,skip=1)
x3 - oC(x2)
pcols  - c(names(x2)[x3$thix],x3$oi1$cnm)
x4 - x2[,match(c(setdiff(names(x2),pcols),pcols),names(x2))]

Thanks a TON

Santosh

[[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] Re-order columns

2009-09-19 Thread John Kane
I'm not sure I understand what you are doing below but to rearrange columns of 
a data.frame you can just rearrange the indices.  Is this what you mean?

A couple of examples:

(mydata - data.frame(aa=as.character(c(a, b, c, d, e)), bb = 1:5))

(mydata  - mydata[,2:1])


df1 - structure(list(site = c(1, 1, 4, 4, 1, 4), id = structure(c(1L,
2L, 2L, 3L, 1L, 2L), .Label = c(a, b, c), class = factor),
cata = c(1, 1, 6, 1, 1, NA), catb = c(1, 2, 3, 4, 5, 6),
doga = c(3, 5, 3, 6, 4, 0), dogb = c(2, 4, 6, 8, 10, 12),
rata = c(NA, 9, 9, 8, 9, 8), ratb = c(1, 2, 3, 4, 5, 6),
bata = c(12, 42, NA, 45, 32, 54), batb = c(13, 15, 17, 19,
21, 23)), .Names = c(site, id, cata, catb, doga,
dogb, rata, ratb, bata, batb), row.names = c(aa,
bb, cc, dd, ee, ff), class = data.frame)

df1

(df1 - df1[,rev(1:10)])


--- On Sat, 9/19/09, Santosh santosh2...@gmail.com wrote:

 From: Santosh santosh2...@gmail.com
 Subject: [R] Re-order columns
 To: r-help@r-project.org
 Received: Saturday, September 19, 2009, 11:25 AM
 Dear R'sians,
 Would really appreciate if you could suggest a more
 efficient way to order
 the columns of a dataset. The column names of the dataset
 contain indices
 separated by a period. Following are examples of my code
 and the dataset.
 
 oC - function(tg=x2) {
     lth    -
 length(grep(T,names(tg)))
     thix   -
 match(paste(T,seq(lth),sep=),names(tg))
     soi    -
 c(grep(O,names(tg),fixed=T),grep(S,names(tg),fixed=T))
     oi     -
 data.frame(t(data.frame(strsplit(names(tg)[soi],\\.),stringsAsFactors=F)),stringsAsFactors=F)
     names(oi) -
 c(par,ix1,ix2);row.names(oi) - NULL
     oi$cnm - sub(^\\s+((.*\\S)\\s+)?$,
 \\2, paste(
 ,paste(oi$par,oi$ix1,oi$ix2, ,sep=.),sep=))
     oi1    -
 oi[order(oi$par,as.integer(oi$ix1),as.integer(oi$ix2)),]
     return(list(oi1=oi1,thix=thix))
  }
 
 x1 - c(TABLE NO. 1: Gold ,
  R            T2 
          T1   
        O.4.1.   
    O.3.1.
 S.1.1.       ,
             0 
 3.68000E+01  1.41000E+03  4.94000E+03 
 2.33000E+01
 4.9E+01,
            43 
 3.77870E+01  2.46260E+03  4.44227E+03 
 2.31390E+01
 4.84272E+01,
            -1 
 3.67870E+01  1.46260E+03  4.44227E+03 
 2.31390E+01
 4.84271E+01)
 x2 -
 read.table(textConnection(x1),as.is=T,head=T,skip=1)
 x3 - oC(x2)
 pcols  - c(names(x2)[x3$thix],x3$oi1$cnm)
 x4 -
 x2[,match(c(setdiff(names(x2),pcols),pcols),names(x2))]
 
 Thanks a TON
 
 Santosh
 
     [[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.
 


  __
Get a 
__
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] How to avoid copy-paste when copying code from this list

2009-09-19 Thread johannes rara
Thanks for the responses.

I think that the best way to avoid lots of hassle is that people
copy-paste their solutions from their code editor, NOT from R console.
For example, I usually save those solutions for my code archive, and
if I want to run these later on (using Tinn-R), I have to parse 
and + marks anyway.

-Johannes

2009/9/19 David Winsemius dwinsem...@comcast.net:

 On Sep 19, 2009, at 10:58 AM, Duncan Murdoch wrote:

 On 19/09/2009 10:12 AM, Gabor Grothendieck wrote:

 One solution would be to have a portable version of the
 Windows
  Edit | Paste commands only
 functionality that works on all platforms.
 For example if a command such as this were available:
 source.commands - function(echo = TRUE, ...) {
   L - readLines(clipboard)
   L - grep(^[+] , L, value = TRUE)
   L - gsub(^.., , L)
   source(textConnection(L), echo = echo, ...)
 }
 one could just copy the email snippet and the issue this command in
 the R session:
 source.commands()
 Building this directly into source as an option might be nice.

 The Windows Rgui is uses slightly more general patterns than those so it
 can take output from running examples, e.g.

  example(mean)

 mean x - c(0:10, 50)

 mean xm - mean(x)

 m
 [1] 8.75 5.50

 mean mean(USArrests, trim = 0.2)
  Murder  Assault UrbanPop     Rape
   7.42   167.60    66.20    20.16

 (and does it in C code, not using grep/gsub; see CleanTranscript in
 https://svn.r-project.org/R/trunk/src/gnuwin32/console.c), but that's
 basically what it does.

 However, it's hard to do this in a portable way, because not all systems
 support clipboard as the name of the clipboard for cut and paste.  I think
 Unix/Linux systems need to be running X11, and OSX systems don't normally
 support it in the GUI.  So it might makes sense to have a portable version
 of the CleanTranscript function available, but it's really up to each
 different system to connect it up to cut and paste.

 Here's a quick version of CleanTranscript, translated to R:

 CleanTranscript - function(lines) {
  lines - grep(^[[:blank:]]*[^+[:blank:]]*[+], lines, value = TRUE)
  lines - sub(^[[:blank:]]*[^+[:blank:]]*[+] ?, , lines)
 }

 So on systems where clipboard is supported, executing

 source(textConnection(CleanTranscript(readLines(clipboard))),
       echo = TRUE, max.deparse.length=Inf)

 will do something similar to what the Windows Paste commands only menu
 option does, but you'd need a different incantation on other systems. And
 even this will sometimes mess up, e.g. it will sometimes misinterpret output
 that contains  or + as input.

 Duncan Murdoch

 On Macs (and possibly other *NIXen) the equivalent to reading from the
 clipboard is: pipe(pbpaste)

 Testing shows that a simple modification after defining CleanTranscript
 produces no error on the example above:

 source(textConnection(CleanTranscript(readLines(pipe(pbpaste,
 +        echo = TRUE, max.deparse.length=Inf)

 example(mean)

 mean x - c(0:10, 50)

 mean xm - mean(x)

 mean c(xm, mean(x, trim = 0.10))
 [1] 8.75 5.50

 mean mean(USArrests, trim = 0.2)
  Murder  Assault UrbanPop     Rape
    7.42   167.60    66.20    20.16

 x - c(0:10, 50)

 --

 David Winsemius, MD
 Heritage Laboratories
 West Hartford, CT

 __
 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] How to avoid copy-paste when copying code from this list

2009-09-19 Thread David Winsemius


On Sep 19, 2009, at 11:58 AM, johannes rara wrote:


Thanks for the responses.

I think that the best way to avoid lots of hassle is that people
copy-paste their solutions from their code editor, NOT from R console.
For example, I usually save those solutions for my code archive, and
if I want to run these later on (using Tinn-R), I have to parse 
and + marks anyway.


I agree entirely but trying to change posting behavior appears to be a  
difficult exercise. It would also be much preferred if people would  
learn to post the output of dput on an object, rather than what is  
displayed on the console when the object is print()ed.


--
David.


-Johannes

2009/9/19 David Winsemius dwinsem...@comcast.net:


On Sep 19, 2009, at 10:58 AM, Duncan Murdoch wrote:



snip



Here's a quick version of CleanTranscript, translated to R:

CleanTranscript - function(lines) {
 lines - grep(^[[:blank:]]*[^+[:blank:]]*[+], lines, value =  
TRUE)

 lines - sub(^[[:blank:]]*[^+[:blank:]]*[+] ?, , lines)
}

So on systems where clipboard is supported, executing

source(textConnection(CleanTranscript(readLines(clipboard))),
  echo = TRUE, max.deparse.length=Inf)

will do something similar to what the Windows Paste commands  
only menu
option does, but you'd need a different incantation on other  
systems. And
even this will sometimes mess up, e.g. it will sometimes  
misinterpret output

that contains  or + as input.

Duncan Murdoch


On Macs (and possibly other *NIXen) the equivalent to reading from  
the

clipboard is: pipe(pbpaste)

Testing shows that a simple modification after defining  
CleanTranscript

produces no error on the example above:


source(textConnection(CleanTranscript(readLines(pipe(pbpaste,

+echo = TRUE, max.deparse.length=Inf)


example(mean)





snip

David Winsemius, MD
Heritage Laboratories
West Hartford, CT

__
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] How to avoid copy-paste when copying code from this list

2009-09-19 Thread Gabor Grothendieck
Combining the code posted by myself, Duncan and David we have:

# Usage: copy code from r-help to clipboard, then in R enter this:
#   source.commands()
#
source.commands - function(echo = TRUE, max.deparse.length = Inf, ...) {
   # L - readLines(pipe(pbpaste)) # use this instead for Mac
   L - readLines(clipboard)
   L - grep(^[[:blank:]]*[^+[:blank:]]*[+], L, value = TRUE)
   L - sub(^[[:blank:]]*[^+[:blank:]]*[+] ?, , L)
   source(textConnection(L), echo = echo,
  max.deparse.length = max.deparse.length, ...)
}

It might be possible to automate the check for Mac using .Platform$GUI


On Sat, Sep 19, 2009 at 12:08 PM, David Winsemius
dwinsem...@comcast.net wrote:

 On Sep 19, 2009, at 11:58 AM, johannes rara wrote:

 Thanks for the responses.

 I think that the best way to avoid lots of hassle is that people
 copy-paste their solutions from their code editor, NOT from R console.
 For example, I usually save those solutions for my code archive, and
 if I want to run these later on (using Tinn-R), I have to parse 
 and + marks anyway.

 I agree entirely but trying to change posting behavior appears to be a
 difficult exercise. It would also be much preferred if people would learn to
 post the output of dput on an object, rather than what is displayed on the
 console when the object is print()ed.

 --
 David.

 -Johannes

 2009/9/19 David Winsemius dwinsem...@comcast.net:

 On Sep 19, 2009, at 10:58 AM, Duncan Murdoch wrote:


 snip


 Here's a quick version of CleanTranscript, translated to R:

 CleanTranscript - function(lines) {
  lines - grep(^[[:blank:]]*[^+[:blank:]]*[+], lines, value = TRUE)
  lines - sub(^[[:blank:]]*[^+[:blank:]]*[+] ?, , lines)
 }

 So on systems where clipboard is supported, executing

 source(textConnection(CleanTranscript(readLines(clipboard))),
      echo = TRUE, max.deparse.length=Inf)

 will do something similar to what the Windows Paste commands only menu
 option does, but you'd need a different incantation on other systems.
 And
 even this will sometimes mess up, e.g. it will sometimes misinterpret
 output
 that contains  or + as input.

 Duncan Murdoch

 On Macs (and possibly other *NIXen) the equivalent to reading from the
 clipboard is: pipe(pbpaste)

 Testing shows that a simple modification after defining CleanTranscript
 produces no error on the example above:

 source(textConnection(CleanTranscript(readLines(pipe(pbpaste,

 +        echo = TRUE, max.deparse.length=Inf)

 example(mean)


 snip
 
 David Winsemius, MD
 Heritage Laboratories
 West Hartford, CT

 __
 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] reducing space between charts in lattice graphics

2009-09-19 Thread Larry White
Hi,

I'm trying to create a lattice plot with three xyplots in one vertical
column. I would like to reduce the vertical space between the charts.  My
code is below. There seems to be a between parameter for lattice.options,
but I can't find any examples. Aside from the data setup, the code is below.
Can anyone provide an example showing how to reduce the white space between
the charts?  Thanks.

total_chart - xyplot(total ~ date,
xlab=list(label=),
ylab=list(label=Total Work)
)

balance_chart - xyplot(bal ~ date,
xlab=list(label=),
ylab=list(label=Remaining Work)
)

index_chart - xyplot(index ~ date,  col=red, type=b, pch=15)

print(total_chart, split=c(1,1,1,3),   position=c(0, 0, 1, 1),
newpage=FALSE, more=TRUE)
print(balance_chart, split=c(1,2,1,3), position=c(0, 0, 1, 1),
newpage=FALSE, more=TRUE)
print(index_chart, split=c(1,3,1,3),   position=c(0, 0, 1, 1), newpage=TRUE,
more=FALSE)

[[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] How to avoid copy-paste when copying code from this list

2009-09-19 Thread baptiste auguie
Neat!

What if, instead, one wanted to format his/her code in the console
before sending it by email? Any tips for that?

(I proposed something like options(prompt= ) above, but got stuck
with adding a comment # to printed results)

Thanks,

baptiste




2009/9/19 Gabor Grothendieck ggrothendi...@gmail.com:
 Combining the code posted by myself, Duncan and David we have:

 # Usage: copy code from r-help to clipboard, then in R enter this:
 #   source.commands()
 #
 source.commands - function(echo = TRUE, max.deparse.length = Inf, ...) {
   # L - readLines(pipe(pbpaste)) # use this instead for Mac
   L - readLines(clipboard)
   L - grep(^[[:blank:]]*[^+[:blank:]]*[+], L, value = TRUE)
   L - sub(^[[:blank:]]*[^+[:blank:]]*[+] ?, , L)
   source(textConnection(L), echo = echo,
      max.deparse.length = max.deparse.length, ...)
 }

 It might be possible to automate the check for Mac using .Platform$GUI


 On Sat, Sep 19, 2009 at 12:08 PM, David Winsemius
 dwinsem...@comcast.net wrote:

 On Sep 19, 2009, at 11:58 AM, johannes rara wrote:

 Thanks for the responses.

 I think that the best way to avoid lots of hassle is that people
 copy-paste their solutions from their code editor, NOT from R console.
 For example, I usually save those solutions for my code archive, and
 if I want to run these later on (using Tinn-R), I have to parse 
 and + marks anyway.

 I agree entirely but trying to change posting behavior appears to be a
 difficult exercise. It would also be much preferred if people would learn to
 post the output of dput on an object, rather than what is displayed on the
 console when the object is print()ed.

 --
 David.

 -Johannes

 2009/9/19 David Winsemius dwinsem...@comcast.net:

 On Sep 19, 2009, at 10:58 AM, Duncan Murdoch wrote:


 snip


 Here's a quick version of CleanTranscript, translated to R:

 CleanTranscript - function(lines) {
  lines - grep(^[[:blank:]]*[^+[:blank:]]*[+], lines, value = TRUE)
  lines - sub(^[[:blank:]]*[^+[:blank:]]*[+] ?, , lines)
 }

 So on systems where clipboard is supported, executing

 source(textConnection(CleanTranscript(readLines(clipboard))),
      echo = TRUE, max.deparse.length=Inf)

 will do something similar to what the Windows Paste commands only menu
 option does, but you'd need a different incantation on other systems.
 And
 even this will sometimes mess up, e.g. it will sometimes misinterpret
 output
 that contains  or + as input.

 Duncan Murdoch

 On Macs (and possibly other *NIXen) the equivalent to reading from the
 clipboard is: pipe(pbpaste)

 Testing shows that a simple modification after defining CleanTranscript
 produces no error on the example above:

 source(textConnection(CleanTranscript(readLines(pipe(pbpaste,

 +        echo = TRUE, max.deparse.length=Inf)

 example(mean)


 snip
 
 David Winsemius, MD
 Heritage Laboratories
 West Hartford, CT

 __
 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] reducing space between charts in lattice graphics

2009-09-19 Thread David Winsemius
The Lattice book shows different uses of the layout and between  
parameters in the early examples in chapter 2. Why not go to the  
book's website and take a look?


--
David.
On Sep 19, 2009, at 12:42 PM, Larry White wrote:


Hi,

I'm trying to create a lattice plot with three xyplots in one vertical
column. I would like to reduce the vertical space between the  
charts.  My
code is below. There seems to be a between parameter for  
lattice.options,
but I can't find any examples. Aside from the data setup, the code  
is below.
Can anyone provide an example showing how to reduce the white space  
between

the charts?  Thanks.

total_chart - xyplot(total ~ date,
xlab=list(label=),
ylab=list(label=Total Work)
)

balance_chart - xyplot(bal ~ date,
xlab=list(label=),
ylab=list(label=Remaining Work)
)

index_chart - xyplot(index ~ date,  col=red, type=b, pch=15)

print(total_chart, split=c(1,1,1,3),   position=c(0, 0, 1, 1),
newpage=FALSE, more=TRUE)
print(balance_chart, split=c(1,2,1,3), position=c(0, 0, 1, 1),
newpage=FALSE, more=TRUE)
print(index_chart, split=c(1,3,1,3),   position=c(0, 0, 1, 1),  
newpage=TRUE,

more=FALSE)

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


David Winsemius, MD
Heritage Laboratories
West Hartford, CT

__
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] Amazon SimpleDB and R

2009-09-19 Thread Tim Shephard
As far as I know there isn't anything available for this, but I
thought I'd check before working up something of my own.

Is there a way to query Amazon SimpleDB and import the data results
directly into R?

Cheers,

Tim.

__
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] reducing space between charts in lattice graphics

2009-09-19 Thread Gabor Grothendieck
xyplot.zoo does that by default.

library(lattice)
library(zoo)
z - zoo(cbind(1:4, 2:5, 3:6))

xyplot(z, type = l)


On Sat, Sep 19, 2009 at 12:42 PM, Larry White ljw1...@gmail.com wrote:
 Hi,

 I'm trying to create a lattice plot with three xyplots in one vertical
 column. I would like to reduce the vertical space between the charts.  My
 code is below. There seems to be a between parameter for lattice.options,
 but I can't find any examples. Aside from the data setup, the code is below.
 Can anyone provide an example showing how to reduce the white space between
 the charts?  Thanks.

 total_chart - xyplot(total ~ date,
 xlab=list(label=),
 ylab=list(label=Total Work)
 )

 balance_chart - xyplot(bal ~ date,
 xlab=list(label=),
 ylab=list(label=Remaining Work)
 )

 index_chart - xyplot(index ~ date,  col=red, type=b, pch=15)

 print(total_chart, split=c(1,1,1,3),   position=c(0, 0, 1, 1),
 newpage=FALSE, more=TRUE)
 print(balance_chart, split=c(1,2,1,3), position=c(0, 0, 1, 1),
 newpage=FALSE, more=TRUE)
 print(index_chart, split=c(1,3,1,3),   position=c(0, 0, 1, 1), newpage=TRUE,
 more=FALSE)

        [[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] Converting matrices into row vectors and saving as ASCII text

2009-09-19 Thread Xi Ang

Hi

I have some data with these dimensions:
5 3 100

which correspond to the x, y, and time dimensions, for a variable, p.

I need the data in this format: 100 rows (1 row per time unit), and 15
values in each row. 

I have attempted to reshape my data

dim(data)
5 3 100

attr(data,'dim')-c(dim(data)[3],dim(data)[1]*dimdata[2])

So I get data with 100 rows, 15 columns.

I need to use this data outside of R, and so have to save it as an ASCII
file that retains the row-column structure of the data, but I do not know
how to.

It would be ideal if I could end up with a text file that also has an
additional column that labels which time unit (1-100) the row belongs to,
i.e.

1   a1,1  a1,2 ... a1,15
2   a2,1  a2,2 ... a2,15
3   a3,1  a3,2 ... a3,15
4   a4,1  a4,2 ... a4,15
.
.
.
99
100

Any suggestions would be appreciated.

Thanks
Xi


-- 
View this message in context: 
http://www.nabble.com/Converting-matrices-into-row-vectors-and-saving-as-ASCII-text-tp25523562p25523562.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] Rcmdr

2009-09-19 Thread oscar linares
Is there a UseR! manual in the works for the outstanding Rcmdr?

-- 
Oscar
Oscar A. Linares, MD
Translational Medicine Unit
Bolles Harbor
Monroe, Michigan

[[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] Rcmdr

2009-09-19 Thread John Fox
Dear Oscar,

 -Original Message-
 From: r-help-boun...@r-project.org [mailto:r-help-boun...@r-project.org]
On
 Behalf Of oscar linares
 Sent: September-19-09 1:14 PM
 To: r-h...@stat.math.ethz.ch
 Subject: [R] Rcmdr
 
 Is there a UseR! manual in the works for the outstanding Rcmdr?

First, thanks for the kind phrasing of your question.

I'm not aware of a book specifically on the Rcmdr, nor do I plan to write
one. It's my intention that the Rcmdr be largely self-explanatory, and I
hope that it doesn't require a book for people to use it.  That said,
Heiberger and Neuwirth's recently published book, R Through Excel, in the
Springer Use R! series, makes use of the Rcmdr menus and describes them. 

Regards,
 John

 
 --
 Oscar
 Oscar A. Linares, MD
 Translational Medicine Unit
 Bolles Harbor
 Monroe, Michigan
 
   [[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] How to avoid copy-paste when copying code from this list

2009-09-19 Thread johannes rara
I made a python script to parse  and + marks, if someone is interested:

#- start --
#!/Python26/
# -*- coding: utf-8 -*-

import sys

def main(argv):
if len(argv)  2:
sys.stderr.write(Usage: %s file.txt % (argv[0],))
return 1

f = open(sys.argv[1])
lines = f.readlines()
f.close()

for line in lines:
line = line.strip()
if not (line[:1] ==  or line[:1] == +):
continue
print line[2:]

if __name__ == __main__:
sys.exit(main(sys.argv))

#- end --

And to use it:

~  python strip_r-help.py code_from_r-help.txt

TP - function(x){
  L - length(x)
  which( ((x[1:(L-2)]x[2:(N-1)])(x[2:(L-1)]x[3:L]))
|((x[1:(L-2)]x[2:(N-1)])(x[2:(L-1)]x[3:L])) ) + 1
}
y-c(93,93,93,93,93,93,93,93,93,93,93,
 93,93,93,93,93,93,93,93,93,93,93)
m-c(02,02,02,02,02,02,02,02,02,02,02,
 02,02,02,02,02,02,02,02,02,02,02)
d-c(07,08,09,10,11,12,13,14,15,16,17,
 18,19,20,21,22,23,24,25,26,27,28)

ix - TP(count)
rbind(d[ix],count[ix])
~ 

This is not a good solutions, but works especially when there is lots
of code to parse.

-Johannes

2009/9/19 baptiste auguie baptiste.aug...@googlemail.com:
 Neat!

 What if, instead, one wanted to format his/her code in the console
 before sending it by email? Any tips for that?

 (I proposed something like options(prompt= ) above, but got stuck
 with adding a comment # to printed results)

 Thanks,

 baptiste




 2009/9/19 Gabor Grothendieck ggrothendi...@gmail.com:
 Combining the code posted by myself, Duncan and David we have:

 # Usage: copy code from r-help to clipboard, then in R enter this:
 #   source.commands()
 #
 source.commands - function(echo = TRUE, max.deparse.length = Inf, ...) {
   # L - readLines(pipe(pbpaste)) # use this instead for Mac
   L - readLines(clipboard)
   L - grep(^[[:blank:]]*[^+[:blank:]]*[+], L, value = TRUE)
   L - sub(^[[:blank:]]*[^+[:blank:]]*[+] ?, , L)
   source(textConnection(L), echo = echo,
      max.deparse.length = max.deparse.length, ...)
 }

 It might be possible to automate the check for Mac using .Platform$GUI


 On Sat, Sep 19, 2009 at 12:08 PM, David Winsemius
 dwinsem...@comcast.net wrote:

 On Sep 19, 2009, at 11:58 AM, johannes rara wrote:

 Thanks for the responses.

 I think that the best way to avoid lots of hassle is that people
 copy-paste their solutions from their code editor, NOT from R console.
 For example, I usually save those solutions for my code archive, and
 if I want to run these later on (using Tinn-R), I have to parse 
 and + marks anyway.

 I agree entirely but trying to change posting behavior appears to be a
 difficult exercise. It would also be much preferred if people would learn to
 post the output of dput on an object, rather than what is displayed on the
 console when the object is print()ed.

 --
 David.

 -Johannes

 2009/9/19 David Winsemius dwinsem...@comcast.net:

 On Sep 19, 2009, at 10:58 AM, Duncan Murdoch wrote:


 snip


 Here's a quick version of CleanTranscript, translated to R:

 CleanTranscript - function(lines) {
  lines - grep(^[[:blank:]]*[^+[:blank:]]*[+], lines, value = TRUE)
  lines - sub(^[[:blank:]]*[^+[:blank:]]*[+] ?, , lines)
 }

 So on systems where clipboard is supported, executing

 source(textConnection(CleanTranscript(readLines(clipboard))),
      echo = TRUE, max.deparse.length=Inf)

 will do something similar to what the Windows Paste commands only menu
 option does, but you'd need a different incantation on other systems.
 And
 even this will sometimes mess up, e.g. it will sometimes misinterpret
 output
 that contains  or + as input.

 Duncan Murdoch

 On Macs (and possibly other *NIXen) the equivalent to reading from the
 clipboard is: pipe(pbpaste)

 Testing shows that a simple modification after defining CleanTranscript
 produces no error on the example above:

 source(textConnection(CleanTranscript(readLines(pipe(pbpaste,

 +        echo = TRUE, max.deparse.length=Inf)

 example(mean)


 snip
 
 David Winsemius, MD
 Heritage Laboratories
 West Hartford, CT

 __
 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] Converting matrices into row vectors and saving as ASCII text

2009-09-19 Thread David Winsemius

XYT - array(1:150, dim=c(3,5,10))
XYbyT= matrix(apply(XYT, 3, I), ncol=10)

...or even...

XYbyT= matrix(XYT, ncol=10)

--  
David.


On Sep 19, 2009, at 1:11 PM, Xi Ang wrote:



Hi

I have some data with these dimensions:
5 3 100

which correspond to the x, y, and time dimensions, for a variable, p.

I need the data in this format: 100 rows (1 row per time unit), and 15
values in each row.

I have attempted to reshape my data


dim(data)

5 3 100


attr(data,'dim')-c(dim(data)[3],dim(data)[1]*dimdata[2])


So I get data with 100 rows, 15 columns.

I need to use this data outside of R, and so have to save it as an  
ASCII
file that retains the row-column structure of the data, but I do not  
know

how to.

It would be ideal if I could end up with a text file that also has an
additional column that labels which time unit (1-100) the row  
belongs to,

i.e.

1   a1,1  a1,2 ... a1,15
2   a2,1  a2,2 ... a2,15
3   a3,1  a3,2 ... a3,15
4   a4,1  a4,2 ... a4,15
.
.
.
99
100

Any suggestions would be appreciated.

Thanks
Xi


--
View this message in context: 
http://www.nabble.com/Converting-matrices-into-row-vectors-and-saving-as-ASCII-text-tp25523562p25523562.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.


David Winsemius, MD
Heritage Laboratories
West Hartford, CT

__
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] generic methods - in particular the summary function

2009-09-19 Thread Christophe Dutang
Hi all,

I'm currently working on the fitdistrplus package (that basically fit  
distributions). There is something I do not understand about the  
generic function summary.

In the current version on CRAN, there is no NAMESPACE saying

S3method(summary, fitdist)

.
However if we use summary on an object send by fitdist function it  
works fine...

According to R-lang, we have

The most common use of generic functions is to provide print and  
summary methods for
statistical ob jects, generally the output of some model fitting  
process. To do this, each model
attaches a class attribute to its output and then provides a special  
method that takes that output
and provides a nice readable version of it. The user then needs only  
remember that print or
summary will provide nice output for the results of any analysis.


I would like to be sure, that if the summary.fitdist is not exported  
in the NAMESPACE, then we must use declare it with S3method.

Thanks in advance

Christophe

--
Christophe Dutang
Ph.D. student at ISFA, Lyon, France
website: http://dutangc.free.fr


[[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] Windows RGui line editing

2009-09-19 Thread OKB (not okblacke)
I've been using RGui and Tinn-R on Windows for a while now, but it 
continues to be a hassle that RGui supports only very rudimentary line 
editing.  I can't even use Shift+arrows to select text, let alone use 
things like Ctrl+arrows to jump left or right a word at a time.

I searched in the list archives and found what seem to be a few 
earlier references to this problem, but I couldn't find a clear answer 
on why it is or whether there's some workaround.  I saw something in the 
docs about it being due to a lack of readline support on Windows, but 
it's hard for me to understand how this can be a deal-breaker, given 
that there are tons of programs that run on Windows with full line 
editing (e.g., cmd.exe, text editors, Python's IDLE).

So, my question is, is there a way to use R in Windows with full 
line editing capabilities, or does every single person who uses R on 
Windows just suffer with this limitation?  (The main reason I'm asking 
is that it seems hard for me to believe the latter is true, so I feel 
like I must be missing something.)

Thanks,
-- 
--OKB (not okblacke)
Brendan Barnwell
Do not follow where the path may lead.  Go, instead, where there is
no path, and leave a trail.
--author unknown

__
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] matrix operations on grobs and grid units

2009-09-19 Thread baptiste auguie
A few amendments might make this improved code more readable,

e = expression(alpha,testing very large width, hat(beta),
integral(f(x)*dx, a, b))

library(grid)

rowMax.units - function(u, nrow){ # rowMax with a fake matrix of units
 matrix.indices - matrix(seq_along(u), nrow=nrow)
 do.call(unit.c, lapply(seq(1, nrow), function(ii) {
  max(u[matrix.indices[ii, ]])
 }))
}

colMax.units - function(u, ncol){ # colMax with a fake matrix of units
 matrix.indices - matrix(seq_along(u), ncol=ncol)
 do.call(unit.c, lapply(seq(1, ncol), function(ii) {
  max(u[matrix.indices[, ii]])
 }))
}


makeTableGrobs - function(e, ncol, nrow, equal.width = F, equal.height=F,
just = c(center, center),
       gpar.text = gpar(col=black, cex=1),
       gpar.fill = gpar(fill = grey95, col=white, lwd=1.5)) {

n - length(e) # number of labels

stopifnot(!n%%2) # only rectangular layouts

if(missing(ncol)  missing(nrow)){
nm - n2mfrow(n)      # pretty default layout
ncol = nm[1]
nrow = nm[2]
}

makeOneLabel - function(label.ind){
textGrob(label=e[label.ind], gp=gpar.text,
name=paste(cells-label-,label.ind, sep=))
}

makeOneCell - function(label.ind){
rectGrob(gp=gpar.fill, name=paste(cells-fill-,label.ind, sep=))
}

 lg - lapply(seq_along(e), makeOneLabel) # list of text grobs
 lf - lapply(seq_along(e), makeOneCell) # list of rect grobs

 wg - lapply(lg, grobWidth) # list of grob widths
 hg - lapply(lg, grobHeight) # list of grob heights

 widths.all - do.call(unit.c, wg) # all grob widths
 heights.all - do.call(unit.c, hg)    #all grob heights

 widths - colMax.units(widths.all, ncol) # all column widths
 heights - rowMax.units(heights.all, nrow) # all row heights

 if(equal.width)
   widths - rep(max(widths), length(widths))
 if(equal.height)
   heights - rep(max(heights), length(heights))

 gcells = frameGrob(name=table.cells, vp = cells,
   layout = grid.layout(nrow, ncol, just=just,
     widths = widths, heights = heights) )

 label.ind - 1   # index running accross labels

 for (ii in seq(1, ncol, 1)) {
   for (jj in seq(1, nrow, 1)) {

     gcells = placeGrob(gcells, lf[[label.ind]], row=jj, col=ii)
     gcells = placeGrob(gcells, lg[[label.ind]], row=jj, col=ii)

     label.ind - label.ind + 1
   }
 }

 gl = gList( gcells)

 gl
}

# tests
vp = viewport(name=cells)
g1 - gTree(children=makeTableGrobs(e), childrenvp=vp)
g2 - gTree(children=makeTableGrobs(e, 4, 1), childrenvp=vp)
g3 - gTree(children=makeTableGrobs(e, 1, 4), childrenvp=vp)
g4 - gTree(children=makeTableGrobs(e, equal.w=T), childrenvp=vp)
g5 - gTree(children=makeTableGrobs(e, equal.h=T), childrenvp=vp)
g6 - gTree(children=makeTableGrobs(e, equal.h=T, equal.w=T), childrenvp=vp)

source(http://gridextra.googlecode.com/svn-history/r21/trunk/R/arrange2.r;)
# wrapper around grid.layout and grid.draw
arrange2(g1, g2, g3, g4, g5, g6, main=Testing different fitting arrangements)


This works as expected, however I would like some advice before going
any further,

- because this layout seems quite common, would it make sense to
provide methods for the following objects? (i) a matrix of grobs; (ii)
a matrix of units; (iii) cbind, rbind, rowMax, colMax methods for a
matrix of units.

- is there a better, recommended way to achieve the same thing?
(examples would be great)

Any comments and suggestions are very welcome.

Best regards,

baptiste

__
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-pkgs] homals package and core loop

2009-09-19 Thread Jan de Leeuw

The homals package

http://www.jstatsoft.org/v31/i04

will get a major programming overhaul. This will take some time,
but what's a few years on a 40-year project. Suggestions
from the audience are welcome.

homals() has a core loop over the m variables in which

1. tapply is used to compute category quantification (centroids)
2. category quantifications are then adjusted to satisfy the
  rank and level constraints

The idea is to replace 1 by least squares fitting of a B-spline and
to adjust 2 accordingly. The core will be re-programmed in C
and/or FORTRAN (sometimes using existing routines), and the loop over
variables will be parallelized using OpenMP or Grand Central Dispatch.
For ordinal variables this requires some alternative quadratic  
programming

routines to be linked in (which could then also become part of the
isotone package).

In addition the basic homals code will have object (individual) weights
(minor addition) and the prehom routines (from the jacobi package) will
be added. Because of the use of B splines the variables in homals will
no longer be all factors, some can now be numerical (continuous).

Otherwise the package will keep its many analysis options (multi-set  
non-metric canonical analysis,
non-metric discriminant analysis, non-metric regression, multiple  
correspondence analysis,
non-metric principal components analysis, non-metric additive conjoint  
analysis)

and its many plot options.


Jan de Leeuw, 11667 Steinhoff Rd, Frazier Park, CA 93225
home 661-245-1725 mobile 661-231-5416 work 310-825-9550
.mac: jdeleeuw +++  aim: deleeuwjan +++ skype: j_deleeuw

If I wanted you to understand it, I would have explained it  
better.	

  -- Johan Cruijff

___
R-packages mailing list
r-packa...@r-project.org
https://stat.ethz.ch/mailman/listinfo/r-packages

__
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] Poisson Regression - Query

2009-09-19 Thread Axel Urbiz
Hi All,

My dependent variable is a ratio that takes a value of 0 (zero) for 95% of
the observations and positive non-integer values for the other 5%. What
model would be appropriate? I'm thinking of fitting a GLM with a Poisson ~.
Now, becuase it takes non-integer values, using the glm function with
Poisson family issues warning messages.

Warning messages:
1: In dpois(y, mu, log = TRUE) : non-integer x = 0.430783
2: In dpois(y, mu, log = TRUE) : non-integer x = 0.162519
3: In dpois(y, mu, log = TRUE) : non-integer x = 0.162519
4: In dpois(y, mu, log = TRUE) : non-integer x = 0.162519
5: In dpois(y, mu, log = TRUE) : non-integer x = 0.371564

I'll appreciate your thoughts.

Thanks!

Axel.

[[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] Poisson Regression - Query

2009-09-19 Thread Achim Zeileis

On Sat, 19 Sep 2009, Axel Urbiz wrote:


Hi All,

My dependent variable is a ratio that takes a value of 0 (zero) for 95% of
the observations and positive non-integer values for the other 5%. What
model would be appropriate? I'm thinking of fitting a GLM with a Poisson ~.
Now, becuase it takes non-integer values, using the glm function with
Poisson family issues warning messages.


If it is a ratio of (integer-valued) counts in the numerator and some 
known denominator, say

  ratio = count/denom
then one standard approach would be to fit
  glm(count ~ ..., offset = log(denom), data = ..., family = poisson)
because this corresponds to
  log(count)   = x'beta + log(denom)
  = log(count/denom) = x'beta

To address the excess zeros, you could use a hurdle model or a 
zero-inflated model. See

  http://www.jstatsoft.org/v27/i08/

Best,
Z


Warning messages:
1: In dpois(y, mu, log = TRUE) : non-integer x = 0.430783
2: In dpois(y, mu, log = TRUE) : non-integer x = 0.162519
3: In dpois(y, mu, log = TRUE) : non-integer x = 0.162519
4: In dpois(y, mu, log = TRUE) : non-integer x = 0.162519
5: In dpois(y, mu, log = TRUE) : non-integer x = 0.371564

I'll appreciate your thoughts.

Thanks!

Axel.

[[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] eval(expr) without printing to screen?

2009-09-19 Thread Nick Matzke

Hi,

I have a script which I source, which evaluates a changing expression 
call hundreds of times.  It works, but it prints to screen each time, 
which is annoying.  There must be simple way to suppress this, or to use 
a slightly different set of commands, which will be obvious to those 
wiser than I...



Here is a simpler mockup which shows the issue:

x = data.frame(rbind(c(1,2,3),c(1,2,3)))
xnames = c(a, b, c)
names(x) = xnames

for(i in 1:length(x))
{
# Create a varying string expression
expr = paste(y = x$, xnames[i], [1], sep=)

# evaluate expression
eval(parse(text=print(expr)))

# This command prints the expression to screen even when embedded in a 
function in a sourced script.  I would prefer it didn't!

}


PS: I have to go through this rigamarole:

expr = y1 = x$c[1]
eval(parse(text=print(expr)))

Because the following doesn't work, even though it seems like it should:
expr = y = x$c[2]
eval(expr)




--

Nicholas J. Matzke
Ph.D. Candidate, Graduate Student Researcher
Huelsenbeck Lab
Center for Theoretical Evolutionary Genomics
4151 VLSB (Valley Life Sciences Building)
Department of Integrative Biology
University of California, Berkeley

Lab websites:
http://ib.berkeley.edu/people/lab_detail.php?lab=54
http://fisher.berkeley.edu/cteg/hlab.html
Dept. personal page: 
http://ib.berkeley.edu/people/students/person_detail.php?person=370

Lab personal page: http://fisher.berkeley.edu/cteg/members/matzke.html
Lab phone: 510-643-6299
Dept. fax: 510-643-6264
Cell phone: 510-301-0179
Email: mat...@berkeley.edu

Mailing address:
Department of Integrative Biology
3060 VLSB #3140
Berkeley, CA 94720-3140

-
[W]hen people thought the earth was flat, they were wrong. When people 
thought the earth was spherical, they were wrong. But if you think that 
thinking the earth is spherical is just as wrong as thinking the earth 
is flat, then your view is wronger than both of them put together.


Isaac Asimov (1989). The Relativity of Wrong. The Skeptical Inquirer, 
14(1), 35-44. Fall 1989.

http://chem.tufts.edu/AnswersInScience/RelativityofWrong.htm

__
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] eval(expr) without printing to screen?

2009-09-19 Thread baptiste auguie
Hi,

What about this,

eval(parse(text=expr))

(no print)

HTH,

baptiste


2009/9/19 Nick Matzke mat...@berkeley.edu:
 Hi,

 I have a script which I source, which evaluates a changing expression call
 hundreds of times.  It works, but it prints to screen each time, which is
 annoying.  There must be simple way to suppress this, or to use a slightly
 different set of commands, which will be obvious to those wiser than I...


 Here is a simpler mockup which shows the issue:

 x = data.frame(rbind(c(1,2,3),c(1,2,3)))
 xnames = c(a, b, c)
 names(x) = xnames

 for(i in 1:length(x))
 {
 # Create a varying string expression
 expr = paste(y = x$, xnames[i], [1], sep=)

 # evaluate expression
 eval(parse(text=print(expr)))

 # This command prints the expression to screen even when embedded in a
 function in a sourced script.  I would prefer it didn't!
 }


 PS: I have to go through this rigamarole:

 expr = y1 = x$c[1]
 eval(parse(text=print(expr)))

 Because the following doesn't work, even though it seems like it should:
 expr = y = x$c[2]
 eval(expr)




 --
 
 Nicholas J. Matzke
 Ph.D. Candidate, Graduate Student Researcher
 Huelsenbeck Lab
 Center for Theoretical Evolutionary Genomics
 4151 VLSB (Valley Life Sciences Building)
 Department of Integrative Biology
 University of California, Berkeley

 Lab websites:
 http://ib.berkeley.edu/people/lab_detail.php?lab=54
 http://fisher.berkeley.edu/cteg/hlab.html
 Dept. personal page:
 http://ib.berkeley.edu/people/students/person_detail.php?person=370
 Lab personal page: http://fisher.berkeley.edu/cteg/members/matzke.html
 Lab phone: 510-643-6299
 Dept. fax: 510-643-6264
 Cell phone: 510-301-0179
 Email: mat...@berkeley.edu

 Mailing address:
 Department of Integrative Biology
 3060 VLSB #3140
 Berkeley, CA 94720-3140

 -
 [W]hen people thought the earth was flat, they were wrong. When people
 thought the earth was spherical, they were wrong. But if you think that
 thinking the earth is spherical is just as wrong as thinking the earth is
 flat, then your view is wronger than both of them put together.

 Isaac Asimov (1989). The Relativity of Wrong. The Skeptical Inquirer,
 14(1), 35-44. Fall 1989.
 http://chem.tufts.edu/AnswersInScience/RelativityofWrong.htm

 __
 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] eval(expr) without printing to screen?

2009-09-19 Thread David Winsemius


On Sep 19, 2009, at 4:48 PM, Nick Matzke wrote:


Hi,

I have a script which I source, which evaluates a changing  
expression call hundreds of times.  It works, but it prints to  
screen each time, which is annoying.  There must be simple way to  
suppress this, or to use a slightly different set of commands, which  
will be obvious to those wiser than I...



Here is a simpler mockup which shows the issue:

x = data.frame(rbind(c(1,2,3),c(1,2,3)))
xnames = c(a, b, c)
names(x) = xnames

for(i in 1:length(x))
{
# Create a varying string expression
expr = paste(y = x$, xnames[i], [1], sep=)

# evaluate expression
eval(parse(text=print(expr)))


Why are you printing expr? Seems that you are making it difficult to  
achieve your goal of quiet execution if you print the expressions  
inside the parse function.




# This command prints the expression to screen even when embedded in  
a function in a sourced script.  I would prefer it didn't!

}


PS: I have to go through this rigamarole:

expr = y1 = x$c[1]
eval(parse(text=print(expr)))

Because the following doesn't work, even though it seems like it  
should:

expr = y = x$c[2]
eval(expr)


--

David Winsemius, MD
Heritage Laboratories
West Hartford, CT

__
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] eval(expr) without printing to screen?

2009-09-19 Thread John Sorkin
David,

You can used the sink function to direct the output to a file. When you do 
this, nothing is printed on the screen.

e.g. 
sink(c:\\RResu.txt)   #Defines location to which output is to be written
#R code goes here
sink()   #Turns off redirection, any code after this  
will print to the screen

John

John David Sorkin M.D., Ph.D.
Chief, Biostatistics and Informatics
University of Maryland School of Medicine Division of Gerontology
Baltimore VA Medical Center
10 North Greene Street
GRECC (BT/18/GR)
Baltimore, MD 21201-1524
(Phone) 410-605-7119
(Fax) 410-605-7913 (Please call phone number above prior to faxing)

 David Winsemius dwinsem...@comcast.net 9/19/2009 5:01 PM 

On Sep 19, 2009, at 4:48 PM, Nick Matzke wrote:

 Hi,

 I have a script which I source, which evaluates a changing  
 expression call hundreds of times.  It works, but it prints to  
 screen each time, which is annoying.  There must be simple way to  
 suppress this, or to use a slightly different set of commands, which  
 will be obvious to those wiser than I...


 Here is a simpler mockup which shows the issue:

 x = data.frame(rbind(c(1,2,3),c(1,2,3)))
 xnames = c(a, b, c)
 names(x) = xnames

 for(i in 1:length(x))
 {
 # Create a varying string expression
 expr = paste(y = x$, xnames[i], [1], sep=)

 # evaluate expression
 eval(parse(text=print(expr)))

Why are you printing expr? Seems that you are making it difficult to  
achieve your goal of quiet execution if you print the expressions  
inside the parse function.


 # This command prints the expression to screen even when embedded in  
 a function in a sourced script.  I would prefer it didn't!
 }


 PS: I have to go through this rigamarole:

 expr = y1 = x$c[1]
 eval(parse(text=print(expr)))

 Because the following doesn't work, even though it seems like it  
 should:
 expr = y = x$c[2]
 eval(expr)

-- 

David Winsemius, MD
Heritage Laboratories
West Hartford, CT

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

Confidentiality Statement:
This email message, including any attachments, is for th...{{dropped:6}}

__
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] Lattice: combine the same strip?

2009-09-19 Thread di jianing
Hello R helpers,

I am producing a figure with dual strips, i.e., x~y | S1 + S2, where S1 and
S2 are two strips. For example, in figure 2.1 at
http://lmdvr.r-forge.r-project.org/figures/figures.html.

In this case, I would like to combine the the top strip, since all three
pictures in the same row have the same level based on the first strip. In
other words, instead of

| -- S11 -- | -- S11 -- | -- S11 -- |
| -- S21 -- | -- S22 -- | -- S23 -- |

I would like my graph to look like

| - S11  |
| -- S21 -- | -- S22 -- | -- S23 -- |

In there a way I can do it?

Thanks!
JD

[[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] Processing strings

2009-09-19 Thread tzygmund mcfarlane
Hi,

I am unable to do something fairly simple. I have matrices called
Table1,..., Table10. I want to be able to print them using a loop. So
I wrote:
##
for (i in 1:10){
  disp-paste(Table, i, sep=)
   eval(parse(text=disp))
}
##
but this produces no output. Any ideas?

__
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] Processing strings

2009-09-19 Thread Jorge Ivan Velez
Dear tzygmund,
Here are two suggestions:

# Suggestion 1
for (i in 1:10){
 disp-paste(Table, i, sep=)
  print(get(disp))
}

# Suggestion 2
disp - paste(Table, 1:10, sep=)
sapply(disp, function(x) print( get(x) ) )

See ?print and ?get for more information.

HTH,
Jorge


On Sat, Sep 19, 2009 at 6:40 PM, tzygmund mcfarlane  wrote:

 Hi,

 I am unable to do something fairly simple. I have matrices called
 Table1,..., Table10. I want to be able to print them using a loop. So
 I wrote:
 ##
 for (i in 1:10){
  disp-paste(Table, i, sep=)
   eval(parse(text=disp))
 }
 ##
 but this produces no output. Any ideas?

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


[[alternative HTML version deleted]]

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


Re: [R] Processing strings

2009-09-19 Thread tzygmund mcfarlane
Jorge,

Your suggestions produce the names of the matrices and not the
contents. Sorry if this was not clear in the question.



On Sat, Sep 19, 2009 at 11:46 PM, Jorge Ivan Velez
jorgeivanve...@gmail.com wrote:
 Dear tzygmund,
 Here are two suggestions:
 # Suggestion 1
 for (i in 1:10){
  disp-paste(Table, i, sep=)
   print(get(disp))
 }
 # Suggestion 2
 disp - paste(Table, 1:10, sep=)
 sapply(disp, function(x) print( get(x) ) )
 See ?print and ?get for more information.
 HTH,
 Jorge

 On Sat, Sep 19, 2009 at 6:40 PM, tzygmund mcfarlane  wrote:

 Hi,

 I am unable to do something fairly simple. I have matrices called
 Table1,..., Table10. I want to be able to print them using a loop. So
 I wrote:
 ##
 for (i in 1:10){
  disp-paste(Table, i, sep=)
   eval(parse(text=disp))
 }
 ##
 but this produces no output. Any ideas?

 __
 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] Processing strings

2009-09-19 Thread Duncan Murdoch

On 19/09/2009 6:51 PM, tzygmund mcfarlane wrote:

Jorge,

Your suggestions produce the names of the matrices and not the
contents. Sorry if this was not clear in the question.


You must not have entered them correctly.  His answer is fine.

Duncan Murdoch





On Sat, Sep 19, 2009 at 11:46 PM, Jorge Ivan Velez
jorgeivanve...@gmail.com wrote:

Dear tzygmund,
Here are two suggestions:
# Suggestion 1
for (i in 1:10){
 disp-paste(Table, i, sep=)
  print(get(disp))
}
# Suggestion 2
disp - paste(Table, 1:10, sep=)
sapply(disp, function(x) print( get(x) ) )
See ?print and ?get for more information.
HTH,
Jorge

On Sat, Sep 19, 2009 at 6:40 PM, tzygmund mcfarlane  wrote:

Hi,

I am unable to do something fairly simple. I have matrices called
Table1,..., Table10. I want to be able to print them using a loop. So
I wrote:
##
for (i in 1:10){
 disp-paste(Table, i, sep=)
  eval(parse(text=disp))
}
##
but this produces no output. Any ideas?

__
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] Processing strings

2009-09-19 Thread tzygmund mcfarlane
Ah, apologies. In the backing and forthing, I assigned the names to
the matrices. All sorted. Thanks!

On Sat, Sep 19, 2009 at 11:55 PM, Duncan Murdoch murd...@stats.uwo.ca wrote:
 On 19/09/2009 6:51 PM, tzygmund mcfarlane wrote:

 Jorge,

 Your suggestions produce the names of the matrices and not the
 contents. Sorry if this was not clear in the question.

 You must not have entered them correctly.  His answer is fine.

 Duncan Murdoch




 On Sat, Sep 19, 2009 at 11:46 PM, Jorge Ivan Velez
 jorgeivanve...@gmail.com wrote:

 Dear tzygmund,
 Here are two suggestions:
 # Suggestion 1
 for (i in 1:10){
  disp-paste(Table, i, sep=)
  print(get(disp))
 }
 # Suggestion 2
 disp - paste(Table, 1:10, sep=)
 sapply(disp, function(x) print( get(x) ) )
 See ?print and ?get for more information.
 HTH,
 Jorge

 On Sat, Sep 19, 2009 at 6:40 PM, tzygmund mcfarlane  wrote:

 Hi,

 I am unable to do something fairly simple. I have matrices called
 Table1,..., Table10. I want to be able to print them using a loop. So
 I wrote:
 ##
 for (i in 1:10){
  disp-paste(Table, i, sep=)
  eval(parse(text=disp))
 }
 ##
 but this produces no output. Any ideas?

 __
 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] Processing strings

2009-09-19 Thread Henrique Dallazuanna
Try this:

sapply(ls(pattern = 'Table[0-9]'), get)

On Sat, Sep 19, 2009 at 7:51 PM, tzygmund mcfarlane
tzygm...@googlemail.com wrote:
 Jorge,

 Your suggestions produce the names of the matrices and not the
 contents. Sorry if this was not clear in the question.



 On Sat, Sep 19, 2009 at 11:46 PM, Jorge Ivan Velez
 jorgeivanve...@gmail.com wrote:
 Dear tzygmund,
 Here are two suggestions:
 # Suggestion 1
 for (i in 1:10){
  disp-paste(Table, i, sep=)
   print(get(disp))
 }
 # Suggestion 2
 disp - paste(Table, 1:10, sep=)
 sapply(disp, function(x) print( get(x) ) )
 See ?print and ?get for more information.
 HTH,
 Jorge

 On Sat, Sep 19, 2009 at 6:40 PM, tzygmund mcfarlane  wrote:

 Hi,

 I am unable to do something fairly simple. I have matrices called
 Table1,..., Table10. I want to be able to print them using a loop. So
 I wrote:
 ##
 for (i in 1:10){
  disp-paste(Table, i, sep=)
   eval(parse(text=disp))
 }
 ##
 but this produces no output. Any ideas?

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




-- 
Henrique Dallazuanna
Curitiba-Paraná-Brasil
25° 25' 40 S 49° 16' 22 O

__
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] Processing strings

2009-09-19 Thread Jorge Ivan Velez
Hi tzygmund,

You can avoid the print() part and the result would be pretty much the same:

# Data
x1 - x2- x3 - matrix( rnorm(20), ncol = 5)

# Names to print
Names - paste('x', 1:3, sep=)

# New suggestion
sapply( Names, function( y ) list( get( y ) ) )

Best,
Jorge


On Sat, Sep 19, 2009 at 6:51 PM, tzygmund mcfarlane  wrote:

 Jorge,

 Your suggestions produce the names of the matrices and not the
 contents. Sorry if this was not clear in the question.



 On Sat, Sep 19, 2009 at 11:46 PM, Jorge Ivan Velez
 jorgeivanve...@gmail.com wrote:
  Dear tzygmund,
  Here are two suggestions:
  # Suggestion 1
  for (i in 1:10){
   disp-paste(Table, i, sep=)
print(get(disp))
  }
  # Suggestion 2
  disp - paste(Table, 1:10, sep=)
  sapply(disp, function(x) print( get(x) ) )
  See ?print and ?get for more information.
  HTH,
  Jorge
 
  On Sat, Sep 19, 2009 at 6:40 PM, tzygmund mcfarlane  wrote:
 
  Hi,
 
  I am unable to do something fairly simple. I have matrices called
  Table1,..., Table10. I want to be able to print them using a loop. So
  I wrote:
  ##
  for (i in 1:10){
   disp-paste(Table, i, sep=)
eval(parse(text=disp))
  }
  ##
  but this produces no output. Any ideas?
 
  __
  R-help@r-project.org mailing list
  https://stat.ethz.ch/mailman/listinfo/r-help
  PLEASE do read the posting guide
  http://www.R-project.org/posting-guide.html
  and provide commented, minimal, self-contained, reproducible code.
 
 


[[alternative HTML version deleted]]

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


Re: [R] Processing strings

2009-09-19 Thread tzygmund mcfarlane
Thanks again!

On Sun, Sep 20, 2009 at 12:04 AM, Jorge Ivan Velez
jorgeivanve...@gmail.com wrote:
 Hi tzygmund,
 You can avoid the print() part and the result would be pretty much the same:
 # Data
 x1 - x2- x3 - matrix( rnorm(20), ncol = 5)
 # Names to print
 Names - paste('x', 1:3, sep=)
 # New suggestion
 sapply( Names, function( y ) list( get( y ) ) )
 Best,
 Jorge

 On Sat, Sep 19, 2009 at 6:51 PM, tzygmund mcfarlane  wrote:

 Jorge,

 Your suggestions produce the names of the matrices and not the
 contents. Sorry if this was not clear in the question.



 On Sat, Sep 19, 2009 at 11:46 PM, Jorge Ivan Velez
 jorgeivanve...@gmail.com wrote:
  Dear tzygmund,
  Here are two suggestions:
  # Suggestion 1
  for (i in 1:10){
   disp-paste(Table, i, sep=)
    print(get(disp))
  }
  # Suggestion 2
  disp - paste(Table, 1:10, sep=)
  sapply(disp, function(x) print( get(x) ) )
  See ?print and ?get for more information.
  HTH,
  Jorge
 
  On Sat, Sep 19, 2009 at 6:40 PM, tzygmund mcfarlane  wrote:
 
  Hi,
 
  I am unable to do something fairly simple. I have matrices called
  Table1,..., Table10. I want to be able to print them using a loop. So
  I wrote:
  ##
  for (i in 1:10){
   disp-paste(Table, i, sep=)
    eval(parse(text=disp))
  }
  ##
  but this produces no output. Any ideas?
 
  __
  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] Converting matrices into row vectors and saving as ASCII text

2009-09-19 Thread Xi Ang


Thanks for your reply.

Is there a way I can save the data to an ascii file without losing the
row/column structure?
I have tried save(...) and write.table(...) but the output file seems to
jumble up the order of the matrix.

Thanks
Xi


David Winsemius wrote:
 
 XYT - array(1:150, dim=c(3,5,10))
 XYbyT= matrix(apply(XYT, 3, I), ncol=10)
 
 ...or even...
 
 XYbyT= matrix(XYT, ncol=10)
 
 --  
 David.
 
 On Sep 19, 2009, at 1:11 PM, Xi Ang wrote:
 

 Hi

 I have some data with these dimensions:
 5 3 100

 which correspond to the x, y, and time dimensions, for a variable, p.

 I need the data in this format: 100 rows (1 row per time unit), and 15
 values in each row.

 I have attempted to reshape my data

 dim(data)
 5 3 100

 attr(data,'dim')-c(dim(data)[3],dim(data)[1]*dimdata[2])

 So I get data with 100 rows, 15 columns.

 I need to use this data outside of R, and so have to save it as an  
 ASCII
 file that retains the row-column structure of the data, but I do not  
 know
 how to.

 It would be ideal if I could end up with a text file that also has an
 additional column that labels which time unit (1-100) the row  
 belongs to,
 i.e.

 1   a1,1  a1,2 ... a1,15
 2   a2,1  a2,2 ... a2,15
 3   a3,1  a3,2 ... a3,15
 4   a4,1  a4,2 ... a4,15
 .
 .
 .
 99
 100

 Any suggestions would be appreciated.

 Thanks
 Xi


 -- 
 View this message in context:
 http://www.nabble.com/Converting-matrices-into-row-vectors-and-saving-as-ASCII-text-tp25523562p25523562.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.
 
 David Winsemius, MD
 Heritage Laboratories
 West Hartford, CT
 
 __
 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/Converting-matrices-into-row-vectors-and-saving-as-ASCII-text-tp25523562p25526729.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] plotting least-squares regression against x-axis

2009-09-19 Thread Jason Priem

Hi,
I want to plot the residuals of a least-squares regression.

plot(lm(y~x), which=1)

does this, but it plots the y-axis of my data on the x-axis of the 
residuals plot.  That is, it plots the residual for each y-value in the 
data.  Can I instead use the x-axis of my data as the x-axis of the 
residuals plot, showing the residual for a given x?


Thanks!

Jason Priem
University of North Carolina at Chapel Hill
School of Information and Library Science

__
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] plotting least-squares regression against x-axis

2009-09-19 Thread Sunil Suchindran
x - seq(50)

y - 10 + x * 2 + rnorm(50,0,10)

plot(y~x)

mylm = lm(y~x)

# Use str(mylm) to see how to get the residuals

plot(x,mylm$residuals)


On Sat, Sep 19, 2009 at 8:35 PM, Jason Priem pr...@email.unc.edu wrote:

 Hi,
 I want to plot the residuals of a least-squares regression.

 plot(lm(y~x), which=1)

 does this, but it plots the y-axis of my data on the x-axis of the
 residuals plot.  That is, it plots the residual for each y-value in the
 data.  Can I instead use the x-axis of my data as the x-axis of the
 residuals plot, showing the residual for a given x?

 Thanks!

 Jason Priem
 University of North Carolina at Chapel Hill
 School of Information and Library Science

 __
 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.htmlhttp://www.r-project.org/posting-guide.html
 and provide commented, minimal, self-contained, reproducible code.


[[alternative HTML version deleted]]

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


Re: [R] Converting matrices into row vectors and saving as ASCII text

2009-09-19 Thread David Winsemius



?cat
?apply
?t

You could follow each row of the transposed matrix with a newline:

apply(t(XYbyT), 1, function(x) cat(x, \n, file=output.txt,  
append=TRUE) )



On Sep 19, 2009, at 8:11 PM, Xi Ang wrote:




Thanks for your reply.

Is there a way I can save the data to an ascii file without losing the
row/column structure?
I have tried save(...) and write.table(...) but the output file  
seems to

jumble up the order of the matrix.

Thanks
Xi


David Winsemius wrote:


XYT - array(1:150, dim=c(3,5,10))
XYbyT= matrix(apply(XYT, 3, I), ncol=10)

...or even...

XYbyT= matrix(XYT, ncol=10)

--  
David.


On Sep 19, 2009, at 1:11 PM, Xi Ang wrote:



Hi

I have some data with these dimensions:
5 3 100

which correspond to the x, y, and time dimensions, for a variable,  
p.


I need the data in this format: 100 rows (1 row per time unit),  
and 15

values in each row.

I have attempted to reshape my data


dim(data)

5 3 100


attr(data,'dim')-c(dim(data)[3],dim(data)[1]*dimdata[2])


So I get data with 100 rows, 15 columns.

I need to use this data outside of R, and so have to save it as an
ASCII
file that retains the row-column structure of the data, but I do not
know
how to.

It would be ideal if I could end up with a text file that also has  
an

additional column that labels which time unit (1-100) the row
belongs to,
i.e.

1   a1,1  a1,2 ... a1,15
2   a2,1  a2,2 ... a2,15
3   a3,1  a3,2 ... a3,15
4   a4,1  a4,2 ... a4,15
.
.
.
99
100

Any suggestions would be appreciated.

Thanks
Xi


--
View this message in context:
http://www.nabble.com/Converting-matrices-into-row-vectors-and-saving-as-ASCII-text-tp25523562p25523562.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.


David Winsemius, MD
Heritage Laboratories
West Hartford, CT

__
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/Converting-matrices-into-row-vectors-and-saving-as-ASCII-text-tp25523562p25526729.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.


David Winsemius, MD
Heritage Laboratories
West Hartford, CT

__
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 matrices into row vectors and saving as ASCII text

2009-09-19 Thread David Winsemius

Another possiblity:

write.table( t(XYbyT), file=outcsv.csv, sep=\t)


On Sep 19, 2009, at 9:16 PM, David Winsemius wrote:




?cat
?apply
?t

You could follow each row of the transposed matrix with a newline:

apply(t(XYbyT), 1, function(x) cat(x, \n, file=output.txt,  
append=TRUE) )



On Sep 19, 2009, at 8:11 PM, Xi Ang wrote:




Thanks for your reply.

Is there a way I can save the data to an ascii file without losing  
the

row/column structure?
I have tried save(...) and write.table(...) but the output file  
seems to

jumble up the order of the matrix.

Thanks
Xi


David Winsemius wrote:


XYT - array(1:150, dim=c(3,5,10))
XYbyT= matrix(apply(XYT, 3, I), ncol=10)

...or even...

XYbyT= matrix(XYT, ncol=10)

-- David.

On Sep 19, 2009, at 1:11 PM, Xi Ang wrote:



Hi

I have some data with these dimensions:
5 3 100

which correspond to the x, y, and time dimensions, for a  
variable, p.


I need the data in this format: 100 rows (1 row per time unit),  
and 15

values in each row.

I have attempted to reshape my data


dim(data)

5 3 100


attr(data,'dim')-c(dim(data)[3],dim(data)[1]*dimdata[2])


So I get data with 100 rows, 15 columns.

I need to use this data outside of R, and so have to save it as an
ASCII
file that retains the row-column structure of the data, but I do  
not

know
how to.

It would be ideal if I could end up with a text file that also  
has an

additional column that labels which time unit (1-100) the row
belongs to,
i.e.

1   a1,1  a1,2 ... a1,15
2   a2,1  a2,2 ... a2,15
3   a3,1  a3,2 ... a3,15
4   a4,1  a4,2 ... a4,15
.
.
.
99
100

Any suggestions would be appreciated.

Thanks
Xi


--
View this message in context:
http://www.nabble.com/Converting-matrices-into-row-vectors-and-saving-as-ASCII-text-tp25523562p25523562.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.


David Winsemius, MD
Heritage Laboratories
West Hartford, CT

__
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/Converting-matrices-into-row-vectors-and-saving-as-ASCII-text-tp25523562p25526729.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.


David Winsemius, MD
Heritage Laboratories
West Hartford, CT

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


David Winsemius, MD
Heritage Laboratories
West Hartford, CT

__
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 matrices into row vectors and saving as ASCII text

2009-09-19 Thread Gabor Grothendieck
If the only reason you want to save it is to later read it
back into R later then see ?dump or even ?save

On Sat, Sep 19, 2009 at 8:11 PM, Xi Ang slideprojec...@gmail.com wrote:


 Thanks for your reply.

 Is there a way I can save the data to an ascii file without losing the
 row/column structure?
 I have tried save(...) and write.table(...) but the output file seems to
 jumble up the order of the matrix.

 Thanks
 Xi


 David Winsemius wrote:

 XYT - array(1:150, dim=c(3,5,10))
 XYbyT= matrix(apply(XYT, 3, I), ncol=10)

 ...or even...

 XYbyT= matrix(XYT, ncol=10)

 --
 David.

 On Sep 19, 2009, at 1:11 PM, Xi Ang wrote:


 Hi

 I have some data with these dimensions:
 5 3 100

 which correspond to the x, y, and time dimensions, for a variable, p.

 I need the data in this format: 100 rows (1 row per time unit), and 15
 values in each row.

 I have attempted to reshape my data

 dim(data)
 5 3 100

 attr(data,'dim')-c(dim(data)[3],dim(data)[1]*dimdata[2])

 So I get data with 100 rows, 15 columns.

 I need to use this data outside of R, and so have to save it as an
 ASCII
 file that retains the row-column structure of the data, but I do not
 know
 how to.

 It would be ideal if I could end up with a text file that also has an
 additional column that labels which time unit (1-100) the row
 belongs to,
 i.e.

 1   a1,1  a1,2 ... a1,15
 2   a2,1  a2,2 ... a2,15
 3   a3,1  a3,2 ... a3,15
 4   a4,1  a4,2 ... a4,15
 .
 .
 .
 99
 100

 Any suggestions would be appreciated.

 Thanks
 Xi


 --
 View this message in context:
 http://www.nabble.com/Converting-matrices-into-row-vectors-and-saving-as-ASCII-text-tp25523562p25523562.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.

 David Winsemius, MD
 Heritage Laboratories
 West Hartford, CT

 __
 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/Converting-matrices-into-row-vectors-and-saving-as-ASCII-text-tp25523562p25526729.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.


[R] Regarding KS Test for Goodness-of-Fit

2009-09-19 Thread Manuj Sharma
I have fitted Hyperexponential distribution (HED) and Hypoexponential 
distribution (HoED) to two different data sets (of size 1000 numeric values 
each) using a software package called EMpht.
I want to use R to perform goodness-of-fit test for the fitted distribution 
with respect to the empirical CDFs of the data sets using KS test 
(Kolmogorov-Smirnov test). 
ks.test() function in R takes the first argument as the data set, 
and the second argument as the name of the distribution, followed by the 
distribution parameter values. In case of the CDFs that are already supported 
by R, this is simple (for example: ks.test(data_set, pnorm, mean, sd)). 

1. Can somebody please suggest whether R has in-built support for 
Hyperexponential and Hypoexponential CDFs 
(they do not appear in the list of distribution given in An Introduction to 
R))?

2. If I write an R function to compute HED (or HoED) CDF value, can I use that 
function name as second argument in ks.test()? For example, if I implement an R 
function named HED_CDF with parameters parameters..., will it be correct to 
use ks.test() as follows:
    ks.test(data_set, HED_CDF, parameters...)
Will it give correct result?

- Manuj Sharma



  From cricket scores to your friends. Try the Yahoo! India Homepage! 
http://in.yahoo.com/trynew
[[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] Barplot error with space=0, log=x

2009-09-19 Thread Shawn Polson

Hello,

I would like to do a barplot that has a log-scaled x axis, but no space
between the bars.  I have attempted the following, but it produces an error
that seems to indicate that the log scaling is dependent on the space being
 0:

x-c(1:100)
barplot(x,log=x,space=0)

Error message:
In plot.window(xlim, ylim, log = log, ...) :
  nonfinite axis limits [GScale(-inf,2,1, .); log=1]

Trying something like this does make a plot with effectively no space
between bars, but the first bar becomes unacceptably wide:

barplot(x,log=x,space=0.001)

I get equivalent results with barplot and barplot2.

Does anyone know a work-around for this issue?

Thank you,
Shawn Polson

Delaware Biotechnology Institute
University of Delaware
-- 
View this message in context: 
http://www.nabble.com/Barplot-error-with-space%3D0%2C-log%3D%22x%22-tp25527514p25527514.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] Computing the sum of cross products of rows of a matrix

2009-09-19 Thread Stephan Lindner
Hi everyone,


I would like to compute the sum of cross products of rows of a
matrix. Does anyone know how to do this without an explicit loop for
computational efficiency? Below is a code example.


Thanks!

Stephan




# I.e., if I have a matrix like this 

x - matrix(rep(c(1,2,3),3),ncol=3)

##  x
##  [,1] [,2] [,3]
## [1,]111
## [2,]222
## [3,]333


## and a storage matrix like this 

cross - matrix(rep(0,9),ncol=3)


## then use a loop to sum up the cross products of the rows 

for (i in 1:nrow(x)){ cross - cross+tcrossprod(x[i,]) }


## The result
##
##  cross
##  [,1] [,2] [,3]
## [1,]   14   14   14
## [2,]   14   14   14
## [3,]   14   14   14






-- 
---
Stephan Lindner
University of Michigan

__
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] Computing the sum of cross products of rows of a matrix

2009-09-19 Thread Jorge Ivan Velez
Dear Stephan,
Try

crossprod(x)

HTH,
Jorge


On Sat, Sep 19, 2009 at 11:42 PM, Stephan Lindner  wrote:

 Hi everyone,


 I would like to compute the sum of cross products of rows of a
 matrix. Does anyone know how to do this without an explicit loop for
 computational efficiency? Below is a code example.


 Thanks!

Stephan




 # I.e., if I have a matrix like this

 x - matrix(rep(c(1,2,3),3),ncol=3)

 ##  x
 ##  [,1] [,2] [,3]
 ## [1,]111
 ## [2,]222
 ## [3,]333


 ## and a storage matrix like this

 cross - matrix(rep(0,9),ncol=3)


 ## then use a loop to sum up the cross products of the rows

 for (i in 1:nrow(x)){ cross - cross+tcrossprod(x[i,]) }


 ## The result
 ##
 ##  cross
 ##  [,1] [,2] [,3]
 ## [1,]   14   14   14
 ## [2,]   14   14   14
 ## [3,]   14   14   14






 --
 ---
 Stephan Lindner
 University of Michigan

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


[[alternative HTML version deleted]]

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


Re: [R] How to avoid copy-paste when copying code from this list

2009-09-19 Thread Gabor Grothendieck
OK.  I've combined both approaches into a single process.source()
function.  Just place the mixed R code and output in the clipboard
and run:

  source.commands()

it will 1. first display clipboard in a suitable manner for pasting into
an r-help post and then 2. execute it.

Thus you can either copy the code from an r-help post into the
clipboard and run the command or you can copy it from earlier
in your session and run the same command.  Just ignore whichever
of the two outputs you don't need (or use the action= argument
to select the appropriate one).

# If clipboard contains R source statements prefaced by
#  or + (or similar prefaces used in example()) together
# with unprefixed output then:
#source.commands()
# will perform these actions in sequence:
# 1. display the source removing the prefixes and commenting
#out the output and
# 2. run the source
# Alternately the first argument, action, can select only one of these.
# In all cases it invisibly returns the source that would have been
# displayed under #1.
#
process.source - function(action = c(both, run, show), echo = TRUE,
   max.deparse.length = Inf, ...) {
   # L - readLines(pipe(pbpaste)) # use this instead for Mac
   L - readLines(clipboard)
   rx - ^[[:blank:]]*[^+[:blank:]]*[+]
   is.cmd - grepl(rx, L)
   L[is.cmd] - gsub(paste(rx, ?), , L[is.cmd])
   L[!is.cmd] - paste(#, L[!is.cmd])
   action - match.arg(action)
   if (action != run) for(el in L) cat(el, \n)
   if (action == both) cat(##\n)
   if (action != show) source(textConnection(L), echo = echo,
 max.deparse.length = max.deparse.length, ...)
   invisible(L)
}

On Sat, Sep 19, 2009 at 12:46 PM, baptiste auguie
baptiste.aug...@googlemail.com wrote:
 Neat!

 What if, instead, one wanted to format his/her code in the console
 before sending it by email? Any tips for that?

 (I proposed something like options(prompt= ) above, but got stuck
 with adding a comment # to printed results)

 Thanks,

 baptiste




 2009/9/19 Gabor Grothendieck ggrothendi...@gmail.com:
 Combining the code posted by myself, Duncan and David we have:

 # Usage: copy code from r-help to clipboard, then in R enter this:
 #   source.commands()
 #
 source.commands - function(echo = TRUE, max.deparse.length = Inf, ...) {
   # L - readLines(pipe(pbpaste)) # use this instead for Mac
   L - readLines(clipboard)
   L - grep(^[[:blank:]]*[^+[:blank:]]*[+], L, value = TRUE)
   L - sub(^[[:blank:]]*[^+[:blank:]]*[+] ?, , L)
   source(textConnection(L), echo = echo,
      max.deparse.length = max.deparse.length, ...)
 }

 It might be possible to automate the check for Mac using .Platform$GUI


 On Sat, Sep 19, 2009 at 12:08 PM, David Winsemius
 dwinsem...@comcast.net wrote:

 On Sep 19, 2009, at 11:58 AM, johannes rara wrote:

 Thanks for the responses.

 I think that the best way to avoid lots of hassle is that people
 copy-paste their solutions from their code editor, NOT from R console.
 For example, I usually save those solutions for my code archive, and
 if I want to run these later on (using Tinn-R), I have to parse 
 and + marks anyway.

 I agree entirely but trying to change posting behavior appears to be a
 difficult exercise. It would also be much preferred if people would learn to
 post the output of dput on an object, rather than what is displayed on the
 console when the object is print()ed.

 --
 David.

 -Johannes

 2009/9/19 David Winsemius dwinsem...@comcast.net:

 On Sep 19, 2009, at 10:58 AM, Duncan Murdoch wrote:


 snip


 Here's a quick version of CleanTranscript, translated to R:

 CleanTranscript - function(lines) {
  lines - grep(^[[:blank:]]*[^+[:blank:]]*[+], lines, value = TRUE)
  lines - sub(^[[:blank:]]*[^+[:blank:]]*[+] ?, , lines)
 }

 So on systems where clipboard is supported, executing

 source(textConnection(CleanTranscript(readLines(clipboard))),
      echo = TRUE, max.deparse.length=Inf)

 will do something similar to what the Windows Paste commands only menu
 option does, but you'd need a different incantation on other systems.
 And
 even this will sometimes mess up, e.g. it will sometimes misinterpret
 output
 that contains  or + as input.

 Duncan Murdoch

 On Macs (and possibly other *NIXen) the equivalent to reading from the
 clipboard is: pipe(pbpaste)

 Testing shows that a simple modification after defining CleanTranscript
 produces no error on the example above:

 source(textConnection(CleanTranscript(readLines(pipe(pbpaste,

 +        echo = TRUE, max.deparse.length=Inf)

 example(mean)


 snip
 
 David Winsemius, MD
 Heritage Laboratories
 West Hartford, CT

 __
 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
 

[R] axis: forcing last label to print

2009-09-19 Thread Shawn Polson

Hello,

I often use the axis command to add labels to axes with large numbers of
consecutively numbered names:

y- barplot (x, log=x)
axis(1, at = y, labels = c(1:12345))

Since there are more labels than will fit in the space, the command only
prints selected labels.  This is what I want, except that it never actually
prints a label for the final item.  Thus I end up with labels something like
this:

1  16  123  1432  2134  3235  6578  11385

when I really want the last label displayed to be the final category number
(12345):

1  16  123  1432  2134  3235  6578   12345

Short of manually choosing the labels, does anyone know a way to force the
last category to be among those printed when axis selects labels?

Thanks,
Shawn Polson

Delaware Biotechnology Institute
University of Delaware
-- 
View this message in context: 
http://www.nabble.com/axis%3A-forcing-last-label-to-print-tp25527633p25527633.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] plotting least-squares regression against x-axis

2009-09-19 Thread milton ruser
By the way, how about:

plot(y,mylm$residuals)

So you can have an idea of your error distribution across your response
variable domain. :-)

milton
toronto=brazil
On Sat, Sep 19, 2009 at 9:02 PM, Sunil Suchindran sunilsuchind...@gmail.com
 wrote:

 x - seq(50)

 y - 10 + x * 2 + rnorm(50,0,10)

 plot(y~x)

 mylm = lm(y~x)

 # Use str(mylm) to see how to get the residuals

 plot(x,mylm$residuals)


 On Sat, Sep 19, 2009 at 8:35 PM, Jason Priem pr...@email.unc.edu wrote:

  Hi,
  I want to plot the residuals of a least-squares regression.
 
  plot(lm(y~x), which=1)
 
  does this, but it plots the y-axis of my data on the x-axis of the
  residuals plot.  That is, it plots the residual for each y-value in the
  data.  Can I instead use the x-axis of my data as the x-axis of the
  residuals plot, showing the residual for a given x?
 
  Thanks!
 
  Jason Priem
  University of North Carolina at Chapel Hill
  School of Information and Library Science
 
  __
  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.htmlhttp://www.r-project.org/posting-guide.html
 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.htmlhttp://www.r-project.org/posting-guide.html
 and provide commented, minimal, self-contained, reproducible code.


[[alternative HTML version deleted]]

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


Re: [R] Replacing values in dataframes

2009-09-19 Thread Don MacQueen

What I would probably do is along these lines:

  iddf - data.frame(Sample.id=names(Prot.amount), new.id=Prot.amount[1,])

  newNAD - merge( NAD, iddf)

This is not tested, but it looks right to me, 
assuming I understand the structure of what 
you're trying to do.


I'm also assuming that NAD has more than three 
rows, and that Prot.amount has as many columns as 
NAD has rows. And that you just showed us the 
first three rows of NAD and first three columns 
of Prot.amount in order to keep the email simple.


One final note ... if Prot.amount is an object 
within R, it is *not* a file. You may have read 
it in from a file, of course, but it isn't a file 
inside R. I'm assuming it's a dataframe.


-Don

At 1:18 PM +0300 9/19/09, Monna Nygård wrote:

Hi,



This is a question of a newbie getting into the exciting world of R.



I have several dataframes in the same format as NAD:






 NAD[1:3,1:3]


Sample.Id Main.abs..1 Main.abs..2
148   10a 0.04836 0.04994
167  11a_1109 0.32245 0.36541
173  11b_1109 0.29293 0.32815


What I want to do is to replace the Sample.Id 
with a corresponding number.The number i have in 
another file,called Prot.amount





 Prot.amount[1:3,1]

 10a 11a_1109 11b_1109
  15.516   38.248   42.297






 row.names(NAD)-(NAD[,1])
 NAD$Sample.Id - replace(NAD$Sample.Id, 
NAD$Sample.Id==10a,Prot.amount[10a,1])



 NAD[1:3,1:3]

 Sample.Id Main.abs..1 Main.abs..2
10a 15.516 0.04836 0.04994
11a_1109  11a_1109 0.32245 0.36541
11b_1109  11b_1109 0.29293 0.32815



So what I have tried to do is to write a 
function that would allow me to replace the 
values automatically of all dataframes. This I 
just can't get to work. 




Thank you so much in advance!
 			  		 
_

[[elided Hotmail spam]]

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



--
-
Don MacQueen
Lawrence Livermore National Laboratory
Livermore, CA, USA
925-423-1062
m...@llnl.gov

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