Re: [R] Invalid connection error message when trying to write a file

2013-12-16 Thread Uwe Ligges
I guess your problem is that you cannot write toplevel into "c:\" with 
your permissions?


Best,
Uwe Ligges


On 16.12.2013 16:40, John Karon wrote:

Thanks for pointing out my error after specifying the destination in the
file(  ) function.  What you proposed also did not work.
It turns out the solution is to give the file name but not include the
path; the resulting file is written in the working directory.
The mystery is that including the path had previously work.
John Karon

-Original Message- From: Uwe Ligges
Sent: Sunday, December 15, 2013 12:30 PM
To: John Karon ; r-help@r-project.org
Subject: Re: [R] Invalid connection error message when trying to write a
file



On 15.12.2013 20:13, John Karon wrote:

The response below asks what I actually did.

I defined a function (details omitted; it computes the data frame
LRtest.out); arguments include "path\\filename.csv" to which I want to
write a data frame using write.csv(  ).  Repeated executions of the
function (without the file(  ) and close(  ) instructions) were
successful until 2 days ago, when I received the error message below.  I
simplified the code to write a file and received the error message below
(same message as before) in response to the commands

zz<-file(description="c:\\LRtest.txt","w")
write.table(LRtest.out, file="c:\\LRtest.txt", sep="\t")
close(zz)


Wrong, *either* use

write.table(LRtest.out, file="c:\\LRtest.txt", sep="\t")

or

zz <- file(description="c:\\LRtest.txt","w")
write.table(LRtest.out, file=zz, sep="\t")
close(zz)

Best,
Uwe Ligges









Error in file(description = "c:\\LRtest.txt", "w") :
  cannot open the connection
In addition: Warning message:
In file(description = "c:\\LRtest.txt", "w") :
  cannot open file 'c:\LRtest.txt': Permission denied

This happens whether there is no previous file with that name or an
essentially empty file with that name.  In previous executions of code
with a path to a folder, executing the file(  )  command would create an
empty file.  Now no empty file is created.  The problem persists after
rebooting the computer.

I also tried writing to the clipboard (description ="clipboard" in the
file(  ) command); that was unsuccessful, with file="clipboard" or no
file statement in the write.table(  ) command (Word showed there was
something to paste, but pasting into an empty Word document did not put
text into the document; with no file statement, the data frame was
written to the console).

I question whether there is a setting that forbids writing to a file.
Information on putting the data frame on the clipboard would also help.
Thanks for any help.  John Karon

-Original Message- From: Uwe Ligges
Sent: Saturday, December 14, 2013 10:05 AM
To: J Karon ; r-help@r-project.org
Subject: Re: [R] Invalid connection error message when trying to write a
file



On 13.12.2013 20:11, J Karon wrote:

I get an invalid connection method error message when trying to write
an R
object from a user-defined function to my hard drive (running Windows 7)
using write.csv.  I have previously not had this problem with the same
user-defined function.  The error message is

Error in isOpen(file, "w") : invalid connection
In addition: Warning message:
In if (file == "") file <- stdout() else if (is.character(file)) { :
   the condition has length > 1 and only the first element will be used

Using
zz<-file(description="path","w")
write.csv(  )
close(zz)

creates an empty file but yields the same error message when I execute
write.csv.



Please tell us what you actually did.

This works for me:

zz <- file(description="path", "w")
write.csv(iris, zz)
close(zz)

Best,
Uwe Ligges

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/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] Invalid connection error message when trying to write a file

2013-12-16 Thread John Karon
Thanks for pointing out my error after specifying the destination in the 
file(  ) function.  What you proposed also did not work.
It turns out the solution is to give the file name but not include the path; 
the resulting file is written in the working directory.

The mystery is that including the path had previously work.
John Karon

-Original Message- 
From: Uwe Ligges

Sent: Sunday, December 15, 2013 12:30 PM
To: John Karon ; r-help@r-project.org
Subject: Re: [R] Invalid connection error message when trying to write a 
file




On 15.12.2013 20:13, John Karon wrote:

The response below asks what I actually did.

I defined a function (details omitted; it computes the data frame
LRtest.out); arguments include "path\\filename.csv" to which I want to
write a data frame using write.csv(  ).  Repeated executions of the
function (without the file(  ) and close(  ) instructions) were
successful until 2 days ago, when I received the error message below.  I
simplified the code to write a file and received the error message below
(same message as before) in response to the commands

zz<-file(description="c:\\LRtest.txt","w")
write.table(LRtest.out, file="c:\\LRtest.txt", sep="\t")
close(zz)


Wrong, *either* use

write.table(LRtest.out, file="c:\\LRtest.txt", sep="\t")

or

zz <- file(description="c:\\LRtest.txt","w")
write.table(LRtest.out, file=zz, sep="\t")
close(zz)

Best,
Uwe Ligges









Error in file(description = "c:\\LRtest.txt", "w") :
  cannot open the connection
In addition: Warning message:
In file(description = "c:\\LRtest.txt", "w") :
  cannot open file 'c:\LRtest.txt': Permission denied

This happens whether there is no previous file with that name or an
essentially empty file with that name.  In previous executions of code
with a path to a folder, executing the file(  )  command would create an
empty file.  Now no empty file is created.  The problem persists after
rebooting the computer.

I also tried writing to the clipboard (description ="clipboard" in the
file(  ) command); that was unsuccessful, with file="clipboard" or no
file statement in the write.table(  ) command (Word showed there was
something to paste, but pasting into an empty Word document did not put
text into the document; with no file statement, the data frame was
written to the console).

I question whether there is a setting that forbids writing to a file.
Information on putting the data frame on the clipboard would also help.
Thanks for any help.  John Karon

-Original Message- From: Uwe Ligges
Sent: Saturday, December 14, 2013 10:05 AM
To: J Karon ; r-help@r-project.org
Subject: Re: [R] Invalid connection error message when trying to write a
file



On 13.12.2013 20:11, J Karon wrote:

I get an invalid connection method error message when trying to write
an R
object from a user-defined function to my hard drive (running Windows 7)
using write.csv.  I have previously not had this problem with the same
user-defined function.  The error message is

Error in isOpen(file, "w") : invalid connection
In addition: Warning message:
In if (file == "") file <- stdout() else if (is.character(file)) { :
   the condition has length > 1 and only the first element will be used

Using
zz<-file(description="path","w")
write.csv(  )
close(zz)

creates an empty file but yields the same error message when I execute
write.csv.



Please tell us what you actually did.

This works for me:

zz <- file(description="path", "w")
write.csv(iris, zz)
close(zz)

Best,
Uwe Ligges

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/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 add a line in the graph?

2013-12-16 Thread David Winsemius

On Dec 15, 2013, at 4:46 AM, 水静流深 wrote:

> t<--4:4
> y<-c(5,7,10,13,15,16,14,12,11)
> plot(t,y,type="l")
> 
> how can i add a curve  y=0.83*t-0.44*t^2  in the graph?
>   [[alternative HTML version deleted]]

t<--4:4
y<-c(5,7,10,13,15,16,14,12,11)
plot(t,y,type="l", ylim=c(-4,16))

curve( 0.83*x-0.44*x^2 , add=TRUE, col="red")

-- 

David Winsemius
Alameda, CA, USA

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


Re: [R] Using assign with mapply

2013-12-16 Thread Julio Sergio Santana
Julio Sergio Santana  gmail.com> writes:

> 
> I have a data frame whose first colum contains the names of the variables 
> and whose second colum contains the values to assign to them:
> 
>: kkk <- data.frame(vars=c("var1", "var2", "var3"), 
>  vals=c(10, 20, 30), stringsAsFactors=F)
> 

For those interested in the problem this is how I solved the problem:


I want to have something similar to:
#
#   var1 <- 10
#   var2 <- 20
#   var3 <- 30

my first trial was:

   mapply(assign,  kkk$vars, kkk$vals)
## var1 var2 var3 
## 10   20   30 
#

This is, however, what I got:

   var1
## Error: object 'var1' not found

David Winsemius suggested me something similar to 


   mapply(assign,  kkk$vars, kkk$vals, MoreArgs = list(pos = 1))
# or:
   mapply(assign,  kkk$vars, kkk$vals, MoreArgs = list(envir = .GlobalEnv))

var1
## [1] 10

This almost works, but what if this construction is used inside a function?

   example <- function () {
  var1 <- 250
  kkk <- data.frame(vars=c("var1", "var2", "var3"), 
vals=c(10, 20, 30), stringsAsFactors=F)
 mapply(assign,  kkk$vars, kkk$vals, MoreArgs = list(pos = 1))
 print (var2)
 print (var1)
   }

   example()
## [1] 20
## [1] 250

var1, which was defined inside the function, isn't modified

To fix this, I defined the function as follows: 

   example <- function () {
 var1 <- 250
 kkk <- data.frame(vars=c("var1", "var2", "var3"), 
   vals=c(10, 20, 30), stringsAsFactors=F)
 mapply(assign,  kkk$vars, kkk$vals, 
MoreArgs = list(pos = sys.frame(sys.nframe(
 # sys.nframe() is the number of the frame created inside the function
 # and sys.frame() establishes it as the one assign uses to set values
 print (var2)
 print (var1)
   }

   example()
## [1] 20
## [1] 10

And the purpose is got

Thanks,

  -Sergio.

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/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] Exporting R graphics into Word without losing graph quality

2013-12-16 Thread Marc Schwartz

On Dec 16, 2013, at 8:39 AM, David Carlson  wrote:

> This will create a simple plot using Windows enhanced metafile
> format:
> 
>> win.metafile("TestFigure.emf")
>> plot(rnorm(25), rnorm(25))
>> dev.off()
> null device 
>  1 
>> 
> 
> Windows does not read pdf.


This is correct for Office on Windows, not for Office on OSX. However, if you 
share the Office document created on OSX that has a PDF embedded with Windows 
Office users, they will see a bitmapped version of the graphic, rather than the 
PDF.


> It will offer to import an eps
> (encapsulated postscript) file, but it only imports the bitmap
> thumbnail image of the figure so it is completely useless.


Regarding EPS imports, this is NOT correct.

Word and the other Office apps will import the EPS file. It cannot render the 
postscript however, thus it will **display** a bitmapped preview image.

If you print the Word document using a PS compatible printer driver, you will 
get the full high quality vector based graphic output. If you print to a non-PS 
compatible printer, the bitmapped preview is what will be printed.

You may need to install EPS import filters for Office if they were not 
installed during the initial Office installation.

That being said, while it has been years since I was on Windows, I used to use 
the WMF/EMF format to import or just copy/paste into Word, when I needed a 
document containing an R plot that could be shared with others. In most cases, 
the image quality was fine.

Regards,

Marc Schwartz


> You
> can edit a metafile in Word, but different versions seem to have
> different issues. Earlier versions would lose clipping if you
> tried to edit the file, but World 2013 works reasonably well.
> Text labels can jump if you edit the figure in Word (especially
> rotated text) although it is simple to drag them back to where
> you want them. I haven't tried 2010 or 2007 recently.
> 
> -
> David L Carlson
> Department of Anthropology
> Texas A&M University
> College Station, TX 77840-4352
> 
> 
> 
> 
> -Original Message-
> From: r-help-boun...@r-project.org
> [mailto:r-help-boun...@r-project.org] On Behalf Of Duncan
> Murdoch
> Sent: Sunday, December 15, 2013 5:24 PM
> To: david hamer; r-help@r-project.org
> Subject: Re: [R] Exporting R graphics into Word without losing
> graph quality
> 
> On 13-12-15 6:00 PM, david hamer wrote:
>> Hello,
>> 
>> My x-y scatterplot produces a very ragged best-fit line when
> imported into
>> Word.
> 
> Don't use a bitmap format (png).
> 
> Don't produce your graph in one format (screen display), then
> convert to 
> another (png).  Open the device in the format you want for the
> final file.
> 
> Use a vector format for output.  I don't know what kinds Word
> supports, 
> but EPS or PDF would likely be best; if it can't read those,
> then 
> Windows metafile (via windows() to open the device) would be
> best. 
> (Don't trust the preview to tell you the quality of the graph,
> try 
> printing the document.  Word isn't quite as bad as it appears.)
> 
> Don't use Word.
> 
> Duncan Murdoch
> 
>> 
>> 
>> 
>> * >plot (data.file$x, data.file$y, type = "p", las=1, pch=20,
> ylab =
>> expression("Cover of Species y" ~ (m^{2}~ha^{-1} )),
> xlab =
>> expression("Cover of Species x" ~ (m^{2}~ha^{-1}))  )
>> lines  (
>> data.file$x,   fitted ( model.x )  )*
>> 
>>  A suggestion from the internet is to use .png at high (1200)
> resolution.
>>* >dev.print  ( device = png,  file = "R.graph.png",
> width = 1200,
>> height = 700)*
>> This gives a high-quality graph, but the titles and tick-mark
> labels become
>> very tiny when exported into Word.
>> 
>> I therefore increased the size of the titles and tick-mark
> labels with cex.
>>* >plot (..cex =1.8, cex.lab = 1.8, cex.axis =
> 1.25,)*
>> But this causes the x-axis title to lie on top of the
> tick-mark labels.
>> (This problem does not occur with the y-axis, where the title
> lies well
>> away from the y-axis tick-mark labels.)
>> Changing margins * >par ( mai = c ( 1.3, 1.35, 1, .75 ) )*
> does not
>> seem to have any effect on this.
>> 
>> A suggestion from the internet is to delete the titles from
> plot, and use
>> mtext with line=4 to drop the title lower on the graph.
>> 
>> * >plot (...  ylab = " ", xlab = " ".)>mtext(side
> = 1, "Cover
>> of Species x (superscripts??)", line = 4)*
>> This works, but with mtext I have now lost the ability to have
> the
>> superscripts in the axis title.
>> 
>> And I am back full circle, having to lower the resolution of
> the graph to
>> keep the x-axis title away from the axis, and thus reverting
> to a ragged,
>> segmented "line" when exported to Word..
>> 
>> Final note:  The R graphics window version of the graph
> becomes very
>> distorted, even though the graph may be of high quality (other
> than the
>> problem of the x-axis title overlaying the x-axis tick-mark
> labels) once in
>> Word.  I guess this is because of

[R] Power calculations for Wilcox.test

2013-12-16 Thread Collin Lynch
Greetings, I'm working on some analyses where I need to calculate wilcox
tests for paired samples.  In my current literature search I've found a
few papers on sample size determination for the wilcox test notably:

Sample Size Determination for Some Common Nonparametric Tests
Gottfried E. Noether
Journal of the American Statistical Association

http://www.jstor.org.pitt.idm.oclc.org/stable/2289477

My question is: are there any implementations of power calculations for
the wilcox test in R based either on Noether's methods for sample size or
another method?

Thanks,
Collin.

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/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] history ?? 2 no readline ?

2013-12-16 Thread Christian Hoffmann

Hi,

What could the cause of


history()

Error in savehistory(file) : no history available to save

savehistory(file="myhist")

Error in savehistory(file) : no history available to save

save.image()


be?

I have the information in the attached gif

Cheers   Christian
--
Christian W. Hoffmann,
CH - 8915 Hausen am Albis, Switzerland
Rigiblickstrasse 15 b, Tel.+41-44-7640853
c-w.hoffm...@sunrise.ch,
christ...@echoffmann.ch,
www.echoffmann.ch

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


[R] error with as.factor raster

2013-12-16 Thread Lauria, Valentina
Dear List members,

I am trying to map the habitat suitability of Nephrops and one of my predictor 
is a categorical variable.

However when I utilised the command "as.factor" (before to create my rasters 
stack) I get the error message "Error in 1:ncol(r) : argument of length 0".

Could anyone help me?

> r4 <- 
> raster("C:/POSTDOC/NEPHROPS_Habitat_Mapping/NEPHROPS_HabMod_PAPER1/Scotland/IN_eunis_sed.tif")
> plot(r4)
> is.factor(r4)
[1] TRUE
> as.factor(r4)
class   : RasterLayer
dimensions  : 250, 413, 103250  (nrow, ncol, ncell)
resolution  : 0.01484784, 0.01484784  (x, y)
extent  : -7.774709, -1.642552, 54.95371, 58.66567  (xmin, xmax, ymin, ymax)
coord. ref. : +proj=longlat +datum=WGS84 +no_defs +ellps=WGS84 +towgs84=0,0,0
data source : 
C:\POSTDOC\NEPHROPS_Habitat_Mapping\NEPHROPS_HabMod_PAPER1\Scotland\IN_eunis_sed.tif
names   : IN_eunis_sed
values  : 1, 6  (min, max)
attributes  :
Error in 1:ncol(r) : argument of length 0
> levels(r4)
[[1]]
  IDOBJECTID Value Count sediment
  0   1   1 2716R
   1   2   2 2249   CS
   2   3   3 2647   MS
   3   4  4 6819M
   45 5  889  MXS
   56 6 3647S


Thank you very much in advance.
Best Regards,
Valentina



[[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] error with as.factor raster

2013-12-16 Thread Prof Brian Ripley

On 16/12/2013 15:14, Lauria, Valentina wrote:

Dear List members,

I am trying to map the habitat suitability of Nephrops and one of my predictor 
is a categorical variable.

However when I utilised the command "as.factor" (before to create my rasters stack) I get 
the error message "Error in 1:ncol(r) : argument of length 0".

Could anyone help me?


Yes.  This is a bug in package raster.  So please follow the posting 
guide and report to the maintainer, with the 'at a minimum' information 
missing here (a crucial part being the version of raster).


Using 1:ncol() is bad practice (seq_len is designed for that purpose), 
but the raster maintainer misuses it ca 100x.





r4 <- 
raster("C:/POSTDOC/NEPHROPS_Habitat_Mapping/NEPHROPS_HabMod_PAPER1/Scotland/IN_eunis_sed.tif")
plot(r4)
is.factor(r4)

[1] TRUE

as.factor(r4)

class   : RasterLayer
dimensions  : 250, 413, 103250  (nrow, ncol, ncell)
resolution  : 0.01484784, 0.01484784  (x, y)
extent  : -7.774709, -1.642552, 54.95371, 58.66567  (xmin, xmax, ymin, ymax)
coord. ref. : +proj=longlat +datum=WGS84 +no_defs +ellps=WGS84 +towgs84=0,0,0
data source : 
C:\POSTDOC\NEPHROPS_Habitat_Mapping\NEPHROPS_HabMod_PAPER1\Scotland\IN_eunis_sed.tif
names   : IN_eunis_sed
values  : 1, 6  (min, max)
attributes  :
Error in 1:ncol(r) : argument of length 0

levels(r4)

[[1]]
   IDOBJECTID Value Count sediment
   0   1   1 2716R
1   2   2 2249   CS
2   3   3 2647   MS
3   4  4 6819M
45 5  889  MXS
56 6 3647S


Thank you very much in advance.
Best Regards,
Valentina



[[alternative HTML version deleted]]

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




--
Brian D. Ripley,  rip...@stats.ox.ac.uk
Professor of Applied Statistics,  http://www.stats.ox.ac.uk/~ripley/
University of Oxford, Tel:  +44 1865 272861 (self)
1 South Parks Road, +44 1865 272866 (PA)
Oxford OX1 3TG, UKFax:  +44 1865 272595

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


[R] Assigning default function arguments to themselves: Why?

2013-12-16 Thread Andrew Hoerner
Let us suppose that we have a function foo(X) which is called inside
another function, bar(). Suppose, moreover, that the name "X" has been
assigned a value when foo is called.

I have noticed that many functions contain arguments with defaults of
the form X=X. Call this reflexive assignment. How is foo(X=X)
different from foo(X)? Isn't the environment from which X is located
the parent environment of foo() in either case? Or if it looks first
in the environment of foo, will it not immediately pop up to the
parent frame if it is not found in foo? Are reflexive assignments just
to keep X from being positionaly assigned accidentally, or are They
doing something deeper?

A question which is (I think) related: Is it good or bad practice,
when defining a function inside another function, to use the name of a
variable from the calling function as the argument of the called
function?

[[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] Assigning default function arguments to themselves: Why?

2013-12-16 Thread William Dunlap
> I have noticed that many functions contain arguments with defaults of
> the form X=X.

Can you show us one (one that 'works')?

Bill Dunlap
Spotfire, TIBCO Software
wdunlap tibco.com

> -Original Message-
> From: r-help-boun...@r-project.org [mailto:r-help-boun...@r-project.org] On 
> Behalf
> Of Andrew Hoerner
> Sent: Monday, December 16, 2013 9:31 AM
> To: r-help@r-project.org
> Subject: [R] Assigning default function arguments to themselves: Why?
> 
> Let us suppose that we have a function foo(X) which is called inside
> another function, bar(). Suppose, moreover, that the name "X" has been
> assigned a value when foo is called.
> 
> I have noticed that many functions contain arguments with defaults of
> the form X=X. Call this reflexive assignment. How is foo(X=X)
> different from foo(X)? Isn't the environment from which X is located
> the parent environment of foo() in either case? Or if it looks first
> in the environment of foo, will it not immediately pop up to the
> parent frame if it is not found in foo? Are reflexive assignments just
> to keep X from being positionaly assigned accidentally, or are They
> doing something deeper?
> 
> A question which is (I think) related: Is it good or bad practice,
> when defining a function inside another function, to use the name of a
> variable from the calling function as the argument of the called
> function?
> 
>   [[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] 3-D interpretation

2013-12-16 Thread Shane Carey
Hey,

I have had another idea since. Is it possible to join these points together
(by lines) and then created a polygon from them?

Thanks


On Wed, Dec 11, 2013 at 10:43 PM, Shane Carey  wrote:

> Hey,
>
> Thanks for this. I think I need some way of transposing the data onto a
> horizontal plane and then running the interpolation. Would this work maybe?
> I really dont know at this stage.
> Thanks for your help
>
>
> On Wednesday, December 11, 2013, Ben Bolker wrote:
>
>>
>> I got a little bit farther.  The results are still very ugly, jagged
>> for linear interpolation and with a huge range of values for cubic
>> spline extrapolation.  I still don't know about the crash (can't
>> reproduce it), but don't know how you expect to be able to extrapolate a
>> sensible 3-D surface from points measured along a single narrow 1-D
>> curve in the X-Y plane ...  Can you propose *any* software tool/method
>> that can do a reasonable job of this?
>>
>> source("akimatmp2.R")  ## BMB: contents from your data dump below,
>>## assigned to "dat2"
>> dat <- dat2
>> nrow(dat)  ## 1500
>>
>> ## BMB: this makes things a little prettier, but just cosmetic
>> dat <- transform(dat,X=X-min(X),Y=Y-min(Y))
>> library(rgl)
>> library(akima)
>> rgl.spheres(dat$X,dat$Z , dat$Y,1,color="red")
>> rgl.bbox()
>> # bivariate linear interpolation
>> # interp:
>>
>> akima.li <- interp(dat$X, dat$Y, dat$Z,
>>xo=seq(min(dat$X), max(dat$X), length = 100),
>>yo=seq(min(dat$Y), max(dat$Y), length = 100),
>>duplicate="mean")
>> # interp surface:
>>
>> ## BMB: this worked for me once I specified *lowercase* (x,y,z)
>> ## rather than *uppercase* (X,Y,Z) elements.
>>
>> with(akima.li,rgl.surface(x,y,z,color="green",alpha=c(0.5)))
>>
>> akima.ci0 <- interp(dat$X, dat$Y, dat$Z,
>>xo=seq(min(dat$X), max(dat$X), length = 100),
>>yo=seq(min(dat$Y), max(dat$Y), length = 100),
>>linear=FALSE,
>>duplicate="mean")
>> akima.ci0$z[!is.finite(akima.ci0$z)] <- NA
>> with(akima.ci0,image(x,y,z))
>> range(na.omit(c(akima.ci0$z)))  ## c() to treat as vector
>> ## -25 to 101000
>> range(dat$Z)  ## 3500 to 4400
>> summary(na.omit(c(akima.ci0$z)))
>> points(dat$X,dat$Y)
>>
>> rgl.close()
>> rgl.spheres(dat$X,dat$Z , dat$Y,1,color="red")
>> rgl.bbox()
>> with(akima.ci0,rgl.surface(x,y,z,color="green",alpha=c(0.5)))
>>
>>
>> # bivariate cubic spline interpolation
>> # interp:
>> akima.si <- interp(dat$X, dat$Y, dat$Z,
>>xo=seq(min(dat$X), max(dat$X), length = 100),
>>yo=seq(min(dat$Y), max(dat$Y), length = 100),
>>linear = FALSE, extrap = TRUE,
>>duplicate="mean")
>> with(akima.si,rgl.surface(x,y,z,color="blue",alpha=c(0.5)))
>> with(akima.si,image(x,y,z))
>> filled.contour(akima.si$x,akima.si$y,akima.si$z)
>>
>>
>> On 13-12-11 11:44 AM, Shane Carey wrote:
>> > I want it as one block, if you know what I mean. Like the akima example.
>> >
>> > Thanks
>> >
>> >
>> > On Wed, Dec 11, 2013 at 4:41 PM, Shane Carey 
>> wrote:
>> >
>> >> Ok, here is the first 1500 points, but Im giving up hope on it to be
>> >> honest.
>> >> It seems to be going crazy, creating triangles everywhere. Do the
>> points
>> >> need to be evenly spaced?
>> >> Thanks for your help.
>> >>
>> >> structure(list(X = c(9816966.951, 9816963.08, 9816947.516, 9816939.51,
>> >> 9816924.005, 9816916.096, 9816901.984, 9816896.967, 9816892.928,
>> >> 9816890.743, 9816886.427, 9816884.006, 9816879.185, 9816876.468,
>> >> 9816871.027, 9816868.276, 9816863.404, 9816860.712, 9816855.409,
>> >> 9816852.487, 9816846.77, 9816843.635, 9816837.53, 9816834.196,
>> >> 9816827.733, 9816824.214, 9816817.419, 9816811.926, 9816797.531,
>> >> 9816789.588, 9816774.134, 9816765.716, 9816749.492, 9816740.717,
>> >> 9816723.946, 9816714.931, 9816697.836, 9816675.781, 9816606.59,
>> >> 9816578.983, 9816544.487, 9816531.179, 9816514.376, 9816505.891,
>> >> 9816489.52, 9816481.288, 9816465.377, 9816457.374, 9816441.836,
>> >> 9816434.026, 9816418.807, 9816411.161, 9816396.205, 9816385.052,
>> >> 9816355.719, 9816341.037, 9816312.075, 9816304.796, 9816304.784,
>> >> 9816916.962, 9816917.365, 9816918.982, 9816919.414, 9816919.519,
>> >> 9816919.545, 9816599.694, 9816615.198, 9816677.27, 9816697.31,
>> >> 9816714.671, 9816723.431, 9816740.464, 9816748.995, 9816765.474,
>> >> 9816773.661, 9816789.36, 9816797.089, 9816811.764, 9816817.212,
>> >> 9816824.113, 9816827.536, 9816834.1, 9816837.345, 9816843.545,
>> >> 9816846.596, 9816852.404, 9816855.248, 9816860.635, 9816863.257,
>> >> 9816868.198, 9816870.861, 9816876.39, 9816879.039, 9816883.937,
>> >> 9816886.296, 9816890.68, 9816892.809, 9816896.829, 9816901.555,
>> >> 9816915.878, 9816921.977, 9816931.382, 9816933.721, 9816619.581,
>> >> 9816631.77, 9816680.572, 9816697.262, 9816714.648, 9816723.385,
>> >> 9816740.441, 9816748.95, 9816765.452, 9816773.618, 98167

Re: [R] Power calculations for Wilcox.test

2013-12-16 Thread David Winsemius

On Dec 16, 2013, at 8:27 AM, Collin Lynch wrote:

> Greetings, I'm working on some analyses where I need to calculate wilcox
> tests for paired samples.  In my current literature search I've found a
> few papers on sample size determination for the wilcox test notably:
> 
> Sample Size Determination for Some Common Nonparametric Tests
> Gottfried E. Noether
> Journal of the American Statistical Association
> 
> http://www.jstor.org.pitt.idm.oclc.org/stable/2289477
> 
> My question is: are there any implementations of power calculations for
> the wilcox test in R based either on Noether's methods for sample size or
> another method?
> 

You've offered a citation that is perhaps only accessible from computers within 
your own institution: at any rate it's not accessible to this non-academic 
viewer. Doing a tiny bit of searching shows it to be found on an alternate 
website:

www.stat.purdue.edu/~jennings/stat582/notes/docs3-9-10/noether.pdf‎

Paired tests are really one-sample tests against a location parameter of 0.

The equations presented in that article are fairly simple. It should be easy to 
implement with basic R programming methods.

These days statisticians would approach the problem by setting up a simulation. 
It allows investiagation of more complex analysis strategies.

To look for pre-canned approaches.
To search R functions, the sos package is useful:

library(sos)

 findFn("power nonparametric")

findFn("sample size power wilcox")
found 25 matches;  retrieving 2 pages
2 
Downloaded 12 links in 10 packages.

I'm not sure why ciNparN {EnvStats} didn't show up in that set of links since 
the title of the help page is "Sample Size for Nonparametric Confidence 
Interval for a Quantile". That should be able to estimate a sample size for a 
specified width of CI for the median. That's a precision oriented determination 
which I suspect should be the same as a method that were based on sampling 
properties of a distribution, since you are working with ranks.

-- 

David Winsemius
Alameda, CA, USA

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


Re: [R] extracting non-NA entries from a two-way frequency table

2013-12-16 Thread rmailbox
Sorry about omitting library(plyr).
It's really thanks to Hadley, of course. His contributions make us all (capable 
of being) better.
Eric


- Original message -
From: Michael Friendly 
To: rmail...@justemail.net, r-help@r-project.org
Subject: Re: extracting non-NA entries from a two-way frequency table
Date: Sat, 14 Dec 2013 17:50:00 -0500

Very elegant! Thank you Eric.

(You omitted library(plyr), so I had to search for arrange())

-Michael

On 12/13/2013 3:01 PM, rmail...@justemail.net wrote:
> Perhaps this?
>
> library(reshape2)
> library(stringr)
>
> GeisslerLong <- melt (Geissler, id.vars = c("boys"))
> GeisslerLong <- transform ( GeisslerLong, girls = as.numeric ( str_replace( 
> variable, "g", '' )) )
> GeisslerLong <- rename ( GeisslerLong, c( value = "Freq"))
> GeisslerLong <- arrange ( GeisslerLong, boys, girls)
> GeisslerLong <- subset ( GeisslerLong, !is.na ( Freq), select = c( boys, 
> girls, Freq))
>
>
> Eric
>
>
> - Original message -
> From: Michael Friendly 
> To: "R-help" 
> Subject: [R] extracting non-NA entries from a two-way frequency table
> Date: Fri, 13 Dec 2013 14:41:58 -0500
>
> I have data in the form of a two-way table recording the number of
> families with varying numbers
> of boys (rows) and girls (columns: g0 -- g12) below, also given in
> dput() format.
>
> I want to convert this to a data frame containing only the non-NA
> entries, with columns
> boys, girls, Freq, where Freq is the table entry.  Can anyone help with
> this?
> I suppose that the steps are to transpose each row to a column
> identifying the number of
> girls, and then delete the NAs, but I can't quite see how to do this.
>
>
>   > Geissler
>  boys g0 g1g2g3g4   g5   g6   g7  g8 g9 g10 g11 g12
> 112  7 NANANANA   NA   NA   NA  NA NA  NA  NA  NA
> 211 24 45NANANA   NA   NA   NA  NA NA  NA  NA  NA
> 310 30 93   181NANA   NA   NA   NA  NA NA  NA  NA  NA
> 4 9 90287   492   478NA   NA   NA   NA  NA NA  NA  NA  NA
> 5 8264713  1027  1077   829   NA   NA   NA  NA NA  NA  NA  NA
> 6 7631   1655  2418  2309  1801 1112   NA   NA  NA NA  NA  NA  NA
> 7 6   1579   3725  4948  4757  3470 2310 1343   NA  NA NA  NA  NA  NA
> 8 5   3666   7908  9547  8498  6436 3878 2161 1033  NA NA  NA  NA  NA
> 9 4   8628  16340 17332 14479 10263 5917 3072 1540 670 NA  NA  NA  NA
> 103  20540  31611 30175 1 13972 7603 3895 1783 837 286  NA  NA  NA
> 112  47819  57179 44793 28630 15700 8171 3951 1776 722 275 104  NA  NA
> 121 114609  89213 53789 28101 13740 6233 2719 1152 432 151  72  24  NA
> 130 NA 108719 42860 17395  7004 2839 1096  436 161 66  30   8   3
>
> Geissler <-
> structure(list(boys = c(12L, 11L, 10L, 9L, 8L, 7L, 6L, 5L, 4L,
> 3L, 2L, 1L, 0L), g0 = c(7L, 24L, 30L, 90L, 264L, 631L, 1579L,
> 3666L, 8628L, 20540L, 47819L, 114609L, NA), g1 = c(NA, 45L, 93L,
> 287L, 713L, 1655L, 3725L, 7908L, 16340L, 31611L, 57179L, 89213L,
> 108719L), g2 = c(NA, NA, 181L, 492L, 1027L, 2418L, 4948L, 9547L,
> 17332L, 30175L, 44793L, 53789L, 42860L), g3 = c(NA, NA, NA, 478L,
> 1077L, 2309L, 4757L, 8498L, 14479L, 1L, 28630L, 28101L, 17395L
> ), g4 = c(NA, NA, NA, NA, 829L, 1801L, 3470L, 6436L, 10263L,
> 13972L, 15700L, 13740L, 7004L), g5 = c(NA, NA, NA, NA, NA, 1112L,
> 2310L, 3878L, 5917L, 7603L, 8171L, 6233L, 2839L), g6 = c(NA,
> NA, NA, NA, NA, NA, 1343L, 2161L, 3072L, 3895L, 3951L, 2719L,
> 1096L), g7 = c(NA, NA, NA, NA, NA, NA, NA, 1033L, 1540L, 1783L,
> 1776L, 1152L, 436L), g8 = c(NA, NA, NA, NA, NA, NA, NA, NA, 670L,
> 837L, 722L, 432L, 161L), g9 = c(NA, NA, NA, NA, NA, NA, NA, NA,
> NA, 286L, 275L, 151L, 66L), g10 = c(NA, NA, NA, NA, NA, NA, NA,
> NA, NA, NA, 104L, 72L, 30L), g11 = c(NA, NA, NA, NA, NA, NA,
> NA, NA, NA, NA, NA, 24L, 8L), g12 = c(NA, NA, NA, NA, NA, NA,
> NA, NA, NA, NA, NA, NA, 3L)), .Names = c("boys", "g0", "g1",
> "g2", "g3", "g4", "g5", "g6", "g7", "g8", "g9", "g10", "g11",
> "g12"), class = "data.frame", row.names = c(NA, -13L))
>
>


-- 
Michael Friendly Email: friendly AT yorku DOT ca
Professor, Psychology Dept. & Chair, Quantitative Methods
York University  Voice: 416 736-2100 x66249 Fax: 416 736-5814
4700 Keele StreetWeb:   http://www.datavis.ca
Toronto, ONT  M3J 1P3 CANADA

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

2013-12-16 Thread yuanzhi
Ista Zahn wrote
> This is the R-help mailing list. If your problem persists when using R
> from the command line or with the GUI shipped with R on your
> (unspecified) platform post back here. Otherwise the RStudio support
> forum is at https://support.rstudio.com
> 
> Best,
> Ista
> 
> On Sat, Dec 14, 2013 at 12:22 AM, yuanzhi <

> yuanzhi.li@

> > wrote:
>> Hello, I met a problem which needs your help. I reinstalled the R and
>> Rstudio
>> recently. After that, I found there was a problem that the Chinese
>> character
>> was garbled in Rstudio sometimes.
>>
>> example 1
>> "richness.csv" is a file containing three columns and the names of the
>> three
>> columns are "处理水平",“组别”,"物种数"。 But when I read this file with function
>> "read.csv" and displayed, these Chinese characters are garbled like the
>> followings:
>>> x<-read.csv("richness.csv")
>>> x[1:5,]
>>   X..理?? X.?? 物种数
>> 1CK总 34
>> 2CK总 43
>> 3CK总 45
>> 4CK总 41
>> 5CK总 33
>>
>> example2
>>
>> Sometimes the prompting message also contains garabled Chinese
>> characters.
>> For example, when I run "?bargraph.CI"(which is a function in package
>> "sciplot") before I use the cammand "library(sciplot)", it will appear
>> the
>> following message with garbled Chinese characters:
>>> ?bargraph.CI
>> No documentation for 慴argraph.CI?in specified packages and libraries:
>> you could try ??bargraph.CI?
>>
>> So, what can I do to solve the problem. Thank you!
>> Yuanzhi
>>
>>
>>
>> --
>> View this message in context:
>> http://r.789695.n4.nabble.com/Chinese-Garbled-tp4682184.html
>> Sent from the R help mailing list archive at Nabble.com.
>>
>> __
>> 

> R-help@

>  mailing list
>> https://stat.ethz.ch/mailman/listinfo/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@

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

Hi, I am sorry to reply so late. Actually, When I run these codes directly
in R(not Rstudio), it also appears the problem but in a different type:

> x<-read.csv("richness.csv")
> x[1:5,]
  X..ÀíË.Æ. X.é.ð ÎïÖÖÊý
1CK×Ü 34
2CK×Ü 43
3CK×Ü 45
4CK×Ü 41
5CK×Ü 33

So, what should I do solve this problem?




--
View this message in context: 
http://r.789695.n4.nabble.com/Chinese-Garbled-tp4682184p4682302.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] Chinese Garbled

2013-12-16 Thread William Dunlap
>> columns are "处理水平",“组别”,"物种数"。 But when I read this file with function
>> "read.csv" and displayed, these Chinese characters are garbled like the
>> followings:
>>> x<-read.csv("richness.csv")
>>> x[1:5,]
>>   X..理?? X.?? 物种数
>> 1CK总 34

You have to, at least, use the check.names=FALSE argument to read.csv.

E.g.,
  > str(read.csv(text="%*,&*,$\n1,2,4\n2,3,5"))
  'data.frame':   2 obs. of  3 variables:
   $ X..  : int  1 2
   $ X...1: int  2 3
   $ X.   : int  4 5
  > str(read.csv(text="%*,&*,$\n1,2,4\n2,3,5", check.names=FALSE))
  'data.frame':   2 obs. of  3 variables:
   $ %*: int  1 2
   $ &*: int  2 3
   $ $ : int  4 5

There may be more you have to do.

Bill Dunlap
Spotfire, TIBCO Software
wdunlap tibco.com


> -Original Message-
> From: r-help-boun...@r-project.org [mailto:r-help-boun...@r-project.org] On 
> Behalf
> Of yuanzhi
> Sent: Monday, December 16, 2013 2:08 PM
> To: r-help@r-project.org
> Subject: Re: [R] Chinese Garbled
> 
> Ista Zahn wrote
> > This is the R-help mailing list. If your problem persists when using R
> > from the command line or with the GUI shipped with R on your
> > (unspecified) platform post back here. Otherwise the RStudio support
> > forum is at https://support.rstudio.com
> >
> > Best,
> > Ista
> >
> > On Sat, Dec 14, 2013 at 12:22 AM, yuanzhi <
> 
> > yuanzhi.li@
> 
> > > wrote:
> >> Hello, I met a problem which needs your help. I reinstalled the R and
> >> Rstudio
> >> recently. After that, I found there was a problem that the Chinese
> >> character
> >> was garbled in Rstudio sometimes.
> >>
> >> example 1
> >> "richness.csv" is a file containing three columns and the names of the
> >> three
> >> columns are "处理水平",“组别”,"物种数"。 But when I read this file with
> function
> >> "read.csv" and displayed, these Chinese characters are garbled like the
> >> followings:
> >>> x<-read.csv("richness.csv")
> >>> x[1:5,]
> >>   X..理?? X.?? 物种数
> >> 1CK总 34
> >> 2CK总 43
> >> 3CK总 45
> >> 4CK总 41
> >> 5CK总 33
> >>
> >> example2
> >>
> >> Sometimes the prompting message also contains garabled Chinese
> >> characters.
> >> For example, when I run "?bargraph.CI"(which is a function in package
> >> "sciplot") before I use the cammand "library(sciplot)", it will appear
> >> the
> >> following message with garbled Chinese characters:
> >>> ?bargraph.CI
> >> No documentation for 慴argraph.CI?in specified packages and libraries:
> >> you could try ??bargraph.CI?
> >>
> >> So, what can I do to solve the problem. Thank you!
> >> Yuanzhi
> >>
> >>
> >>
> >> --
> >> View this message in context:
> >> http://r.789695.n4.nabble.com/Chinese-Garbled-tp4682184.html
> >> Sent from the R help mailing list archive at Nabble.com.
> >>
> >> __
> >>
> 
> > R-help@
> 
> >  mailing list
> >> https://stat.ethz.ch/mailman/listinfo/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@
> 
> >  mailing list
> > https://stat.ethz.ch/mailman/listinfo/r-help
> > PLEASE do read the posting guide
> > http://www.R-project.org/posting-guide.html
> > and provide commented, minimal, self-contained, reproducible code.
> 
> Hi, I am sorry to reply so late. Actually, When I run these codes directly
> in R(not Rstudio), it also appears the problem but in a different type:
> 
> > x<-read.csv("richness.csv")
> > x[1:5,]
>   X..ÀíË.Æ. X.é.ð ÎïÖÖÊý
> 1CK×Ü 34
> 2CK×Ü 43
> 3CK×Ü 45
> 4CK×Ü 41
> 5CK×Ü 33
> 
> So, what should I do solve this problem?
> 
> 
> 
> 
> --
> View this message in context: http://r.789695.n4.nabble.com/Chinese-Garbled-
> tp4682184p4682302.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] read ".slk" file

2013-12-16 Thread Santosh
Dear Rxperts..

I recently received a data file with the extension ".slk". If I save the
file as MS Excel file, I am able to read in R without issues.  Is it
possible to read this ".slk" file without converting into another
R-readable data format?

Regards,
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] Invalid connection error message when trying to write a file

2013-12-16 Thread J Karon
Indeed, I presume something changed.  I would get an error message with the 
file(description=.) command.  The mystery is that everything worked fine 
before.  Thanks for your comments.  john karon

From: Uwe Ligges-3 [via R] 
Sent: Monday, December 16, 2013 8:44 AM
To: J Karon 
Subject: Re: Invalid connection error message when trying to write a file

I guess your problem is that you cannot write toplevel into "c:\" with 
your permissions? 

Best, 
Uwe Ligges 


On 16.12.2013 16:40, John Karon wrote: 

> Thanks for pointing out my error after specifying the destination in the 
> file(  ) function.  What you proposed also did not work. 
> It turns out the solution is to give the file name but not include the 
> path; the resulting file is written in the working directory. 
> The mystery is that including the path had previously work. 
> John Karon 
> 
> -Original Message- From: Uwe Ligges 
> Sent: Sunday, December 15, 2013 12:30 PM 
> To: John Karon ; [hidden email] 
> Subject: Re: [R] Invalid connection error message when trying to write a 
> file 
> 
> 
> 
> On 15.12.2013 20:13, John Karon wrote: 
>> The response below asks what I actually did. 
>> 
>> I defined a function (details omitted; it computes the data frame 
>> LRtest.out); arguments include "path\\filename.csv" to which I want to 
>> write a data frame using write.csv(  ).  Repeated executions of the 
>> function (without the file(  ) and close(  ) instructions) were 
>> successful until 2 days ago, when I received the error message below.  I 
>> simplified the code to write a file and received the error message below 
>> (same message as before) in response to the commands 
>> 
>> zz<-file(description="c:\\LRtest.txt","w") 
>> write.table(LRtest.out, file="c:\\LRtest.txt", sep="\t") 
>> close(zz) 
> 
> Wrong, *either* use 
> 
> write.table(LRtest.out, file="c:\\LRtest.txt", sep="\t") 
> 
> or 
> 
> zz <- file(description="c:\\LRtest.txt","w") 
> write.table(LRtest.out, file=zz, sep="\t") 
> close(zz) 
> 
> Best, 
> Uwe Ligges 
> 
> 
> 
> 
> 
> 
> 
>> 
>> Error in file(description = "c:\\LRtest.txt", "w") : 
>>   cannot open the connection 
>> In addition: Warning message: 
>> In file(description = "c:\\LRtest.txt", "w") : 
>>   cannot open file 'c:\LRtest.txt': Permission denied 
>> 
>> This happens whether there is no previous file with that name or an 
>> essentially empty file with that name.  In previous executions of code 
>> with a path to a folder, executing the file(  )  command would create an 
>> empty file.  Now no empty file is created.  The problem persists after 
>> rebooting the computer. 
>> 
>> I also tried writing to the clipboard (description ="clipboard" in the 
>> file(  ) command); that was unsuccessful, with file="clipboard" or no 
>> file statement in the write.table(  ) command (Word showed there was 
>> something to paste, but pasting into an empty Word document did not put 
>> text into the document; with no file statement, the data frame was 
>> written to the console). 
>> 
>> I question whether there is a setting that forbids writing to a file. 
>> Information on putting the data frame on the clipboard would also help. 
>> Thanks for any help.  John Karon 
>> 
>> -Original Message- From: Uwe Ligges 
>> Sent: Saturday, December 14, 2013 10:05 AM 
>> To: J Karon ; [hidden email] 
>> Subject: Re: [R] Invalid connection error message when trying to write a 
>> file 
>> 
>> 
>> 
>> On 13.12.2013 20:11, J Karon wrote: 
>>> I get an invalid connection method error message when trying to write 
>>> an R 
>>> object from a user-defined function to my hard drive (running Windows 7) 
>>> using write.csv.  I have previously not had this problem with the same 
>>> user-defined function.  The error message is 
>>> 
>>> Error in isOpen(file, "w") : invalid connection 
>>> In addition: Warning message: 
>>> In if (file == "") file <- stdout() else if (is.character(file)) { : 
>>>the condition has length > 1 and only the first element will be used 
>>> 
>>> Using 
>>> zz<-file(description="path","w") 
>>> write.csv(  ) 
>>> close(zz) 
>>> 
>>> creates an empty file but yields the same error message when I execute 
>>> write.csv. 
>> 
>> 
>> Please tell us what you actually did. 
>> 
>> This works for me: 
>> 
>> zz <- file(description="path", "w") 
>> write.csv(iris, zz) 
>> close(zz) 
>> 
>> Best, 
>> Uwe Ligges 
>> 
>> __ 
>> [hidden email] mailing list 
>> https://stat.ethz.ch/mailman/listinfo/r-help
>> PLEASE do read the posting guide 
>> http://www.R-project.org/posting-guide.html
>> and provide commented, minimal, self-contained, reproducible code. 
> 

__ 
[hidden email] mailing list 
https://stat.ethz.ch/mailman/listinfo/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 choose data from two sets of data to ensure that the choosed data has a better normal feature?

2013-12-16 Thread Rolf Turner

On 16/12/13 20:59, Jeff Newmiller wrote:



This is not a statistics theory forum, but posting a solution to this 
nonsensical problem would be irresponsible.


Fortune?

cheers,

Rolf

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/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] Exporting R graphics into Word without losing graph quality

2013-12-16 Thread Steve Taylor
Unfortunately the win.metafile() device does not support semi-transparent 
colours, which I like using.

In my experience, the best way to get R graphics into Word is to use compressed 
high-resolution tiff, like this:

word.tif = function(filename="Word_Figure_%03d.tif", zoom=4, width=17, 
height=10, pointsize=10, ...) {
  if (!grepl("[.]ti[f]+$", filename, ignore.case=TRUE))
  filename = paste0(filename,".tif")
  tiff(filename=filename, compression="lzw", res=96*zoom, 
   width=width, height=height, units='cm', pointsize=pointsize, ...)
}
word.tif('test')
plot(rnorm(100))
dev.off()

Now drag the file test.tif into your Word document.

Sure, it's a bitmap format rather than a vector format, but the quality is 
excellent and the file sizes are still quite small.  None of the vector formats 
works as well as this.

cheers,
Steve

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/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] Exporting R graphics into Word without losing graph quality

2013-12-16 Thread Steve Taylor
> From: Duncan Murdoch...
 
> Don't use a bitmap format (png).
I disagree.  Each vector format comes with its own problems.

> Don't produce your graph in one format (screen display), then convert to
> another (png).  Open the device in the format you want for the final file.
Agreed.
 
> Use a vector format for output.  
Why?  Sure, that's good advice in the ideal (pdflatex) world, but not 
necessarily the best of advice for Word users.

> I don't know what kinds Word supports, but
> EPS or PDF would likely be best; if it can't read those, then Windows metafile
> (via windows() to open the device) would be best.
None of these works well, if at all, in my experience with Word.

> Don't use Word.
Some of us don't really have a choice.

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/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] Exporting R graphics into Word without losing graph quality

2013-12-16 Thread david hamer
Thanks to everyone for the helpful suggestions.   --   David.


On Mon, Dec 16, 2013 at 7:23 PM, Steve Taylor wrote:

> > From: Duncan Murdoch...
>
> > Don't use a bitmap format (png).
> I disagree.  Each vector format comes with its own problems.
>
> > Don't produce your graph in one format (screen display), then convert to
> > another (png).  Open the device in the format you want for the final
> file.
> Agreed.
>
> > Use a vector format for output.
> Why?  Sure, that's good advice in the ideal (pdflatex) world, but not
> necessarily the best of advice for Word users.
>
> > I don't know what kinds Word supports, but
> > EPS or PDF would likely be best; if it can't read those, then Windows
> metafile
> > (via windows() to open the device) would be best.
> None of these works well, if at all, in my experience with Word.
>
> > Don't use Word.
> Some of us don't really have a choice.
>
>
>

[[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 choose data from two sets of data to ensure that the choosed data has a better normal feature?

2013-12-16 Thread Marino David
Anyway, thanks for all your response. These two sets of data are similar.
let's assume them are obtained from two experimental setups but at
the situation, so they are more similar but not the same because measure
error may be involved. I hope I can chose a set of data with a better
normal feature mentioned in my previous email.

Sorry about the caused misinterpretation.

Thank you!

David
2013/12/16 Rolf Turner 

> On 16/12/13 20:59, Jeff Newmiller wrote:
>
> 
>
> This is not a statistics theory forum, but posting a solution to this
>> nonsensical problem would be irresponsible.
>>
>
> Fortune?
>
> cheers,
>
> Rolf
>
>
> __
> R-help@r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/
> posting-guide.html 
> and provide commented, minimal, self-contained, reproducible code.
>

[[alternative HTML version deleted]]

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


[R] result

2013-12-16 Thread ????????
Mydata is as under.
dat="  salary   ex
+ 1   1856 1799
+ 2   1856 1800
+ 3   1858 1800
+ 4   1858 1801
+ 5   1862 1803
+ 6   1862 1805
+ 7   1862 1810
+ 8   1865 1805
+ 9   1865 1808
+ 10  1865 1815
+ 11  1865 1820
+ 12  1870 1810
+ 13  1870 1830
+ 14  1880 1840
+ 15  1880 1845
+ 16  1880 1851
+ 17  1880 1853
+ 18  1880 1855
+ 19  1885 1850
+ 20  1885 1852
+ 21  1885 1857
+ 22  1885 1860
+ 23  1898 1855
+ 24  1898 1858
+ 25  1898 1861
+ 26  1898 1863
+ 27  1898 1866
+ 28  1898 1867
+ 29  1898 1890
+ 30  1902 1850
+ 31  1902 1853
+ 32  1902 1869
+ 33  1902 1872
+ 34  1902 1873
+ 35  1915 1850
+ 36  1915 1859
+ 37  1915 1863
+ 38  1915 1868
+ 39  1915 1875
+ 40  1915 1898
+ "
 
data<-read.table(text=dat,header=TRUE)
 
I want to get the result(please see the attatchment),the header is salary,the 
rownames is ex.
I only can get the "total column"
rev(table(cut(data[,2],breaks=seq(1795,1905,10),right=F))) 

How can I get the other data  by some code,not by hand?__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/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] result

2013-12-16 Thread David Winsemius

On Dec 16, 2013, at 10:50 PM,  wrote:

> Mydata is as under.
> dat="  salary   ex
> + 1   1856 1799
> + 2   1856 1800
> + 3   1858 1800
> + 4   1858 1801
> 
snipped
> + "
> 
> data<-read.table(text=dat,header=TRUE)
> 
> I want to get the result(please see the attatchment),the header is salary,the 
> rownames is ex.
> I only can get the "total column"
> rev(table(cut(data[,2],breaks=seq(1795,1905,10),right=F))) 
> 
> How can I get the other data  by some code,not by hand?

Please do not crosspost to StackOverflow and Rhelp.
-- 


David Winsemius
Alameda, CA, USA

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


Re: [R] What is the formula of Pseudo-F statistic in capscale in vegan?

2013-12-16 Thread Kristen Ross
Dear R-help,

We are conducting a distance-based redundancy analysis using capscale and
then testing for statistical significance for six terms in the model for the
constrained ordination using anova.cca in the vegan package. The
significance test is sequential, i.e., testing for significance of a term
only after accounting for all preceding terms. Could someone please provide
us with either the actual formula for the pseudo-F statistic or a reference
that provides this formula?

We ask because we are doing the exact same analysis in another program
(using distLM in PRIMER 6 v 6.1.13 and PERMANOVA+ v 1.0.3 from PRIMER-E),
but we are getting very different pseudo-F ratios despite specifying the
exact same order of model terms, using the same Bray-Curtis distance measure
(distance matrices produced by the two programs are the same), and using the
same sequential test for significance. Below is a table displaying the order
of the model terms and the pseudo-F values computed by R and by PRIMER (we
also ran the same analysis in CANOCO which showed the same results in
pseudo-F values as PRIMER). We have not been able to figure out why we get
very different pseudo-F values, leading us to believe that R calculates
pseudo-F values differently than PRIMER for the sequential tests.
Furthermore, constrained ordination outputs, i.e., eigenvalues, proportion
of variability explained by each constrained axes, etc. appear to be
identical between the two programs.  Below we provide (1) the table showing
the different pseudo-F values; (2) the formula used by PRIMER to calculate
pseudo-F values that we think is the same being used in R, but need
confirmation; and (3) the R code used for this analysis.  

(1) Table


Model

Social Variables

PRIMER pseudo-F

R pseudo-F


SEQUENTIAL TESTS

GroupSize

1.1904

1.5528


 

Board

1.5079

1.8872


 

MtgStyle

1.1326

1.4007


 

DmStyle

1.0971

1.3437


 

DifView

1.4892

1.7299


 

VolAuton

2.2923

2.2925

 

(2) pseudo-F formula

We know that PRIMER uses the following formula to calculate the pseudo-F for
a sequential test of significance (equation 4.3, Anderson, Gorley, and
Clarke 2008, Chapter 4. Pg. 129, and based on pseudo-F equation in Legendre
and Anderson (1999), Ecological Monographs vol. 69):

 

F= (SSFull - SSReduced)/(qFull-qReduced)

(SSTotal-SSFull)/(N - qFull - 1)

 (3) R code

## creating Bray-Curtis of Biodiversity data

H.BC <- vegdist(H.Full [,14:211], "bray")

 

## Distance based redundancy analysis (dbRDA)

m1<-capscale(H.BC ~ GroupSize + Board + MtgStyle + DmStyle + DifView +
VolAuton, SScomp [,14:19], distance = "euclidean", add = TRUE)

### NOTE: pseudo-F values are the same with or without correcting for
negative eigenvalues (although they are different from other programs).

 

## Sequential test for terms

anova.cca(m1, by="terms", perm.max=1000, permu=500) 

 

Thank you very much for any help or insights that anyone can provide,

Kristen

 

Kristen A. Ross, PhD

Post Doctoral Researcher 

University of Illinois at Chicago

kristenross...@gmail.com

  and

Research Associate

Green Mountain College

One Brennan Circle

Poultney, VT 05764

 


[[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] (no subject)

2013-12-16 Thread Mahboobe Akhlaghi
hello,
I have a project in dose response and I should fit some models on my data.
how can I fit linear and quadritic models on my data?
many thanks,
mahboobe

[[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] unable to install XML package on Windows7

2013-12-16 Thread Wasili Goutas
Hi,

 I try to install the XML package, but unfortunatelly I get an erroron
uncompressing it

'Fehler in untar2(tarfile, files, list, exdir, restore_times) :
incomplete block on file'

I tried it manually using WinZip and tra in a Cygwin shell and get also errors
there.

  gzip: stdin: unexpected end of file
  tar: Unerwartetes Dateiende im Archiv.
  tar: Error is not recoverable: exiting now

I tried to extract the versions XML_3.9-0.tar.gz, XML_3.98-0.tar.gz and
XML_3.98-1.tar.gz in Cygwin and got always the same error.

To take care, that the reason is not any download problem since I sit behind a
firewall and proxy I checked if also other packages from
  behave the same, but I was able to
untar

R2GoogleMaps_0.2-0.tar.gz  RCUDA_0.4-0.tar.gz  RCurl_1.95-4.tar.gz
 RGraphicsDevice_0.5-0.tar.gz

in a Cygwin shell with ‘tar tvzf …’ without any problems.

I can't believe that the XML package basically always is broken but I also don't
understand what I'm doing wrong.

 Do you have an idea?

Regards

Wasili
[[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 choose data from two sets of data to ensure that the choosed data has a better normal feature?

2013-12-16 Thread Jeff Newmiller
Your question as posed is incomplete, because you have not specified what the 
mean and standard deviation are of the distribution that you wish to use as the 
target. Two histograms may each have an excellent fit to different 
distributions, such that neither can be faulted as a poor fit to a normal 
distribution, yet mixing the two would only make things worse. Nor does picking 
and choosing bins make sense to me even if they are from the same distribution 
(normally you pool all the data if they are from the same distribution).

This is not a statistics theory forum, but posting a solution to this 
nonsensical problem would be irresponsible.
---
Jeff NewmillerThe .   .  Go Live...
DCN:Basics: ##.#.   ##.#.  Live Go...
  Live:   OO#.. Dead: OO#..  Playing
Research Engineer (Solar/BatteriesO.O#.   #.O#.  with
/Software/Embedded Controllers)   .OO#.   .OO#.  rocks...1k
--- 
Sent from my phone. Please excuse my brevity.

Marino David  wrote:
>Hi R mailing listers:
>
>Assume that there are two sets of data  (denoted as A and B) with the
>same
>size, say 100X1. And I try to select a new set of data (100X1) that has
>a
>better normal feature  from these two sets. Better normal feature means
>that the histogram shape of the constructed set of data is more normal
>bell-shaped.  The choose rule is that the i-th element of new set is
>from
>i-th element of A or B.
>
>Any suggest is greatly appreciated.
>
>Thank you!
>
>David
>
>   [[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 fit exponential curve such as a*b^t in r?

2013-12-16 Thread Berend Hasselman

On 16-12-2013, at 08:52, 水静流深 <1248283...@qq.com> wrote:

> input <- "
>  ty
> 1  5.3
> 2  7.2
> 3  9.6
> 4 12.9
> 5 17.1
> 6 23.2" 
>dat<-read.table(textConnection(input),header=TRUE,sep="")
>t<-dat[,1]
>y<-dat[,2]   
> 
> `y=3.975*(1.341^t)` is the resule of fit,how can i use `nls` function to get 
> it?


Have you looked at ?nls.
Have you simply tried

nls(y~a*b^t,data=dat)

You can also do a linear regression  on  log(y) ~ A + B* t.
And afterwards transform to the original coefficients.

Berend

>   [[alternative HTML version deleted]]
> 

Please do not post in 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.

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/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 fit exponential curve such as a*b^t in r?

2013-12-16 Thread Jeff Newmiller
Read the examples section of

?nls

You probably need to provide a start list of values.

There are some points you should note from the Posting Guide mentioned in the 
footer of emails on this list: this is not a homework help forum, you should 
provide a reproducible example, and you should not post in HTML format.
---
Jeff NewmillerThe .   .  Go Live...
DCN:Basics: ##.#.   ##.#.  Live Go...
  Live:   OO#.. Dead: OO#..  Playing
Research Engineer (Solar/BatteriesO.O#.   #.O#.  with
/Software/Embedded Controllers)   .OO#.   .OO#.  rocks...1k
--- 
Sent from my phone. Please excuse my brevity.

"水静流深" <1248283...@qq.com> wrote:
>input <- "
>  ty
> 1  5.3
> 2  7.2
> 3  9.6
> 4 12.9
> 5 17.1
> 6 23.2" 
>dat<-read.table(textConnection(input),header=TRUE,sep="")
>t<-dat[,1]
>y<-dat[,2]   
>
>`y=3.975*(1.341^t)` is the resule of fit,how can i use `nls` function
>to get it?
>   [[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] log transforming predictor variables in a binomial GAM?

2013-12-16 Thread PETER MITCHELL
Hi all,

I am applying a Presence/absence Generalized additive model to model the 
distribution of marine algae species in R. I have found that log transforming 
the environmental variables improves the explained deviance of the model 
considerably. While log transforming is common practice in GLM, I have been 
unable to find any papers where this is performed in a GAM. Im wondering 
whether this breaks any of the rules of GAMs and is statistically acceptable?

Thanks all
Peter

[[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] Rows to Column

2013-12-16 Thread arun
Hi,
Try:
dat1 <- read.table(text="id cat val
1  A  2
1  C  4
3  B  1
5  A  2
6  A  3
6  B  5
6  C  2
8  B  5
8  D  2
9  D  3",sep="",header=TRUE,stringsAsFactors=FALSE)


library(reshape2)
 res1 <- dcast(dat1,id~cat,value.var="val",fill=0)
colnames(res1)[-1] <- paste0("cat",colnames(res1)[-1])


#or
 xtabs(val~id+cat,data=dat1)
A.K.


On Sunday, December 15, 2013 8:38 PM, marcos.takahashi 
 wrote:
Hi all,
I'm kinda new in R programming and I need some help preparing a database to
run logistic regression.

I have data in a tuple form:

*id cat val*
1   A   2
1   C   4
3   B   1
5   A   2
6   A   3
6   B   5
6   C   2
8   B   5
8   D   2
9   D   3

and would like to have it like:

*id    catA    catB    catC    catD*
1    2    0      4      0
3    0    1      0      0
5    2    0      0      0
6    3    5      2      0
8    0    5      0      2
9    0    0      0      3

Could someone help me?
I have already tried table function, but it doesn't return row and column
names.



--
View this message in context: 
http://r.789695.n4.nabble.com/Rows-to-Column-tp4682245.html
Sent from the R help mailing list archive at Nabble.com.

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


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


Re: [R] log transforming predictor variables in a binomial GAM?

2013-12-16 Thread Simon Wood


It doesn't break anything - you can transform the predictors pretty much
any way you like, and it is often sensible as a way of tackling very
uneven leverage. By transforming predictors, all you are changing in the
model is what "smooth" means. e.g. smooth w.r.t. log(x) is somewhat
different to sooth w.r.t. x.

best,
Simon

On 16/12/13 04:54, PETER MITCHELL wrote:

Hi all,

I am applying a Presence/absence Generalized additive model to model
the distribution of marine algae species in R. I have found that log
transforming the environmental variables improves the explained
deviance of the model considerably. While log transforming is common
practice in GLM, I have been unable to find any papers where this is
performed in a GAM. Im wondering whether this breaks any of the rules
of GAMs and is statistically acceptable?

Thanks all Peter

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




--
Simon Wood, Mathematical Science, University of Bath BA2 7AY UK
+44 (0)1225 386603   http://people.bath.ac.uk/sw283

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/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 there is no quarters?

2013-12-16 Thread Pancho Mulongeni
Hi,
I also would like to use quarters. I think a work around would be to just label 
each record in the dataframe by its quarter.
i.e. you add a factor called 'Quarter' with four levels (Q1 to Q4) for each row 
and you assign the level based on the month of the date.
You can easily do this with as.Date and as.character.

Pancho Mulongeni
Research Assistant
PharmAccess Foundation
1 Fouché Street
Windhoek West
Windhoek
Namibia
 
Tel:   +264 61 419 000
Fax:  +264 61 419 001/2
Mob: +264 81 4456 286

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/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 there is no quarters?

2013-12-16 Thread Dániel Kehl
Hi,

try

x <- seq(as.Date("2001/1/1"),as.Date("2010/1/1"),"3 months")

best,
daniel

Feladó: r-help-boun...@r-project.org [r-help-boun...@r-project.org] ; 
meghatalmazó: Pancho Mulongeni [p.mulong...@namibia.pharmaccess.org]
Küldve: 2013. december 16. 13:05
To: 1248283...@qq.com
Cc: r-help@r-project.org
Tárgy: Re: [R] why there is no quarters?

Hi,
I also would like to use quarters. I think a work around would be to just label 
each record in the dataframe by its quarter.
i.e. you add a factor called 'Quarter' with four levels (Q1 to Q4) for each row 
and you assign the level based on the month of the date.
You can easily do this with as.Date and as.character.

Pancho Mulongeni
Research Assistant
PharmAccess Foundation
1 Fouché Street
Windhoek West
Windhoek
Namibia

Tel:   +264 61 419 000
Fax:  +264 61 419 001/2
Mob: +264 81 4456 286

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/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] why there is no quarters?

2013-12-16 Thread Marc Schwartz

On Dec 15, 2013, at 6:11 AM, Duncan Murdoch  wrote:

> On 13-12-15 6:43 AM, 水静流深 wrote:
>> seq(as.Date("2001/1/1"),as.Date("2010/1/1"),"years")
>> seq(as.Date("2001/1/1"),as.Date("2010/1/1"),"weeks")
>> seq(as.Date("2001/1/1"),as.Date("2010/1/1"),"days")
>> 
>> why there is no
>> seq(as.Date("2001/1/1"),as.Date("2010/1/1"),"quarters")  ?
> 
> There's no need for it.  Just use months, and take every 3rd one:
>   
> x <- seq(as.Date("2001/1/1"),as.Date("2010/1/1"),"months")
> x[seq_along(x) %% 3 == 1]


Alternatively, ?cut.Date has "quarter" for the 'breaks' argument:

x <- seq(as.Date("2001/1/1"), as.Date("2010/1/1"), "months")

xq <- cut(x, breaks = "quarter")

> head(xq, 10)
 [1] 2001-01-01 2001-01-01 2001-01-01 2001-04-01 2001-04-01 2001-04-01
 [7] 2001-07-01 2001-07-01 2001-07-01 2001-10-01
37 Levels: 2001-01-01 2001-04-01 2001-07-01 2001-10-01 ... 2010-01-01


If you want to change the values to use "2001-Q2" or variants, you can do 
something like:

S <- c("01-01", "04-01", "07-01", "10-01")

xqq <- paste(substr(xq, 1, 5), "Q", match(substr(xq, 6, 10), S), sep = "") 

> head(xqq, 10)
 [1] "2001-Q1" "2001-Q1" "2001-Q1" "2001-Q2" "2001-Q2" "2001-Q2"
 [7] "2001-Q3" "2001-Q3" "2001-Q3" "2001-Q4"



See ?match, ?substr and ?paste


Regards,

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] why there is no quarters?

2013-12-16 Thread Marc Schwartz
That will only work if your starting date happens to be the first day of the 
year:

x <- seq(as.Date("2001/1/1"), as.Date("2010/1/1"), "3 months")

> head(x)
[1] "2001-01-01" "2001-04-01" "2001-07-01" "2001-10-01" "2002-01-01"
[6] "2002-04-01"


Compare that to:

x2 <- seq(as.Date("2001/2/3"), as.Date("2010/1/1"), "3 months")

> head(x2, 10)
 [1] "2001-02-03" "2001-05-03" "2001-08-03" "2001-11-03" "2002-02-03"
 [6] "2002-05-03" "2002-08-03" "2002-11-03" "2003-02-03" "2003-05-03"


The "3 months" is literally 3 months from the defined start date, not 3 months 
from the first of the year. So you are not going to get calendar quarter 
starting dates in that case.


On the other hand:

> cut(x2, breaks = "quarter")
 [1] 2001-01-01 2001-04-01 2001-07-01 2001-10-01 2002-01-01 2002-04-01
 [7] 2002-07-01 2002-10-01 2003-01-01 2003-04-01 2003-07-01 2003-10-01
[13] 2004-01-01 2004-04-01 2004-07-01 2004-10-01 2005-01-01 2005-04-01
[19] 2005-07-01 2005-10-01 2006-01-01 2006-04-01 2006-07-01 2006-10-01
[25] 2007-01-01 2007-04-01 2007-07-01 2007-10-01 2008-01-01 2008-04-01
[31] 2008-07-01 2008-10-01 2009-01-01 2009-04-01 2009-07-01 2009-10-01
36 Levels: 2001-01-01 2001-04-01 2001-07-01 2001-10-01 ... 2009-10-01


Regards,

Marc Schwartz


On Dec 16, 2013, at 6:35 AM, Dániel Kehl  wrote:

> Hi,
> 
> try
> 
> x <- seq(as.Date("2001/1/1"),as.Date("2010/1/1"),"3 months")
> 
> best,
> daniel
> 
> Feladó: r-help-boun...@r-project.org [r-help-boun...@r-project.org] ; 
> meghatalmazó: Pancho Mulongeni [p.mulong...@namibia.pharmaccess.org]
> Küldve: 2013. december 16. 13:05
> To: 1248283...@qq.com
> Cc: r-help@r-project.org
> Tárgy: Re: [R] why there is no quarters?
> 
> Hi,
> I also would like to use quarters. I think a work around would be to just 
> label each record in the dataframe by its quarter.
> i.e. you add a factor called 'Quarter' with four levels (Q1 to Q4) for each 
> row and you assign the level based on the month of the date.
> You can easily do this with as.Date and as.character.
> 
> Pancho Mulongeni
> Research Assistant
> PharmAccess Foundation
> 1 Fouché Street
> Windhoek West
> Windhoek
> Namibia
> 
> Tel:   +264 61 419 000
> Fax:  +264 61 419 001/2
> Mob: +264 81 4456 286

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/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 there is no quarters?

2013-12-16 Thread arun
Hi,
Also,

library(zoo)
format.yearqtr(x)
identical(gsub("\\-"," ",xqq),format.yearqtr(x))
#[1] TRUE
A.K.





On Monday, December 16, 2013 8:01 AM, Marc Schwartz  
wrote:

On Dec 15, 2013, at 6:11 AM, Duncan Murdoch  wrote:

> On 13-12-15 6:43 AM, 水静流深 wrote:
>> seq(as.Date("2001/1/1"),as.Date("2010/1/1"),"years")
>> seq(as.Date("2001/1/1"),as.Date("2010/1/1"),"weeks")
>> seq(as.Date("2001/1/1"),as.Date("2010/1/1"),"days")
>> 
>> why there is no
>> seq(as.Date("2001/1/1"),as.Date("2010/1/1"),"quarters")  ?
> 
> There's no need for it.  Just use months, and take every 3rd one:
>     
> x <- seq(as.Date("2001/1/1"),as.Date("2010/1/1"),"months")
> x[seq_along(x) %% 3 == 1]


Alternatively, ?cut.Date has "quarter" for the 'breaks' argument:

x <- seq(as.Date("2001/1/1"), as.Date("2010/1/1"), "months")

xq <- cut(x, breaks = "quarter")

> head(xq, 10)
[1] 2001-01-01 2001-01-01 2001-01-01 2001-04-01 2001-04-01 2001-04-01
[7] 2001-07-01 2001-07-01 2001-07-01 2001-10-01
37 Levels: 2001-01-01 2001-04-01 2001-07-01 2001-10-01 ... 2010-01-01


If you want to change the values to use "2001-Q2" or variants, you can do 
something like:

S <- c("01-01", "04-01", "07-01", "10-01")

xqq <- paste(substr(xq, 1, 5), "Q", match(substr(xq, 6, 10), S), sep = "") 

> head(xqq, 10)
[1] "2001-Q1" "2001-Q1" "2001-Q1" "2001-Q2" "2001-Q2" "2001-Q2"
[7] "2001-Q3" "2001-Q3" "2001-Q3" "2001-Q4"



See ?match, ?substr and ?paste


Regards,

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.


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

2013-12-16 Thread Earl F Glynn

水静流深 wrote:

i  have write a function to convert decimal number into binary number in R.

dectobin can get right result ,it is so long ,is there a  build-in function to 
do ?


Try the R.utils package:

> library(R.utils)

> intToBin(12)
[1] "1100"
> intToBin(255)
[1] ""
> intToBin(65535)
[1] ""
> intToBin(65536)
[1] "1"

Earl F Glynn
Principal Programmer/Analyst
Center for Health Insights • University of Missouri – Kansas City

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/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] Exporting R graphics into Word without losing graph quality

2013-12-16 Thread David Carlson
This will create a simple plot using Windows enhanced metafile
format:

> win.metafile("TestFigure.emf")
> plot(rnorm(25), rnorm(25))
> dev.off()
null device 
  1 
>

Windows does not read pdf. It will offer to import an eps
(encapsulated postscript) file, but it only imports the bitmap
thumbnail image of the figure so it is completely useless. You
can edit a metafile in Word, but different versions seem to have
different issues. Earlier versions would lose clipping if you
tried to edit the file, but World 2013 works reasonably well.
Text labels can jump if you edit the figure in Word (especially
rotated text) although it is simple to drag them back to where
you want them. I haven't tried 2010 or 2007 recently.

-
David L Carlson
Department of Anthropology
Texas A&M University
College Station, TX 77840-4352




-Original Message-
From: r-help-boun...@r-project.org
[mailto:r-help-boun...@r-project.org] On Behalf Of Duncan
Murdoch
Sent: Sunday, December 15, 2013 5:24 PM
To: david hamer; r-help@r-project.org
Subject: Re: [R] Exporting R graphics into Word without losing
graph quality

On 13-12-15 6:00 PM, david hamer wrote:
> Hello,
>
> My x-y scatterplot produces a very ragged best-fit line when
imported into
> Word.

Don't use a bitmap format (png).

Don't produce your graph in one format (screen display), then
convert to 
another (png).  Open the device in the format you want for the
final file.

Use a vector format for output.  I don't know what kinds Word
supports, 
but EPS or PDF would likely be best; if it can't read those,
then 
Windows metafile (via windows() to open the device) would be
best. 
(Don't trust the preview to tell you the quality of the graph,
try 
printing the document.  Word isn't quite as bad as it appears.)

Don't use Word.

Duncan Murdoch

>
>
>
> * >plot (data.file$x, data.file$y, type = "p", las=1, pch=20,
ylab =
> expression("Cover of Species y" ~ (m^{2}~ha^{-1} )),
xlab =
> expression("Cover of Species x" ~ (m^{2}~ha^{-1}))  )
>lines  (
> data.file$x,   fitted ( model.x )  )*
>
>   A suggestion from the internet is to use .png at high (1200)
resolution.
> * >dev.print  ( device = png,  file = "R.graph.png",
width = 1200,
> height = 700)*
> This gives a high-quality graph, but the titles and tick-mark
labels become
> very tiny when exported into Word.
>
> I therefore increased the size of the titles and tick-mark
labels with cex.
> * >plot (..cex =1.8, cex.lab = 1.8, cex.axis =
1.25,)*
> But this causes the x-axis title to lie on top of the
tick-mark labels.
> (This problem does not occur with the y-axis, where the title
lies well
> away from the y-axis tick-mark labels.)
> Changing margins * >par ( mai = c ( 1.3, 1.35, 1, .75 ) )*
does not
> seem to have any effect on this.
>
> A suggestion from the internet is to delete the titles from
plot, and use
> mtext with line=4 to drop the title lower on the graph.
>
> * >plot (...  ylab = " ", xlab = " ".)>mtext(side
= 1, "Cover
> of Species x (superscripts??)", line = 4)*
> This works, but with mtext I have now lost the ability to have
the
> superscripts in the axis title.
>
> And I am back full circle, having to lower the resolution of
the graph to
> keep the x-axis title away from the axis, and thus reverting
to a ragged,
> segmented "line" when exported to Word..
>
> Final note:  The R graphics window version of the graph
becomes very
> distorted, even though the graph may be of high quality (other
than the
> problem of the x-axis title overlaying the x-axis tick-mark
labels) once in
> Word.  I guess this is because of using "tricks" to try to get
a desired
> end-product in Word
>
> Thanks for any suggestions,
>   David.
>
>   [[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-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/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] Question

2013-12-16 Thread Rasool Asoodeh
Hello Dears.

 I have a 2 questions about Discriminant Analysis in R.

1- In "ade4" package I perform this analysis for both quantitative and
qualitative variables using "discrimin" function.
R gives me "Canonical weights/ Loadings" and "Canonical scores" but doesn't
give "*F* or *t *or *X-square *statistic" and "P-value" to determine
effective variables and doesn't give "classification matrix" and
"classification error rate".

2-  In "DiscriMiner" package, using "disqual" function, we can do
discriminant analysis for qualitative variables. It is performed for
"insurance" data but has error for other data such as "birds" (in Rmixmod
package) . The error sentense for this data is "Error in svd(Znorm) :
infinite or missing values in 'x'". Why? Should data have special
conditions? Also, this function doesn't give "*F* or *t *or *X-square
*statistic"
and "P-value" to determine effective variables for "insurance" data.

Thanks
Best Regards

[[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] Rows to Column

2013-12-16 Thread David Carlson
Also
> tbl <- xtabs(val~id+cat, dat1)
> tbl
   cat
id  A B C D
  1 2 0 4 0
  3 0 1 0 0
  5 2 0 0 0
  6 3 5 2 0
  8 0 5 0 2
  9 0 0 0 3

To get your column names
> dimnames(tbl)$cat <- paste0("cat", dimnames(tbl)$cat)
> tbl
   cat
id  catA catB catC catD
  12040
  30100
  52000
  63520
  80502

-
David L Carlson
Department of Anthropology
Texas A&M University
College Station, TX 77840-4352



-Original Message-
From: r-help-boun...@r-project.org
[mailto:r-help-boun...@r-project.org] On Behalf Of arun
Sent: Sunday, December 15, 2013 7:49 PM
To: r-help@r-project.org
Cc: marcos.takahashi
Subject: Re: [R] Rows to Column

Hi,
Try:
dat1 <- read.table(text="id cat val
1  A  2
1  C  4
3  B  1
5  A  2
6  A  3
6  B  5
6  C  2
8  B  5
8  D  2
9  D  3",sep="",header=TRUE,stringsAsFactors=FALSE)


library(reshape2)
 res1 <- dcast(dat1,id~cat,value.var="val",fill=0)
colnames(res1)[-1] <- paste0("cat",colnames(res1)[-1])


#or
 xtabs(val~id+cat,data=dat1)
A.K.


On Sunday, December 15, 2013 8:38 PM, marcos.takahashi
 wrote:
Hi all,
I'm kinda new in R programming and I need some help preparing a
database to
run logistic regression.

I have data in a tuple form:

*id cat val*
1   A   2
1   C   4
3   B   1
5   A   2
6   A   3
6   B   5
6   C   2
8   B   5
8   D   2
9   D   3

and would like to have it like:

*id    catA    catB    catC    catD*
1    2    0      4      0
3    0    1      0      0
5    2    0      0      0
6    3    5      2      0
8    0    5      0      2
9    0    0      0      3

Could someone help me?
I have already tried table function, but it doesn't return row
and column
names.



--
View this message in context:
http://r.789695.n4.nabble.com/Rows-to-Column-tp4682245.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-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/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] convergence=0 in optim and nlminb is real?

2013-12-16 Thread Adelchi Azzalini
It must be the case that this issue has already been rised before,
but I did not manage to find it in past posting. 

In some cases, optim() and nlminb() declare a successful convergence,
but the corresponding Hessian is not positive-definite.  A simplified
version of the original problem is given in the code which for
readability is placed below this text.  The example is built making use
of package 'sn', but this is only required to set-up the example: the
question is about the outcome of the optimizers. At the end of the run,
a certain point is declared to correspont to a minimum since
'convergence=0' is reported, but the eigenvalues of the (numerically
evaluated) Hessian matrix at that point are not all positive.

Any views on the cause of the problem? (i) the point does not
correspong to a real minimum, (ii) it does dive a minimum but the
Hessian matrix is wrong, (iii) the eigenvalues are not right. 
...and, in case, how to get the real solution. 


Adelchi Azzalini

#--
library(sn) # version 0.4-18
data(ais, package="sn")
attach(ais)
X <- cbind(1,Ht,Wt) 
y <- cbind(bmi, lbm)
dettach(ais)
negLogLik <- function(vdp, x, y)
{
  d <- ncol(y)
  p <- ncol(x)
  beta <- matrix(vdp[1:(d*p)], p, d)
  Omega <- matrix(0, d, d)
  Omega[lower.tri(Omega, TRUE)] <- vdp[(p*d+1):(p*d+d*(d+1)/2)]
  Omega <- Omega + t(Omega) - diag(diag(Omega), d)
  if(any(eigen(Omega)$values <= 0)) return(Inf)
  omega <- sqrt(diag(Omega))
  alpha <- vdp[(p*d+d*(d+1)/2+1):(p*d+d*(d+1)/2+d)]
  nu <- vdp[p*d+d*(d+1)/2+d+1]
  if(nu <= 0) return(Inf)
  logL <- sum(dmst(y, x %*% beta, Omega, alpha, nu, log=TRUE))
  return(-logL)
}
# run 1
vdp <-  c(44, 0, 0, -4, 0, 0, 0.05, -0.5, 35, 0.5, -20, 3.5)
opt <- optim(vdp, negLogLik, method="BFGS", hessian=TRUE, x=X, y=y)
opt$value
# [1] 625.3
opt$convergence
# [1] 0
eigen(opt$hessian)$values
# [1]  7.539e+07  1.523e+06  5.684e-02 -4.516e-01
#---
# run 2
vdp <-  c(44.17,  -0.2441,  0.303, -3.620, 0.04044, 0.8906, 
 0.0487, -0.5072, 36.33, 0.4445, -20.87, 3.5)
opt <- optim(vdp, negLogLik, method="BFGS", hessian=TRUE, x=X, y=y)
opt$value
# [1] 599.7
opt$convergence
# [1] 0
eigen(opt$hessian)$values
# [1]  1.235e+08    3.845e-02 -1.311e-03 -6.701e+02
#---
# run 3
vdp <-  c(44.17,  -0.2441,  0.303, -3.620, 0.04044, 0.8906, 
 0.0487, -0.5072, 36.33, 0.4445, -20.87, 3.5)
opt <- optim(vdp, negLogLik, method="SANN", hessian=TRUE, x=X, y=y)
opt$value
# [1] 599.8
opt$convergence
# [1] 0
eigen(opt$hessian)$values
# [1]  1.232e+08  3.225e-02 -6.681e-02 -7.513e+02
#--
# run 4
vdp <-  c(44.17,  -0.2441,  0.303, -3.620, 0.04044, 0.8906, 
 0.0487, -0.5072, 36.33, 0.4445, -20.87, 3.5)
opt <- optim(vdp, negLogLik, method="Nelder", hessian=TRUE, x=X, y=y)
opt$value
# [1] 599.7
opt$convergence
# [1] 1
#--
# run 5
vdp <-  c(44.17,  -0.2441,  0.303, -3.620, 0.04044, 0.8906, 
 0.0487, -0.5072, 36.33, 0.4445, -20.87, 3.5)
opt <- optim(vdp, negLogLik, method="CG", hessian=TRUE, x=X, y=y)
opt$value
# [1] 599.7
opt$convergence
# [1] 0
eigen(opt$hessian)$values
# [1]  1.236e+08  3.026e+06   3.801e-02 -2.348e-04 -7.344e+02

#--
# run 6
vdp <-  c(44.17,  -0.2441,  0.303, -3.620, 0.04044, 0.8906, 
 0.0487, -0.5072, 36.33, 0.4445, -20.87, 3.5)
opt <- nlminb(vdp, negLogLik, x=X, y=y)
opt$obj
# [1] 599.7
H <- optimHess(opt$par, negLogLik, x=X, y=y)
eigen(H)$values
# [1]  1.236e+08  3.041e+06 ... 4.090e-05 -7.176e+02
=
_   
platform   x86_64-unknown-linux-gnu
arch   x86_64  
os linux-gnu   
system x86_64, linux-gnu   
status 
major  3   
minor  0.2 
year   2013
month  09  
day25  
svn rev63987   
language   R   
version.string R version 3.0.2 (2013-09-25)
nickname   Frisbee Sailing

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/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 plug in characters as object names in a formula (recast from package reshape2 specifically)

2013-12-16 Thread Jun Shen
Hi everyone,

This may be very simple but I couldn't figure it out. I have this function

rsm.lm<-function(data,xvar='xCmin',yvar='yCmin') {

 #some calculation..

 recast(df, xvar~yvar, id.var=1:2, measure.var=3)
 #some other operations
}

df is a dataframe defined internally within the function with two id
variables (xCmin and yCmin) and a measure variable. recast doesn't work and
keep saying "Casting formula contains variables not found in molten data:
xvar, yvar.."

I tried

as.name(xvar)~as.name(yvar)
get(xvar)~get(yvar)
cat(xvar)~cat(yvar)
eval(cat(xvar))~eval(cat(yval))

But none of these works. It only works when I explicitly specify the
formula as

recast(df, xCmin~yCmin, id.var=1:2, measure.var=3)

Is there a workaround this issue? Thanks.

Jun

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