Re: [R] colouring a table, data.frame or matrix in an interactive R session

2012-01-08 Thread Jakson Alves de Aquino
On Sun, Jan 8, 2012 at 9:52 AM, Vincent Zoonekynd zoo...@gmail.com wrote:
 On 7 January 2012 19:48, drflxms drfl...@googlemail.com wrote:

 as I am dealing with complex confusion matrices, I wonder whether there
 might be a way to colour text/tabular data in R. I.e. imagine
 highlighting the true positive values or certain classes in a table.

 The colorout package does part of what you want: colouring the
 output, in a terminal.
 But some more work may be needed if you want to change the colours
 depending on the values of your matrix.

With the next version of the colorout package users will be able to
choose a different color for negative numbers. I'll release it soon
but anyone wanting to try it immediately may write directly to me.

-- 
Jakson Alves de Aquino
Federal University of Ceará
Social Sciences Department
www.lepem.ufc.br/aquino.php

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/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] Making outregs in R

2011-12-09 Thread Jakson Alves de Aquino
On Fri, Dec 9, 2011 at 7:22 AM, David . loove...@hotmail.com wrote:
 I am interesting in making an equivalent command like
 outreg in stata where I get all my 8 regressions in one table.
 Does R have an easy command to that?

The function of mtable() of memisc package may be what you want. There
is also a script called outreg-worked.R written by Paul Johnson that
you can find on the web.

-- 
Jakson

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/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] New package 'colorout' to colorize R output on terminal emulators

2011-11-29 Thread Jakson Alves de Aquino
Dear R Community,

I'm pleased to announce the availability of 'colorout' on CRAN.
The package colorizes R output when it is running on a terminal
emulator.

Screenshot: http://www.lepem.ufc.br/jaa/R_color_output.png

You can use either 16 colors (8 colors * 2 degrees of intensity)
or 256 colors to highlight normal text, numbers, strings,
warnings, errors and the keywords TRUE, FALSE, NA, NaN and Inf.

The package is not available for Windows, and there is no support
for Graphical User Interfaces, such as RStudio, RKward, JGR, Rcmdr
and other interfaces which have their own engine to display R
output. The colorization of output only works if R is compiled
for Unix systems and it is running interactively in a terminal
emulator (like when using RGedit or Vim-R-plugin).

The terminal must support Select Graphic Rendition (SGR, also
known as ANSI escape codes or sequences), otherwise you may see
garbage like this:

 rnorm(5)
[32m[ [33m1 [32m] [0m [32m  [33m0.07574585 [32m [0m [32m
[33m0.88167822 [32m [0m [32m  [33m0.60788656 [32m [0m [32m
[33m1.13590951 [32m [0m [32m  [33m1.07758879 [32m [0m [32m [0m

Notes for Emacs/ESS users:
  1. Emacs terminal does not support 256 colors.
  2. When the colorizing of R output is enabled, the ESS
 autocompletion of R object names and function arguments
 stops working on the R buffer.

Functions available in the package:

ColorOut:   Colorize R output in terminal emulator
noColorOut: Stop colorizing R output
setOutputColors:Set the colors to be used on R output
setOutputColors256: Set the colors to be used on R output
show256Colors:  Create and show a table with 256 colors

Any feedback will be appreciated.

Sincerely,

-- 
Jakson Alves de Aquino
Federal University of Ceará
Social Sciences Department
www.lepem.ufc.br/aquino.php
jalvesaq at gmail.com

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


Re: [R] Boxplot

2011-11-27 Thread Jakson Alves de Aquino
On Sun, Nov 27, 2011 at 2:15 AM, Jeffrey Joh johjeff...@hotmail.com wrote:
 I'm trying to do the second case among Jim's suggestions.  I used
 Bert's suggestion and it works great.

 I would also like to ask if anyone is familiar with a package for
 making box-plots.  I would like to bin my datapoints at defined X
 intervals and display a boxplot for each bin on the same chart.  In
 Stata, there is a tool for making these, and it varies the width of
 the boxplot based on the number of points in each plot.  I am hoping
 there is a similar tool for R.

You can do it if you pass suitable values for the 'width' argument of
boxplot().

-- 
Jakson Alves de Aquino
Federal University of Ceará
Social Sciences Department
www.lepem.ufc.br/aquino.php

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/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] On-demand importing of a package

2011-11-25 Thread Jakson Alves de Aquino
On Fri, Nov 25, 2011 at 1:21 PM, Gabor Grothendieck
ggrothendi...@gmail.com wrote:

[...]

 I was framing this in terms of the Matrix example, but perhaps its
 easier to understand with the actual example which motivated this for
 me.  That is, the feature is that whenever sqldf is installed then
 RSQLite is installed too without having RSQLite automatically load
 when sqldf loads.

[...]

I think that the following procedure has the result that you want:

Put in the DESCRIPTION file:

Imports: RSQLite

And in the R code write something like:

RSQLite::AnRSQLiteFunction()

-- 
Jakson Alves de Aquino
Federal University of Ceará
Social Sciences Department
www.lepem.ufc.br/aquino.php

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/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] On-demand importing of a package

2011-11-25 Thread Jakson Alves de Aquino
On Fri, Nov 25, 2011 at 2:40 PM, Gabor Grothendieck
ggrothendi...@gmail.com wrote:
 I think that the following procedure has the result that you want:

 Put in the DESCRIPTION file:

 Imports: RSQLite

 And in the R code write something like:

 RSQLite::AnRSQLiteFunction()

 I had been thinking of using Imports in DESCRIPTION but was concerned
 that that would put RSQLite objects ahead of everything else on
 sqldf's search path even when not wanted but I gather you are
 intending that Imports be used in DESCRIPTION: but _not_ in the
 NAMESPACE file.  I think that that would likely work. I will test it
 out to be sure. What I would probably want to do is to require()
 RSQLite in case the user wants to mix sqldf and RSQLite calls and I
 will check whether the check procedure allows that if the package is
 only named in Imports but, if not, it might be sufficient to put
 RSQLite in both Imports and Suggests.  Thanks.

I have done this with the 'descr' package. It wasn't necessary to put
the imported packages in two places, only in the Imports field. This
was enough to make R install all dependencies but not load then along
with 'descr'.

-- 
Jakson Alves de Aquino
Federal University of Ceará
Social Sciences Department
www.lepem.ufc.br/aquino.php

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/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] new package: colorout (Colorize R output on terminal emulator)

2011-11-16 Thread Jakson Alves de Aquino
Hello,

Two days ago I posted a patch to R source code to colorize its output
when running it in a terminal emulator (Linux or other Unix with
support to ANSI escape codes).

I converted the patch into an R package, and people interested in
testing it should do the following:

1) Download and install:

wget http://www.lepem.ufc.br/jaa/colorout_0.1.tar.gz
R CMD INSTALL colorout_0.1.tar.gz

2) Run R and load the package:

library(colorout)

Best regards,

-- 
Jakson Aquino
Federal University of Ceará - Brazil
www.lepem.ufc.br/aquino.php

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/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] Colored output in terminal emulator

2011-11-14 Thread Jakson Alves de Aquino
Hi,

I wrote a small patch to make it possible to get colored output from R
running in a Linux terminal emulator. It's a dirty patch. I hope that
someone with better knowledge of R source code and C programming will
improve it. To force the use of Rstd_WriteConsoleEx function
(src/unix/sys-std.c) I edited the file src/unix/system.c and I copied
four lines from an AQUA #ifdef preprocessor directive and pasted them
outside the condition. Then I edited the Rstd_WriteConsoleEx function
to change the colors of the output: errors and warnings are red,
normal output is green and numbers are yellow. If anyone is interested
in trying the patch, here how to do it:

1) Copy the file rcolor.patch to R-2.14.0/src/unix/ directory.
2) Go to the R-2.14.0/src/unix directory and do the following command:

patch -p3  rcolor.patch

3) Compile R.
4) Put in your ~/.Rprofile:
options(color.output = TRUE)

The patch is attached and a screenshot is available at
http://www.lepem.ufc.br/jaa/R_color_output.png

-- 
Jakson Aquino
__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/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] Need some help in R : value more than equals to a row.

2009-06-07 Thread Jakson Alves de Aquino
suparna mitra wrote:
 Hallo,
  I was trying some code, but couldn't make one step of the code properly.
 Can anybody  please  help me?
 
 I have one matrix like this
 values
   [,1]   [,2]   [,3]  [,4]  [,5]
 [1,] 0.778 0.3611 0. 0.139 0.000
 [2,] 1.000 0. 0.53846154 0.000 0.5384615
 [3,] 0.520 0.4800 0.6400 0.000 0.880
 [4,] 0.8928571 1. 0. 0.8928571 0.1071429
 
 
 And I want to get some matrix like:
 values.new
   [,1]  [,2]  [,3]  [,4]  [,5]
 [1,] 0.2  0.4  0.6  0.8  1.0
 [2,] 0.2  1.0  0.6  1.0  0.6
 [3,] 0.6  0.8  0.4  1.0  0.2
 [4,] 0.6  0.2  1.0  0.6  0.8
 
 
 This table should be computed by taking proportion of values in the row that
 are larger or equals to the value being considered with the total no of
 objects in the row.

I think the code below do what you want, but I would like to know how to
do it with one of the *apply functions:

m - read.table(stdin(), header=F)
0.778 0.3611 0. 0.139 0.000
1.000 0. 0.53846154 0.000 0.5384615
0.520 0.4800 0.6400 0.000 0.880
0.8928571 1. 0. 0.8928571 0.1071429

m - as.matrix(m)
bdim - dim(m)
m2 - m
for(i in 1:bdim[1])
  for(j in 1:bdim[2])
m2[i,j] - sum(m[i,j] = m[i,]) / bdim[2]
m2

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/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] Journal Articles that Have Used R

2009-06-06 Thread Jakson Alves de Aquino
Jason Rupert wrote:
 Is there a way to get a reference list of journal articles that have used R?  
 
 I am just looking for some examples of R graphs and presentation of results 
 where R was used to generate the results. 

Did you try Google Scholar:

http://scholar.google.com.br/scholar?q=R%3A+A+Language+and+Environment+for+Statistical+Computing

It has cited by links.

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/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] Bug in gmodels CrossTable()?

2009-05-31 Thread Jakson Alves de Aquino
Is the code below showing a bug in Crosstable()? My expectation was that
the values produced by xtabs were rounded instead of truncated:

library(gmodels)
abc - c(a, a, b, b, c, c)
def - c(d, e, f, f, d, e)
wgt - c(0.8, 0.6, 0.4, 0.5, 1.4, 1.3)

xtabs(wgt ~ abc + def)

CrossTable(xtabs(wgt ~ abc + def), prop.r = F, prop.c = F,
  prop.t = F, prop.chisq = F)

-- 
Jakson Aquino
Professor of Political Science
Federal University of Ceara, Brazil

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/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] Bug in gmodels CrossTable()?

2009-05-31 Thread Jakson Alves de Aquino
Dear Marc Schwartz,

You are correct: there is no bug in CrossTable(). To get what I want I
should have done:

CrossTable(round(xtabs(wgt ~ abc + def)), prop.r = F, prop.c = F,
  prop.t = F, prop.chisq = F)

Thank you for the explanation!

Jakson


Marc Schwartz wrote:
 On May 31, 2009, at 7:51 AM, Jakson Alves de Aquino wrote:
 
 Is the code below showing a bug in Crosstable()? My expectation was that
 the values produced by xtabs were rounded instead of truncated:

 library(gmodels)
 abc - c(a, a, b, b, c, c)
 def - c(d, e, f, f, d, e)
 wgt - c(0.8, 0.6, 0.4, 0.5, 1.4, 1.3)

 xtabs(wgt ~ abc + def)

 CrossTable(xtabs(wgt ~ abc + def), prop.r = F, prop.c = F,
  prop.t = F, prop.chisq = F)
 
 
 CrossTable() is designed to take one or two vectors, which are then
 [cross-]tabulated to yield integer counts, OR a matrix of integer
 counts, not fractional values. In the latter case, it is presumed that
 the matrix is the result of an 'a priori' cross-tabulation operation
 such as the use of table().
 
 The output of xtabs() above is:
 
 xtabs(wgt ~ abc + def)
def
 abc   d   e   f
   a 0.8 0.6 0.0
   b 0.0 0.0 0.9
   c 1.4 1.3 0.0
 
 
 
 The relevant output of CrossTable() in your example above shows:
 
 
  | def
  abc | d | e | f | Row Total |
 -|---|---|---|---|
a | 0 | 0 | 0 | 1 |
 -|---|---|---|---|
b | 0 | 0 | 0 | 0 |
 -|---|---|---|---|
c | 1 | 1 | 0 | 2 |
 -|---|---|---|---|
 Column Total | 2 | 1 | 0 | 5 |
 -|---|---|---|---|
 
 
 
 The internal table object that would be generated here is effectively:
 
 addmargins(xtabs(wgt ~ abc + def))
  def
 abc d   e   f Sum
   a   0.8 0.6 0.0 1.4
   b   0.0 0.0 0.9 0.9
   c   1.4 1.3 0.0 2.7
   Sum 2.2 1.9 0.9 5.0
 
 
 
 The textual output of CrossTable() is internally formatted using
 formatC(..., format = d), which is an integer based format:
 
 formatC(addmargins(xtabs(wgt ~ abc + def)), format = d)
  def
 abc   d e f Sum
   a   0 0 0 1
   b   0 0 0 0
   c   1 1 0 2
   Sum 2 1 0 5
 
 
 
 In other words, you are getting the integer coerced values of the
 individual cells and then the same for the column, row and table totals:
 
 matrix(as.integer(addmargins(xtabs(wgt ~ abc + def))), 4, 4)
  [,1] [,2] [,3] [,4]
 [1,]0001
 [2,]0000
 [3,]1102
 [4,]2105
 
 
 
 If you review ?as.integer, you will note the following in the 'Value'
 section:
 
   Non-integral numeric values are truncated towards zero (i.e.,
 as.integer(x) equals trunc(x) there)
 
 
 
 The output is correct, if confusing, but you are really using the
 function in a fashion that is not intended.
 
 HTH,
 
 Marc Schwartz
 


__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/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] Cream Text Editor

2009-05-24 Thread Jakson Alves de Aquino
JiHO wrote:
 On 2009-May-23  , at 20:16 , Jakson Alves de Aquino wrote:
 
 Just a note: there is no need of Esc before F9. Almost all key
 bindings work in insert, normal and visual modes.
 
 Well, without switching to the non-insert mode, I find that pressing F9
 prints the commands in the file instead of executing them. Maybe that's
 specific to Cream.

I installed and tested cream here, and F9 in insert mode works for me,
but in few minutes I've found other problems. The customization of key
bindings in .vimrc is ignored by cream and omni completion doesn't work
correctly: cream inserts a spurious '.x:call Cream - redo(i)' in
addition to the correct completion. It seems that cream is unable to
work properly in expert mode. Instead of using cream in expert mode it
might be easier to use gvim. Alternatively, if you prefer to use cream,
it might be easier to copy and paste commands in a regular R session
running directly in a terminal emulator because you will benefit from
R's built-in tab-completion.

-- 
Jakson

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/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] Cream Text Editor

2009-05-24 Thread Jakson Alves de Aquino
Paul Heinrich Dietrich wrote:
 Thank you much for the help, I will work on this over the weekend.  Is there
 a way in Windows to connect R and Cream?

Perhaps, although I can't help... It would be necessary to write another
plugin: https://stat.ethz.ch/pipermail/r-help/2009-May/197794.html

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/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] Cream Text Editor

2009-05-23 Thread Jakson Alves de Aquino

As pointed by JiHO the biggest disadvantage of using the plugin is that
R is running through a pipe and consequently it is less interactive.
Just a note: there is no need of Esc before F9. Almost all key
bindings work in insert, normal and visual modes.

The last version of the plugin allows the user to set the terminal
emulator in the vimrc and now all key bindings are customizable. The
details are in the plugin's documentation.

Please write, to me if you find bugs in the plugin.

Jakson

JiHO wrote:
 On 2009-May-23  , at 17:40 , Paul Heinrich Dietrich wrote:
 
 I'm interested in easing my way into learning VIM by first using the
 Cream
 text editor, liking the idea that it will work on both my Linux and
 Windows
 computers.  I've installed Cream on my Linux machine, but can't figure
 out
 how to make Cream talk to R?  Does anybody know?  I'm using Ubuntu if it
 makes a difference.  Thanks.
 
 You should install the R Vim Plugin and its dependencies:
 http://www.vim.org/scripts/script.php?script_id=2628
 This creates commands and icons dedicated to the interaction between Vim
 and R.
 
 
 Then switch cream Settings  Preferences  Expert Mode.
 
 This will allow you to work in Cream and have all the simple keyboard
 shortcuts (Control-C, Control-V etc.) but still be able to switch
 between modes as in vim. By default you are in insert mode. You need to
 switch to normal mode (by pressing ESC) to be able to use the commands
 of the R-Vim plugin.
 
 The workflow is therefore:
 - open a R file
 - edit stuff
 - press ESC (to switch to non-edit mode)
 - start R in a terminal (click the icon or press F2)
 - send lines/selection (F9) or document (F5)
 - press ESC (to switch back to insert mode)
 - edit 2 lines
 - ESC
 - F9
 - F9
 - ESC
 - edit again
 etc...
 
 The terminal opened this way does not work completely as a regular one
 and there are some caveats when reading help and using general command
 line editing shortcuts (Ctrl-R for backward search for example). I
 haven't found a way around them so I usually open a second terminal to
 read the help in, or set R to display the help as HTML files in a
 browser window.
 
 I must say that those caveats can be quite serious and I often find
 myself just using copy-paste from gedit in a terminal:
 - set your desktop to focus follow mouse
 - select text in your editor
 - move the mouse to the terminal
 - click middle mouse button
 - move the mouse back to the editor
 etc...
 More cumbersome but reliable.
 
 Final note: since you are on ubuntu, you may want to change the terminal
 from the default X-term to gnome-terminal. You have to edit the file
 .vim/ftplugin/r.vim. There is a line commented with the gnome-terminal
 command instead of xterm. Uncomment this one and comment the xterm one.
 
 JiHO
 ---
 http://jo.irisson.free.fr/

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/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 do a pretty panel plot?

2009-05-15 Thread Jakson Alves de Aquino
Ajay Shah wrote:
 Here's my best version of your code:
 
 ## Data
 M - structure(list(date = structure(c(13634, 13665, 13695, 13726, 
   13757, 13787, 13818, 13848, 13879, 13910, 13939, 13970, 
 14000, 
   14031, 14061, 14092, 14123, 14153, 14184, 14214, 14245, 
 14276, 
   14304, 14335), class = Date),
 cospi = c(1987.31, 2033.37, 2140.13, 
   2120.66, 2427.09, 2917.7, 2915.28, 3262.06, 2616.26, 
 2617.75, 
   2277.69, 2538.13, 2374.09, 1911.22, 2063.73, 2081.28, 
 1813.58, 
   1304.96, 1219.73, 1361.74, 1299.2, 1242.74, 1339.18, 
 1557.29), 
 cospi.PE = c(19.2, 19.69, 20.13, 24.08, 27.61, 30.9, 
 30.69, 
   34.92, 26.95, 27.63, 23.86, 26.14, 23.72, 19.5, 23.43, 
 23.73, 
   20.69, 16.4, 16.12, 18.04, 18.46, 18.86, 20.24, 23.53)),
.Names = c(date, cospi, cospi.PE),
row.names = 209:232, class = data.frame)
 
 ## Set up par's to make 2 panel chart 
 par(bty=l); par(ps=10)
 par(mfrow=c(2,1))   # try to get two plots, one above the other 
 par(mar=c(0,4,0,1)) ## Set par(mar) to eliminate X axis gap 
 par(oma=c(2,2,2,2))
 
 ## Make Plot 1
 plot(M$date, M$cospi, type=l, log=y, 
  xaxs=i, yaxs=i, axes=F, lwd=2,
  ylab=Cospi level) 
 axis(1, col=grey, at=NULL, labels=FALSE) 
 axis(2, col=black, labels=TRUE) 
 axis(3, col=grey, labels=TRUE)
 grid(col = lightgrey, lty=1)
 box(col = grey)
 
 ## Adjust par(mar) for 2nd plot
 par(mar=c(2,4,0,1))
 
 ## Second plot
 plot(M$date, M$cospi.PE, type=l, col=black, log=y, 
  xaxs=i, yaxs=i, axes=F, lwd=2,
  ylab=Cospi P/E) 
 axis(2, col=black, at=NULL, labels=T) 
 axis(1, col=lightgrey, at=NULL, labels=T)
 grid(col = lightgrey, lty=1)
 box(col = grey)
 

I think it's better if the lines are above the grid:

## Data
M - structure(list(date = structure(c(13634, 13665, 13695, 13726,
13757, 13787, 13818, 13848, 13879, 13910, 13939, 13970, 14000,
14031, 14061, 14092, 14123, 14153, 14184, 14214, 14245, 14276,
14304, 14335), class = Date),
cospi = c(1987.31, 2033.37, 2140.13,
  2120.66, 2427.09, 2917.7, 2915.28, 3262.06, 2616.26, 2617.75,
  2277.69, 2538.13, 2374.09, 1911.22, 2063.73, 2081.28, 1813.58,
  1304.96, 1219.73, 1361.74, 1299.2, 1242.74, 1339.18, 1557.29),
cospi.PE = c(19.2, 19.69, 20.13, 24.08, 27.61, 30.9, 30.69,
  34.92, 26.95, 27.63, 23.86, 26.14, 23.72, 19.5, 23.43, 23.73,
  20.69, 16.4, 16.12, 18.04, 18.46, 18.86, 20.24, 23.53)),
  .Names = c(date, cospi, cospi.PE),
  row.names = 209:232, class = data.frame)

## Set up par's to make 2 panel chart
par(bty=l)
par(ps=10)
par(mfrow=c(2,1))   # try to get two plots, one above the other
par(mar=c(0,4,0,1)) ## Set par(mar) to eliminate X axis gap
par(oma=c(2,2,2,2))

## Make Plot 1
plot(M$date, M$cospi, type=l, log=y, xaxs=i, yaxs=i, axes=F,
  lwd=0, ylab=Cospi level)
grid(col = lightgrey, lty=1)
lines(M$date, M$cospi, type=l, lwd=2)
axis(1, col=grey, at=NULL, labels=FALSE)
axis(2, col=black, labels=TRUE)
axis(3, col=grey, labels=TRUE)
box(col = grey)

## Adjust par(mar) for 2nd plot
par(mar=c(2,4,0,1))

## Second plot
plot(M$date, M$cospi.PE, type=l, col=black, log=y,
  xaxs=i, yaxs=i, axes=F, lwd=0, ylab=Cospi P/E)
grid(col = lightgrey, lty=1)
lines(M$date, M$cospi.PE, col=black, lwd=2)
axis(2, col=black, at=NULL, labels=T)

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/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] Reading large files quickly

2009-05-09 Thread Jakson Alves de Aquino
Rob Steele wrote:
 I'm finding that readLines() and read.fwf() take nearly two hours to
 work through a 3.5 GB file, even when reading in large (100 MB) chunks.
  The unix command wc by contrast processes the same file in three
 minutes.  Is there a faster way to read files in R?

I use statist to convert the fixed width data file into a csv file
because read.table() is considerably faster than read.fwf(). For example:

system(statist --na-string NA --xcols collist big.txt big.csv)
bigdf - read.table(file = big.csv, header=T, as.is=T)

The file collist is a text file whose lines contain the following
information:

variable begin end

where variable is the column name, and begin and end are integer
numbers indicating where in big.txt the columns begin and end.

Statist can be downloaded from: http://statist.wald.intevation.org/

-- 
Jakson Aquino
Social Sciences Department
Federal University of Ceará, Brazil

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