Re: [R] Error in setwd(dir) : cannot change working directory

2011-08-30 Thread Jeff Newmiller
Unless you have a subdirectory called "dir" below the directory returned by 
getwd(), the command you gave would be expected to fail. Perhaps you should use 
an absolute directory specification?
---
Jeff Newmiller The . . Go Live...
DCN: Basics: ##.#. ##.#. Live Go...
Live: OO#.. Dead: OO#.. Playing
Research Engineer (Solar/Batteries O.O#. #.O#. with
/Software/Embedded Controllers) .OO#. .OO#. rocks...1k
--- 
Sent from my phone. Please excuse my brevity.

Greg Lyukshin  wrote:

Hello, I got some of the R source code and not being able to Run it in
RStudio.
I get the error:

Error in setwd("dir") :
cannot change working directory


I have gone through forums but nothing seemed relevant to my issue.
What bugs me the most is the ("dir") that the error shows, is of those who
wrote the source code and not mine(it still sees the directory of their
computer, even though, I have changed all the directories).
When I write getwd(), it dispalys my "dir".
Does anyone have any ideas on what's going on here?
Thank you


-- 
Greg Lyukshin

[[alternative HTML version deleted]]

_

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


[[alternative HTML version deleted]]

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


[R] Error in setwd(dir) : cannot change working directory

2011-08-30 Thread Greg Lyukshin
Hello, I got some of the R source code and not being able to Run it in
RStudio.
I get the error:

Error in setwd("dir") :
  cannot change working directory


I have gone through forums but nothing seemed relevant to my issue.
What bugs me the most is the ("dir") that the error shows, is of  those who
wrote the source code and not mine(it still sees the directory of their
computer, even though, I have changed all the directories).
When I write getwd(), it dispalys my "dir".
Does anyone have any ideas on what's going on here?
Thank you


-- 
Greg Lyukshin

[[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] Fitting my data to a Weibull model

2011-08-30 Thread Marcio
Hi guys,
I have a data-set that fits well into a Weibull model y = a-b*exp(-c*x^d).
I want to estimate the parameters of the coefficients a, b, c and d, given x
and y.
Can you guys help me?

Just as an example, I fit the data
y <- c(1,2,3,4,10,20)
and 
x <- c(1,7,14,25,29,30)

According to this model above, and using the software CurveExpert, and I got
the estimates of a (2.95),b (2.90),c (2.82e-2) and d (2.97).

This is just a sample data but I would like to do it on R because I can loop
multiple times through all my files.
 
I would also like to fit a logistic model y = a/(1+b*exp-c*x)

Can you help  me
Thanks

--
View this message in context: 
http://r.789695.n4.nabble.com/Fitting-my-data-to-a-Weibull-model-tp3780169p3780169.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] stumped on how to reorder factors

2011-08-30 Thread David Winsemius


On Aug 30, 2011, at 10:00 PM, Markus Weisner wrote:


snipped long preamble:



 Now I have a more complicated
problem and I need help.  Assuming the following factor:


B = as.factor(c("Engine 1", "Engine 10", "Ladder 3", "Engine 3",  
"Ladder 10",

"Engine 10"))

levels(B)


I would like the factor ordered first by the proceeding unit type  
and then
ordered by the following integer.  In this case, I would like to see  
this
order:  Engine 1, Engine 3, Engine 10, Ladder 3, Ladder 10.  I have  
tried
many different ways of separating out the unit type from the number,  
but am
having trouble figuring out a good way of achieving this factor  
order.  For
such a small example, I could obviously manually change the order,  
but I am

dealing with much larger datasets with many unit types and up to 20
different numbers for each unit type.  Having an automated way of  
ordering
these units would be a huge help.  Thanks in advance for any help  
you can

provide.



library(gtools)
?mixedsort



--Markus Weisner

[[alternative HTML version deleted]]


--

David Winsemius, MD
West Hartford, CT

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


Re: [R] stumped on how to reorder factors

2011-08-30 Thread Peter Alspach
Tena koe Markus

I think you'll have to tailor a solution specific to your case.  However, the 
following might give you some ideas:

B <- as.factor(c("Engine 1", "Engine 10", "Ladder 3", "Engine 3", "Ladder 10", 
"Engine 10"))
summary(B)
 Engine 1 Engine 10  Engine 3 Ladder 10  Ladder 3 
1 2 1 1 1 

ttMat <- as.data.frame(matrix(unlist(strsplit(as.character(B), ' ')), ncol=2, 
byrow=TRUE))
ttMat <- ttMat[order(ttMat[,1], as.numeric(as.character(ttMat[,2]))),]
B <- factor(B, levels=unique(apply(ttMat, 1, paste, collapse=' ')))
summary(B)
 Engine 1  Engine 3 Engine 10  Ladder 3 Ladder 10 
1 1 2 1 1 

HTH 

Peter Alspach

> -Original Message-
> From: r-help-boun...@r-project.org [mailto:r-help-bounces@r-
> project.org] On Behalf Of Markus Weisner
> Sent: Wednesday, 31 August 2011 2:00 p.m.
> To: r-help@r-project.org
> Subject: [R] stumped on how to reorder factors
> 
> I am trying to reorder a factor data type so that when I plot stats
> associated with the factor, the ordering makes sense.
> 
> For instance, if I have a factor entered as follows ...
> 
> A = as.factor(c("1", "10", "3", "3", "10", "10"))
> 
> levels(A)
> 
> 
> ... the ordering does not really make sense (assuming I want the factor
> ordered by integer value), but I understand that this "mis-ordering"
> is
> because the ordering is based on a character string data type and not
> on an
> integer data type.  Because I run into this problem frequently, I wrote
> a
> small function to fix this:
> 
> 
> reorder_factor = function(x, x_sum, decreasing=FALSE){
> 
> factor(as.character(x), levels=levels(x)[order(x_sum,
> decreasing=decreasing)
> ])
> 
> }
> 
> 
> I can then run the following code to fix the problem:
> 
> 
> A = reorder_factor(x=A, x_sum=as.numeric(levels(A)), decreasing=FALSE)
> 
> levels(A)
> 
> 
> ... and now I have correctly ordered integers.  Perhaps not the most
> elegant
> solution, but it worked for my purposes.  Now I have a more complicated
> problem and I need help.  Assuming the following factor:
> 
> 
> B = as.factor(c("Engine 1", "Engine 10", "Ladder 3", "Engine 3",
> "Ladder 10",
> "Engine 10"))
> 
> levels(B)
> 
> 
> I would like the factor ordered first by the proceeding unit type and
> then
> ordered by the following integer.  In this case, I would like to see
> this
> order:  Engine 1, Engine 3, Engine 10, Ladder 3, Ladder 10.  I have
> tried
> many different ways of separating out the unit type from the number,
> but am
> having trouble figuring out a good way of achieving this factor order.
> For
> such a small example, I could obviously manually change the order, but
> I am
> dealing with much larger datasets with many unit types and up to 20
> different numbers for each unit type.  Having an automated way of
> ordering
> these units would be a huge help.  Thanks in advance for any help you
> can
> provide.
> 
> --Markus Weisner
> 
>   [[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.

The contents of this e-mail are confidential and may be subject to legal 
privilege.
 If you are not the intended recipient you must not use, disseminate, 
distribute or
 reproduce all or any part of this e-mail or attachments.  If you have received 
this
 e-mail in error, please notify the sender and delete all material pertaining 
to this
 e-mail.  Any opinion or views expressed in this e-mail are those of the 
individual
 sender and may not represent those of The New Zealand Institute for Plant and
 Food Research Limited.

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/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] Multivariate Normal: Help wanted!

2011-08-30 Thread meddee
djmuseR

Sorry about that! I am using the mvtnorm package.
I forgot that R has (so) many packages as it is has been a while since I
last used R.

Meddee

--
View this message in context: 
http://r.789695.n4.nabble.com/Multivariate-Normal-Help-wanted-tp3779831p3780104.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] Hmisc Latex Question: column headings and Major Column Headings not properly alligned

2011-08-30 Thread David Winsemius


On Aug 30, 2011, at 10:13 PM, . . wrote:

By way of follow-up, here is some data and code that generates the  
output with headings out of alignment:


Looks perfectly acceptable to me. I attached what I got when saved as  
a PDF which is exactly how it looks in my dvi viewer.




filed0e744c.pdf
Description: Adobe PDF document




--  
David.


> dput(mytab)
structure(c(1.3878, -0.7194, 0.3235, 1.6316, -0.4356, 1.8148,
2.1689, -1.3665, -0.2746, -0.5798, 0.7115, -0.1848, -0.2882,
-1.2555, 1.0218, -1.0525, 0.0228, -0.4127, -0.1542, 0.6117, -1.3412,
0.5571, -0.3136, -1.0425, 0.1988, 0.4753, -1.1376, 1.4776, 0.3341,
0.3023, 0.9131, 0.0879, 1.0132, -0.2998, 1.957, 0.6771, 0.3905,
0.55, 0.2163, -0.2591, -1.6511, 2.2718, 0.2844, 0.7738, 0.5144,
0.3111, -0.1829, -1.3218, 0.3496, -0.9592, -0.5241, -2.4456,
-0.0152, 0.9551), .Dim = c(6L, 9L), .Dimnames = list(c("1a",
"1b", "Overall", "2a", "2b", "Overall"), c("mean", "sd", "mean",
"sd", "mean", "sd", "mean", "sd", "n")))
>

Code:
w <- latex(mytab,title="",file="tab/ 
mytab.tex",ctable=TRUE,caption="Descriptive statistic by  
Covariate",caption.loc="bottom",label="tab:sumtab",where="! 
htbp",n.rgroup=c(3,3),rgroup=c("Type I","Type  
II"),size="scriptsize",n.cgroup=c(2,2,2,2,1),cgroup=c("Type A","Type  
B","Type C","Type D","N"))


Thank-you again-

> From: dwinsem...@comcast.net
> To: stat...@hotmail.com
> Subject: Re: [R] Hmisc Latex Question: column headings and Major  
Column Headings not properly alligned

> Date: Tue, 30 Aug 2011 21:23:41 -0400
>
> May I suggest you post to the list the output of dput(mytab) ?
>
> If Frank can see immediately what the problem is, he may come along
> in a day or two, but he usually wants a working example.
>
> --
> David.
>
>
> On Aug 30, 2011, at 9:12 PM, . . wrote:
>
> >
> > Dear R users:
> >
> > When I create a table without Major Column headings, my *regular*
> > column headings appear correct in the typeset latex file. The  
major

> > row heading and row groups are as they should.
> >
> > w <- latex(mytab,title="",file="tab/
> > my.tex",ctable=TRUE,caption="Descriptive statistics by
> > Covariate",caption.loc="bottom",label="tab:mytab",where="!
> > htbp",n.rgroup=c(3,3),rgroup=c("Type I","Type II"))
> >
> > However, I'm trying to use cgroup and n.cgroup to group my columns
> > under appropriate heading as:
> >
> > w <- latex(mytab,title="",file="tab/
> > mytab.tex",ctable=TRUE,caption="Descriptive statistics by
> > Covariate",caption.loc="bottom",label="tab:mytab",where="!
> > htbp",n.rgroup=c(3,3),rgroup=c("Type I","Type
> > II"),n.cgroup=c(2,2,2,2,1),cgroup=c("Type A","Type B","Type  
C","Type

> > D","n"),rowlabel="",size="scriptsize")
> >
> > When I use this code (there are 9 columns total in R object  
"mytab")

> > the resulting Major Column headings are typeset properly, however
> > the colheads themselves are missaligned. The first column heading
> > is over the row labels (Type I and Type II), and the rest of the
> > column headings are spaced offset to the major column headings, so
> > don't line up underneath.
> >
> > I've searched through google and haven't found anything, and I've
> > been experimenting with every combination of latex() options I can
> > think of, and nothing is working. Any suggestions/solutions are
> > greatly appreciated!
> >
> > My Hmisc version is: 3.8-3
> > and R version is: 2.8.1
> >
> >
> >
> > [[alternative HTML version deleted]]
> >
> > __
> > R-help@r-project.org mailing list
> > https://stat.ethz.ch/mailman/listinfo/r-help
> > PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> > and provide commented, minimal, self-contained, reproducible code.
>
> David Winsemius, MD
> West Hartford, CT
>


David Winsemius, MD
West Hartford, CT

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


Re: [R] Error: evaluation nested too deeply: infinite recursion / options(expressions=)?

2011-08-30 Thread Jim Holtman
get a 'traceback' at the point of the error to see how deep the stack is and 
what is being called.  Also look at the help page for 'options' to see how to 
get the browser when an error ocurs; this is under 'error' on the help page.  
also lookup debugging under R so that you can do this yourself.

the error indicates you have probably an infinite recursive call that you have 
to track down.

Sent from my iPad

On Aug 30, 2011, at 22:08, ". ."  wrote:

> Hi all,
> 
> Why I am getting,
> 
> Error: evaluation nested too deeply: infinite recursion / 
> options(expressions=)?
> 
> Thanks in advance!
> 
> func <- Vectorize(function(x, a, sad, trunc=0, ...) {
>  result <- function(x) {
>f1 <- function(n) {
>  dcom <- paste("d", deparse(substitute(sad)), sep="")
>dots <- c(as.name("n"), list(...))
>f <- do.call(dcom, dots)
>  g <- dpois(x,a*n)
>  f * g
>}
>integrate(f1, 0, Inf)$value
>  }
>  return(result(x) / (1 - result(trunc)))
> }, "x")
> 
> func(1, 0.1, exp)
> 
> __
> R-help@r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/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] reading data from multiple files with multiple header

2011-08-30 Thread Jim Holtman
use readLines to read in the entire file, find your pattern of where your data 
starts and then write the data starting there using writeLines to a temporary 
file and now you can just read in that file using read.table; you will have 
'skipped' the extra header data.

Sent from my iPad

On Aug 30, 2011, at 22:23, Julius Tesoro  wrote:

> Dear All,
> 
> 
> I have many files with a lot of headers and text at the beginning of the 
> file. The headers are not uniform though and they contain different sizes Is 
> there a way where I can read a table and skip all of the headers/text on top 
> of it until I encounter a certain text pattern? Here is an example. I just 
> want to read the table after the ~A. 
> 
> 
> ~Version Information
>  VERS.  2.00: CWLS log ASCII Standard -VERSION 2.00
>  WRAP.NO: One line per depth step
> #
> #
> ~Well Information Block
> #MNEM.UNIT Data Type  Description
> #- ---
>  STRT.M 51.000:START DEPTH
>  STOP.M   .010:STOP DEPTH 
>  STEP.M  -.010:STEP   
> #
> #
> ~Curve Information Block
> #MNEM.UNITCurve Description
> #--
>  DEPT.M   :DEPTH
>  GRDE.GAPI:GAMMA FROM DENSITY TOOL 
>  CODE.G/C3:COMPENSATED DENSITY 
> #
> 
> #
> #
> ~A  Depth   GRDE   CODE   LSDU   BRDU   CADE   DENL   
> DENB   ADEN   VL2F   VL4F   VL6F   VL2A
> 51.000-999.25-999.25-999.25-999.25-999.25-999.25  
>   -999.25-999.25-999.25-999.25-999.25-999.25
> 50.990-999.25-999.25-999.25-999.25-999.25-999.25  
>   -999.25-999.25-999.25-999.25-999.25-999.25
> 50.980-999.25-999.25-999.25-999.25-999.25-999.25  
>   -999.25-999.25-999.25-999.25-999.25-999.25
> 50.970-999.25-999.25-999.25-999.25-999.25-999.25  
>   -999.25-999.25-999.25-999.25-999.25-999.25
> 50.960-999.25-999.25-999.25-999.25-999.25-999.25  
>   -999.25-999.25-999.25-999.25-999.25-999.25
> 50.950-999.25-999.25-999.25-999.25-999.25-999.25  
>   -999.25-999.25-999.25-999.25-999.25-999.25
> 50.940-999.25-999.25-999.25-999.25-999.25-999.25  
>   -999.25-999.25-999.25-999.25-999.25-999.25
> 
> __
> R-help@r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/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] wdTable() in R2wd

2011-08-30 Thread Wang, Kevin (SYD)
Hi all,

 

I've been using the wdTable() function from R2wd package and it's been
working great.

 

However I just tried to  do the following:

> table.2

  WasteRebate code   Chargeable (fin_map) Quantity (qty)
Total

 [1,] "Waste"  "Rebate code" "CHG""121"
"$22,534.01" 

 [2,] "Waste"  "Rebate code" "NOCHG"  "229"
"$51,346.14" 

 [3,] "Waste"  "No code" "CHG""2"
"$1,260.01"  

 [4,] "Waste"  "No code" "NOCHG"  "26"
"$10,969.1"  

 [5,] "Total Waste"""""   "378"
"$86,109.26" 

 [6,] "No Waste"   "Rebate code" "CHG""5,330"
"$3,427,721" 

 [7,] "No Waste"   "Rebate code" "NOCHG"  "15,781"
"$6,949,667" 

 [8,] "No Waste"   "No code" "CHG""197"
"$143,407.2" 

 [9,] "No Waste"   "No code" "NOCHG"  "1,205"
"$1,172,939" 

[10,] "Total No Waste" """"   "22513"
"$11,693,735"

[11,] "Grand Total"""""   "22891"
"$11,779,844"

  Per cent Total $

[1,] "0.2%"  

 [2,] "0.4%"  

 [3,] "0%"

 [4,] "0.1%"  

 [5,] "0.7%"  

 [6,] "29.1%" 

 [7,] "58.9%" 

 [8,] "1.2%"  

 [9,] "9.9%"  

[10,] "99.2%" 

[11,] "99.9%" 

> format(table.2)

  WasteRebate code  Chargeable (fin_map) Quantity
(qty)  

 [1,] "Waste " "Rebate code   " "CHG   " "121
"

[2,] "Waste " "Rebate code   " "NOCHG " "229
"

[3,] "Waste " "No code   " "CHG   " "2
"

[4,] "Waste " "No code   " "NOCHG " "26
"

[5,] "Total Waste   " "  " "  " "378
"

[6,] "No Waste  " "Rebate code   " "CHG   " "5,330
"

[7,] "No Waste  " "Rebate code   " "NOCHG " "15,781
"

[8,] "No Waste  " "No code   " "CHG   " "197
"

[9,] "No Waste  " "No code   " "NOCHG " "1,205
"

[10,] "Total No Waste" "  " "  " "22513
"

[11,] "Grand Total   " "  " "  " "22891
"

  TotalPer cent Total $

[1,] "$22,534.01" "0.2%  "

[2,] "$51,346.14" "0.4%  "

[3,] "$1,260.01 " "0%"

[4,] "$10,969.1 " "0.1%  "

[5,] "$86,109.26" "0.7%  "

[6,] "$3,427,721" "29.1% "

[7,] "$6,949,667" "58.9% "

[8,] "$143,407.2" "1.2%  "

[9,] "$1,172,939" "9.9%  "

[10,] "$11,693,735   " "99.2% "

[11,] "$11,779,844   " "99.9% "

> wdTable(format(table.2), caption = "Wastage by chargeable status and
rebate code")

Error in out[1 + (1:nr), 1] <- row.names(data) : 

  number of items to replace is not a multiple of replacement length

 

I'm not sure what caused the error message (table.2 can be exported as a
CSV file fine), and am wondering if anyone has experience similar
problem using wdTable()?

 

Kind regards


Kevin Wang

Manager, Government Advisory Services
Advisory

KPMG
10 Shelley Street
Sydney  NSW  2000  Australia

 

Tel 

+61 2 9335 8282

Fax

+61 2 9335 7001

Mob

0419 374 580

kevinw...@kpmg.com.au  

 

kpmg.com.au  

 

Protect the environment: please think before you print

 



[[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] Question about paste

2011-08-30 Thread Andra Isan
Hello All, 
I have a data frame called train.data which has 100 columns. I am using an 
statistical package to learn a model and the format of using that package is as 
follows:
ex5 <- stepFlexmix(cbind(y,1-y)~x|id2, data=NPreg, k=2,
   model=FLXMRglm(family="binomial"), nrep=5)
the first column of train.data contains the yvector and the rest is the x. I 
have used paste as follows to do cbind(y,1-y)~x but I am not sure how I can use 
that to do the | id2 part:
x =  paste(colnames(train.data[,4:91]), collapse = "+")
mm <- as.formula(paste("cbind(train.data[,1],1-train.data[,1]) ~ ", x))
but I would like to have "|" colnames(train.data[,3]) at the end which would be 
"| id2" in the above example. First of all, when I do colnames for my third 
column (colnames(train.data[,3])) I get NULL which I dont why, because 
colnames(train.data) works perfectly fine. 
Second of all, how should I add that part to my formula?
Thanks a lot,Andra

[[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] Hmisc Latex Question: column headings and Major Column Headings not properly alligned

2011-08-30 Thread . .


  By way of follow-up, here is some data and code that generates the 
output with headings out of alignment:

> dput(mytab)
structure(c(1.3878, -0.7194, 0.3235, 1.6316, -0.4356, 1.8148, 
2.1689, -1.3665, -0.2746, -0.5798, 0.7115, -0.1848, -0.2882, 
-1.2555, 1.0218, -1.0525, 0.0228, -0.4127, -0.1542, 0.6117, -1.3412, 
0.5571, -0.3136, -1.0425, 0.1988, 0.4753, -1.1376, 1.4776, 0.3341, 
0.3023, 0.9131, 0.0879, 1.0132, -0.2998, 1.957, 0.6771, 0.3905, 
0.55, 0.2163, -0.2591, -1.6511, 2.2718, 0.2844, 0.7738, 0.5144, 
0.3111, -0.1829, -1.3218, 0.3496, -0.9592, -0.5241, -2.4456, 
-0.0152, 0.9551), .Dim = c(6L, 9L), .Dimnames = list(c("1a", 
"1b", "Overall", "2a", "2b", "Overall"), c("mean", "sd", "mean", 
"sd", "mean", "sd", "mean", "sd", "n")))
> 

Code:
w <- latex(mytab,title="",file="tab/mytab.tex",ctable=TRUE,caption="Descriptive 
statistic by 
Covariate",caption.loc="bottom",label="tab:sumtab",where="!htbp",n.rgroup=c(3,3),rgroup=c("Type
 I","Type II"),size="scriptsize",n.cgroup=c(2,2,2,2,1),cgroup=c("Type A","Type 
B","Type C","Type D","N"))

Thank-you again-

> From: dwinsem...@comcast.net
> To: stat...@hotmail.com
> Subject: Re: [R] Hmisc Latex Question: column headings and Major Column 
> Headings not properly alligned
> Date: Tue, 30 Aug 2011 21:23:41 -0400
> 
> May I suggest you post  to the list the output of dput(mytab) ?
> 
>   If Frank can see immediately what the problem is, he may come along  
> in a day or two, but he usually wants a working example.
> 
> -- 
> David.
> 
> 
> On Aug 30, 2011, at 9:12 PM, . . wrote:
> 
> >
> > Dear R users:
> >
> > When I create a table without Major Column headings, my *regular*  
> > column headings appear correct in the typeset latex file.  The major  
> > row heading and row groups are as they should.
> >
> > w <- latex(mytab,title="",file="tab/ 
> > my.tex",ctable=TRUE,caption="Descriptive statistics by  
> > Covariate",caption.loc="bottom",label="tab:mytab",where="! 
> > htbp",n.rgroup=c(3,3),rgroup=c("Type I","Type II"))
> >
> > However, I'm trying to use cgroup and n.cgroup to group my columns  
> > under appropriate heading as:
> >
> > w <- latex(mytab,title="",file="tab/ 
> > mytab.tex",ctable=TRUE,caption="Descriptive statistics by  
> > Covariate",caption.loc="bottom",label="tab:mytab",where="! 
> > htbp",n.rgroup=c(3,3),rgroup=c("Type I","Type  
> > II"),n.cgroup=c(2,2,2,2,1),cgroup=c("Type A","Type B","Type C","Type  
> > D","n"),rowlabel="",size="scriptsize")
> >
> > When I use this code (there are 9 columns total in R object "mytab")  
> > the resulting Major Column headings are typeset properly, however  
> > the colheads themselves are missaligned.  The first column heading  
> > is over the row labels (Type I and Type II), and the rest of the  
> > column headings are spaced offset to the major column headings, so  
> > don't line up underneath.
> >
> > I've searched through google and haven't found anything, and I've  
> > been experimenting with every combination of latex() options I can  
> > think of, and nothing is working.  Any suggestions/solutions are  
> > greatly appreciated!
> >
> > My Hmisc version is: 3.8-3
> > and R version is: 2.8.1
> >
> >
> > 
> > [[alternative HTML version deleted]]
> >
> > __
> > R-help@r-project.org mailing list
> > https://stat.ethz.ch/mailman/listinfo/r-help
> > PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> > and provide commented, minimal, self-contained, reproducible code.
> 
> David Winsemius, MD
> West Hartford, CT
> 
  
[[alternative HTML version deleted]]

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


[R] stumped on how to reorder factors

2011-08-30 Thread Markus Weisner
I am trying to reorder a factor data type so that when I plot stats
associated with the factor, the ordering makes sense.

For instance, if I have a factor entered as follows ...

A = as.factor(c("1", "10", "3", "3", "10", "10"))

levels(A)


... the ordering does not really make sense (assuming I want the factor
ordered by integer value), but I understand that this "mis-ordering"  is
because the ordering is based on a character string data type and not on an
integer data type.  Because I run into this problem frequently, I wrote a
small function to fix this:


reorder_factor = function(x, x_sum, decreasing=FALSE){

factor(as.character(x), levels=levels(x)[order(x_sum, decreasing=decreasing)
])

}


I can then run the following code to fix the problem:


A = reorder_factor(x=A, x_sum=as.numeric(levels(A)), decreasing=FALSE)

levels(A)


... and now I have correctly ordered integers.  Perhaps not the most elegant
solution, but it worked for my purposes.  Now I have a more complicated
problem and I need help.  Assuming the following factor:


B = as.factor(c("Engine 1", "Engine 10", "Ladder 3", "Engine 3", "Ladder 10",
"Engine 10"))

levels(B)


I would like the factor ordered first by the proceeding unit type and then
ordered by the following integer.  In this case, I would like to see this
order:  Engine 1, Engine 3, Engine 10, Ladder 3, Ladder 10.  I have tried
many different ways of separating out the unit type from the number, but am
having trouble figuring out a good way of achieving this factor order.  For
such a small example, I could obviously manually change the order, but I am
dealing with much larger datasets with many unit types and up to 20
different numbers for each unit type.  Having an automated way of ordering
these units would be a huge help.  Thanks in advance for any help you can
provide.

--Markus Weisner

[[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] gradient function in OPTIMX

2011-08-30 Thread John C Nash
optimx uses exactly the same code as optim for BFGS. However, the call to optim 
in optimx
is preceded by a check of the gradient at the starting values supplied using 
numDeriv.

That is, we evaluate the gradient with gr=(user's function for gradient) and 
then with
the grad() function from numDeriv. There are some tolerances used, and 
depending on your
function and its perversities (and most nonlinear functions do have some), 
there won't be
total agreement, so the message can get popped up.

Suggestion: Try evaluating the function and gradient at several sets of inputs 
along with
the numDeriv grad() equivalent and see if they are close enough in your own 
view. If not,
then possibly your gradient code is not quite right.

This suggestion is appropriate generally in building optimization problem 
codes, and is
part of the optimgui package of Yixuan Qui built in the recent Google Summer of 
Code effort.

John Nash


On 08/30/2011 06:00 AM, r-help-requ...@r-project.org wrote:
> Message: 10
> Date: Mon, 29 Aug 2011 02:10:36 -0700 (PDT)
> From: Kathie 
> To: r-help@r-project.org
> Subject: [R] gradient function in OPTIMX
> Message-ID: <1314609036951-3775791.p...@n4.nabble.com>
> Content-Type: text/plain; charset=us-ascii
> 
> Dear R users
> 
> 
> When I use OPTIM with BFGS, I've got a significant result without an error
> message.  However, when I use OPTIMX with BFGS( or spg), I've got the
> following an error message.
> 
> 
> 
>> >  optimx(par=theta0, fn=obj.fy, gr=gr.fy, method="BFGS",
>> > control=list(maxit=1))
> Error: Gradient function might be wrong - check it! 
> 
> 
> 
> I checked and checked my gradient function line by line. I could not find
> anything wrong.
> 
> Is it a bug or something?  I prefer OPTIMX, so I'd like to know why.
> 
> Thanks a lot in advance
> 
> Regards,
> 
> Kathryn Lord 
> 
> --
> View this message in context: 
> http://r.789695.n4.nabble.com/gradient-function-in-OPTIMX-tp3775791p3775791.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] reading data from multiple files with multiple headers

2011-08-30 Thread Julius Tesoro
Dear All,


I have many files with a lot of headers and text at the beginning of the file. 
The headers are not uniform though and they contain different sizes Is there a 
way where I can read a table and skip all of the headers/text on top of it 
until I encounter a certain text pattern? Here is an example. I just want to 
read the table after the ~A. 


~Version Information
 VERS.  2.00: CWLS log ASCII Standard -VERSION 2.00
 WRAP.    NO: One line per depth step
#
#
~Well Information Block
#MNEM.UNIT Data Type  Description
#- ---    
 STRT.M 51.000    :START DEPTH    
 STOP.M   .010    :STOP DEPTH     
 STEP.M  -.010    :STEP   
#
#
~Curve Information Block
#MNEM.UNIT    Curve Description
#-    -
 DEPT.M   :DEPTH
 GRDE.GAPI    :GAMMA FROM DENSITY TOOL 
 CODE.G/C3    :COMPENSATED DENSITY     
#

#
#
~A  Depth   GRDE   CODE   LSDU   BRDU   CADE   
DENL   DENB   ADEN   VL2F   VL4F   VL6F   VL2A
    51.000    -999.25    -999.25    -999.25    -999.25    -999.25    -999.25    
-999.25    -999.25    -999.25    -999.25    -999.25    -999.25
    50.990    -999.25    -999.25    -999.25    -999.25    -999.25    -999.25    
-999.25    -999.25    -999.25    -999.25    -999.25    -999.25
    50.980    -999.25    -999.25    -999.25    -999.25    -999.25    -999.25    
-999.25    -999.25    -999.25    -999.25    -999.25    -999.25
    50.970    -999.25    -999.25    -999.25    -999.25    -999.25    -999.25    
-999.25    -999.25    -999.25    -999.25    -999.25    -999.25
    50.960    -999.25    -999.25    -999.25    -999.25    -999.25    -999.25    
-999.25    -999.25    -999.25    -999.25    -999.25    -999.25
    50.950    -999.25    -999.25    -999.25    -999.25    -999.25    -999.25    
-999.25    -999.25    -999.25    -999.25    -999.25    -999.25
    50.940    -999.25    -999.25    -999.25    -999.25    -999.25    -999.25    
-999.25    -999.25    -999.25    -999.25    -999.25    -999.25

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/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: evaluation nested too deeply: infinite recursion / options(expressions=)?

2011-08-30 Thread . .
Hi all,

Why I am getting,

Error: evaluation nested too deeply: infinite recursion / options(expressions=)?

Thanks in advance!

func <- Vectorize(function(x, a, sad, trunc=0, ...) {
  result <- function(x) {
f1 <- function(n) {
  dcom <- paste("d", deparse(substitute(sad)), sep="")
dots <- c(as.name("n"), list(...))
f <- do.call(dcom, dots)
  g <- dpois(x,a*n)
  f * g
}
integrate(f1, 0, Inf)$value
  }
  return(result(x) / (1 - result(trunc)))
}, "x")

func(1, 0.1, exp)

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/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] Multivariate Normal: Help wanted!

2011-08-30 Thread Dennis Murphy
Hi:

It's polite to mention from which package you extract certain
functions. For example, the function dmvnorm() exists in at least the
following packages (following a search from the sos package):
mixtools, emdbook, klaR and mvtnorm, not to mention related functions
in three other packages. Since I can't discern which package your
dmvnorm() comes from, I am loath to test your code.

However, if the objective is to apply the MV.MSE function to all
elements of the list EP, then try (untested)

EPres <- lapply(EP, function(x) MV.MSE(10, x, c(.25, .25), diag(c(1, 2

HTH,
Dennis

On Tue, Aug 30, 2011 at 3:01 PM, meddee  wrote:
> I have the following function, a MSE calc based on some Multivariate normals:
>
> MV.MSE<-function(n,EP,X,S){
>           (dmvnorm(X,mean=rep(0,2),I+S+EP)-dmvnorm(X,mean=rep(0,2),I+S))^2
> +
>           1/n*(dmvnorm(X,mean=rep(0,2),1+S+EP/2)*det(4*pi*EP)^-.5-
>           (dmvnorm(X,mean=rep(0,2),I+S+EP ))^2)}
>
> I can get the  MV.MSE for given values of the function e.g
>         MV.MSE(10,diag(0.5,2),c(.25,.25),diag(1,2))
>
> But I would like to how MV.MSE varies for different EP matrices. I tried
> this,
>         ep<-seq(0,10,by=.01)
>         EP <- lapply(ep, function(d) diag(d, 2)) # thanks Joshua, Mark!
>         MV.MSE(10,EP,c(.25,.25),diag(1,2))
>
> but got this error: *Error in diag(1, 2) + S + EP : non-numeric argument to
> binary operator*
>
> Any help would be most welcome!
>
> Meddee
>
>
> --
> View this message in context: 
> http://r.789695.n4.nabble.com/Multivariate-Normal-Help-wanted-tp3779831p3779831.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] Hmisc Latex Question: column headings and Major Column Headings not properly alligned

2011-08-30 Thread . .

Dear R users:

When I create a table without Major Column headings, my *regular* column 
headings appear correct in the typeset latex file.  The major row heading and 
row groups are as they should.

w <- latex(mytab,title="",file="tab/my.tex",ctable=TRUE,caption="Descriptive 
statistics by 
Covariate",caption.loc="bottom",label="tab:mytab",where="!htbp",n.rgroup=c(3,3),rgroup=c("Type
 I","Type II"))

However, I'm trying to use cgroup and n.cgroup to group my columns under 
appropriate heading as:

w <- latex(mytab,title="",file="tab/mytab.tex",ctable=TRUE,caption="Descriptive 
statistics by 
Covariate",caption.loc="bottom",label="tab:mytab",where="!htbp",n.rgroup=c(3,3),rgroup=c("Type
 I","Type II"),n.cgroup=c(2,2,2,2,1),cgroup=c("Type A","Type B","Type C","Type 
D","n"),rowlabel="",size="scriptsize")

When I use this code (there are 9 columns total in R object "mytab") the 
resulting Major Column headings are typeset properly, however the colheads 
themselves are missaligned.  The first column heading is over the row labels 
(Type I and Type II), and the rest of the column headings are spaced offset to 
the major column headings, so don't line up underneath.

I've searched through google and haven't found anything, and I've been 
experimenting with every combination of latex() options I can think of, and 
nothing is working.  Any suggestions/solutions are greatly appreciated!

My Hmisc version is: 3.8-3
and R version is: 2.8.1 

 
  
[[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] convert a matrix to binaryMatrix in Recommenderlab

2011-08-30 Thread Michael Hahsler

Hi Jing

recommenderlab is still under heavy development and quite far away from 
version 1.0-0. Here is some code to create a binaryRatingMatrix from a 
0-1 matrix:


library(recommenderlab)

## create a 10x10 0-1 matrix
m <- matrix(sample(c(0,1),100, replace=TRUE), nrow=10, ncol=10)
m

## coerce it into a binaryRatingMatrix
b <- as(m, "binaryRatingMatrix")
b

## coerce it back to see if it worked
as(b, "matrix")

Hope this helps,
-Michael

--
  Dr. Michael Hahsler, Visiting Assistant Professor
  Department of Computer Science and Engineering
  Lyle School of Engineering
  Southern Methodist University, Dallas, Texas

  (214) 768-8878 * mhahs...@lyle.smu.edu * http://lyle.smu.edu/~mhahsler

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/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] Descriptive Stats from Data Frame

2011-08-30 Thread Simon Zehnder
Hi Rich,

I do not know what u really want, because it seems to me, u want to calculate 
the mean of all rows, where the chemical is Arsenic??

But try this to get a little more inside:

mean(chemdata$quant[chemdata$param=="Arsenic"])

The vector chemdata[chemdata$param=="Arsenic",] is a logical vector, returning 
TRUE for every row in which the variable param takes the value "Arsenic". Try 
it in your R editor to see it and understand the R concept!

If u now want to get all values of a certain column, given all values have 
"Arsenic" as param, u just write:

chemdata$COLUMNNAME[chemdata$param=="Arsenic"]

I do not know if this helps, as it seems to me, that Arsenic only occurs once 
in your frame…..

Good luck Simon



On Aug 30, 2011, at 11:00 PM, Rich Shepard wrote:

>  I don't find how to do what I need to do in Dalgaard or 'R Cookbook', so
> I'm asking here.
> 
>  I have a data frame with water chemistry data and I want to start
> exploring these data. There are three factors (site, date, chemical)
> associated with each measurement. The data frame looks like this:
> 
>> summary(chemdata)
> site_id.sample_date.param.quant
> BC-0.5|1996-04-19|Arsenic|0.01  :1
> BC-0.5|1996-04-19|Calcium|76.56 :1
> BC-0.5|1996-04-19|Chloride|12   :1
> BC-0.5|1996-04-19|Magnesium|43.23   :1
> BC-0.5|1996-04-19|Sulfate|175   :1
> BC-0.5|1996-04-19|Total Dissolved Solids|460:1
> (Other) :14880
> 
>  I want first to calculate (and plot) descriptive stats by chemical,
> ignoring site and date and telling R to ignore missing data. (Incorporating
> those factors will occur later.) What I have not been able to figure out is
> how to specify the command to, for example, calculate mean and sd for
> Arsenic. My floundering and thrashing includes attempts like these:
> 
>> mean(chemdata.param="Arsenic")
> Error in is.numeric(x) : 'x' is missing
>> mean(chemdata.quant, param="Arsenic")
> Error in mean(chemdata.quant, param = "Arsenic") :
>  object 'chemdata.quant' not found
>> mean(chemdata$quant, param="Arsenic")
> [1] NA
> Warning message:
> In mean.default(chemdata$quant, param = "Arsenic") :
>  argument is not numeric or logical: returning NA
> 
>  As a newcomer to R I've done a lot of reading, yet all the examples use
> nicely structured data to illustrate the point being made. I need to work
> with my data and learn how to specify columns and write correct commands for
> the analyses I need. Please point me in the right direction.
> 
> Rich
> 
> __
> R-help@r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/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] Multivariate Normal: Help wanted!

2011-08-30 Thread meddee
I have the following function, a MSE calc based on some Multivariate normals:

MV.MSE<-function(n,EP,X,S){ 
   (dmvnorm(X,mean=rep(0,2),I+S+EP)-dmvnorm(X,mean=rep(0,2),I+S))^2 
+
   1/n*(dmvnorm(X,mean=rep(0,2),1+S+EP/2)*det(4*pi*EP)^-.5- 
   (dmvnorm(X,mean=rep(0,2),I+S+EP ))^2)}

I can get the  MV.MSE for given values of the function e.g
 MV.MSE(10,diag(0.5,2),c(.25,.25),diag(1,2))

But I would like to how MV.MSE varies for different EP matrices. I tried
this,
 ep<-seq(0,10,by=.01)
 EP <- lapply(ep, function(d) diag(d, 2)) # thanks Joshua, Mark!
 MV.MSE(10,EP,c(.25,.25),diag(1,2))

but got this error: *Error in diag(1, 2) + S + EP : non-numeric argument to
binary operator*

Any help would be most welcome!

Meddee


--
View this message in context: 
http://r.789695.n4.nabble.com/Multivariate-Normal-Help-wanted-tp3779831p3779831.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] putting in special characters in print statements

2011-08-30 Thread Erin Hodgess
Solved!

 xe <- paste("\\end{verbatim}\n",sep="")
> cat(xe)
\end{verbatim}
>




On Tue, Aug 30, 2011 at 5:31 PM, Erin Hodgess  wrote:
> Dear R People:
>
> Here is a question which probably has a very simple answer.  I want to
> print "\end{verbatim}" in the output of a sink file.  If I put in
>
> \end{verbatim}
> I get an unrecognized escape sequence.  If I put in \\end{verbatim},
> it runs fine, but the output is "\\end{verbatim}"
>
> How do I get just one bracket, please?
>
> Thanks,
> Erin
>
>
> --
> Erin Hodgess
> Associate Professor
> Department of Computer and Mathematical Sciences
> University of Houston - Downtown
> mailto: erinm.hodg...@gmail.com
>



-- 
Erin Hodgess
Associate Professor
Department of Computer and Mathematical Sciences
University of Houston - Downtown
mailto: erinm.hodg...@gmail.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] term lists with tm package

2011-08-30 Thread Jack Tanner
I've got a sparse term list of the form

term1 doc1
term2 doc1
term3 doc2
etc.

I'd like to load this into a Corpus, as defined in the tm package. I was
thinking that one way to do this is to iterate over the list building up the i,
j, v vectors for a simple_triplet_matrix, and then to use that as an input to
as.TermDocumentMatrix.

Is that the best way to go? Any hints? Thanks in advance.

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

2011-08-30 Thread jim holtman
There are 10 overlaps in the data:

> df1<-data.frame(start=as.POSIXct(paste('2011-06-01 ',1:20,':00',sep='')),
+ end=as.POSIXct(paste('2011-06-01 ',1:20,':30',sep='')))
> df2<-data.frame(start=as.POSIXct(paste('2011-06-01
+ ',rep(seq(1,20,2),2),':',sample(1:19,20,replace=T),sep='')),
+ end=as.POSIXct(paste('2011-06-01
+ ',rep(seq(1,20,2),2),':',sample(20:50,20),sep='')))
>
> # create a matrix where the 'start' adds 1 to a count and the 'end' subtracts 
> 1
> # the second column is the df# and the 4th is the row number of the data
>
> x <- rbind(
+ cbind(df1$start, 1, 1, seq(nrow(df1))),
+ cbind(df1$end, 1, -1, seq(nrow(df1))),
+ cbind(df2$start, 2, 1, seq(nrow(df2))),
+ cbind(df2$end, 2, -1, seq(nrow(df2)))
+ )
> # sort by time
> x <- x[order(x[,1]),]
> # add the queue count; this is the number of items in a queue which is
> # used to determine any overlaps if the queue is greater than one
> x <- cbind(x, count = cumsum(x[,3]))
> # split the data into group when the count == 0
> indx <- split(seq(nrow(x)), cumsum(c(FALSE, head(x[, 'count'], -1) == 0)))
> # keep groups of length > 2; there are the overlaps
> indx <- indx[sapply(indx, length) > 2]
> # get unique df# and row indices
> lapply(indx, function(a){
+ unique(paste(x[a, 2], x[a, 4], sep = ' - '))
+ })
$`0`
[1] "1 - 1"  "2 - 11" "2 - 1"

$`2`
[1] "1 - 3"  "2 - 12" "2 - 2"

$`4`
[1] "1 - 5"  "2 - 13" "2 - 3"

$`6`
[1] "1 - 7"  "2 - 14" "2 - 4"

$`8`
[1] "1 - 9"  "2 - 15" "2 - 5"

$`10`
[1] "1 - 11" "2 - 16" "2 - 6"

$`12`
[1] "1 - 13" "2 - 17" "2 - 7"

$`14`
[1] "1 - 15" "2 - 8"  "2 - 18"

$`16`
[1] "1 - 17" "2 - 19" "2 - 9"

$`18`
[1] "1 - 19" "2 - 20" "2 - 10"


On Tue, Aug 30, 2011 at 2:15 PM, Justin Haynes  wrote:
> Hiya,
>
> maybe there is a native R function for this and if so please let me know!
>
> I have 2 data.frames with start and end dates, they read in as strings and I
> am converting to POSIXct.  How can I check for overlap?
>
> The end result ideally will be a single data.frame containing all the
> columns of the other two with rows where there were date overlaps.
>
>
> df1<-data.frame(start=as.POSIXct(paste('2011-06-01 ',1:20,':00',sep='')),
> end=as.POSIXct(paste('2011-06-01 ',1:20,':30',sep='')))
> df2<-data.frame(start=as.POSIXct(paste('2011-06-01
> ',rep(seq(1,20,2),2),':',sample(1:19,20,replace=T),sep='')),
> end=as.POSIXct(paste('2011-06-01
> ',rep(seq(1,20,2),2),':',sample(20:50,20),sep='')))
>
> I tried:
> library(lubridate)
>
> df1$interval<-new_interval(df1$start,df1$end)
>
>> df1$interval[1]
> [1] 2011-06-01 01:00:00 -- 2011-06-01 01:30:00
>> df2$start[1]
> [1] "2011-06-01 01:17:00 PDT"
>
> but
>
>> df2$start[1] %in% df1$interval[1]
> [1] FALSE
>>
>
> This must be fairly straight forward and I just don't know where to look!
>
>
> Thanks,
> Justin
>
>        [[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.
>



-- 
Jim Holtman
Data Munger Guru

What is the problem that you are trying to solve?

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/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] Problem resolved: thanks! RE: column names with rbind loop

2011-08-30 Thread Vining, Kelly
Thanks to both Weidong and David for the help! By implementing both of your 
suggestions I was able to make this work.  I did end up putting header=TRUE for 
both read operations. 

--Kelly

From: David Winsemius [dwinsem...@comcast.net]
Sent: Tuesday, August 30, 2011 1:16 PM
To: Vining, Kelly
Cc: Weidong Gu; r-help@r-project.org
Subject: Re: [R] column names with rbind loop

On Aug 30, 2011, at 3:46 PM, Vining, Kelly wrote:

> Thanks much for your help! This almost works. However, now I am
> getting the following error:
>
>> for(i in all.files) {
> + if (i==all.files[1]) new.data <- read.table(i,header=TRUE) else {
> + new.data <- rbind(new.data, read.table(i))}}
> Error in match.names(clabs, names(xi)) :
>  names do not match previous names

You need to decide if you are going to use the V-names or the original
names because rbind requires that the names for its two arguments
match. Perhaps you want to read the names in separately with
readLines? Also look at the skip argument to read.tables.

>
> I am wondering if this is because R adds row numbers as a numerical
> column to the table of the first file it reads?

It does so by default. It needs to have some sort of character vector
to use, so if there is none, it makes up names. I don't understand why
you didn't use, ... header =TRUE, for both read operations.

--
David.

>
>
> 
> From: Weidong Gu [anopheles...@gmail.com]
> Sent: Tuesday, August 30, 2011 12:00 PM
> To: Vining, Kelly
> Cc: r-help@r-project.org
> Subject: Re: [R] column names with rbind loop
>
> How about to add a conditional statement to get the header from 1st
> file
>
> for(i in all.files) {
> if (i==all.files[1]) new.data <- read.table(i,header=TRUE) else {
> new.data <- rbind(new.data, read.table(i))}}
>
>
> Weidong Gu
>
>
> On Tue, Aug 30, 2011 at 1:42 PM, Vining, Kelly
>  wrote:
>> Hello R  users.
>>
>> This is a fairly basic question:
>>
>> I am concatenating data from sets of files in a directory using a
>> loop. The column names in all files are exactly the same. My
>> understanding is that rbind takes column names from the first file
>> it reads. However, my output is showing that the column names are
>> treated as a first data row, not treated as headers.
>>
>> I compile my file names like this:
>>
>>> all.files <- list.files()
>>> all.files
>> [1] "1.rpkm"  "10.rpkm" "11.rpkm" "12.rpkm" "13.rpkm" "14.rpkm"
>> [7] "15.rpkm" "16.rpkm" "17.rpkm" "18.rpkm" "19.rpkm" "2.rpkm"
>> [13] "3.rpkm"  "4.rpkm"  "5.rpkm"  "6.rpkm"  "7.rpkm"  "8.rpkm"
>> [19] "9.rpkm"
>>
>> Then loop through them like this:
>>> new.data <- NULL
>>> for(i in all.files) {
>> + in.data <- read.table(i)
>> + new.data <- rbind(new.data, in.data)}
>>> head(new.data)
>>V1   V2V3 V4 V5V6 V7
>> 1 seq_id   source  type  startend score strand
>> 2 scaffold_1 Ptrichocarpav2_0 gene_body  12639  13384 .  +
>> 3 scaffold_1 Ptrichocarpav2_0 gene_body  22190  22516 .  +
>> 4 scaffold_1 Ptrichocarpav2_0 gene_body  74076 75893 .  +
>> 5 scaffold_1 Ptrichocarpav2_0 gene_body  80207  81289 .  -
>> 6 scaffold_1 Ptrichocarpav2_0 gene_body 105236 107712 .  +
>>
>>
>> As you can see, R is putting a "V1, V2..." header row here because
>> I didn't say "header=TRUE" in my read.table command. But if I do
>> this within the loop, I get an error. If I try to delete the V1, V2
>> row after the fact by
>>
>> new.data <- new.data[-1,]
>>
>> R deletes my "real" header row.
>>
>> How can I get the header that I want?
>>
>> Thanks for any help,
>> --Kelly V.
>>
>> __
>> R-help@r-project.org mailing list
>> https://stat.ethz.ch/mailman/listinfo/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.

David Winsemius, MD
West Hartford, CT

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


Re: [R] Error in evalauating a function

2011-08-30 Thread Martin Morgan

On 08/30/2011 04:19 PM, Debs Majumdar wrote:

Here's the plik code I ran:

plink --bfile olr_try1 --pheno p3.txt --pheno-name dnum --covar p3.txt 
--covar-name a4 --missing-phenotype -9 --R olr2.R

The below function is contained in the olr2.R script.

The data which I input is contained in the binary file named olr_try1.
The response variable (PHENO) and the covariate (COVAR) is contained in the 
file p3.txt.

I added the option --R-debug to get the output below.

  Thanks,

  Debs




- Original Message -
From: Debs Majumdar
To: "r-help@r-project.org"
Cc:
Sent: Tuesday, August 30, 2011 3:49 PM
Subject: Error in evalauating a function

Hi,


   I am very new to R. So, pardon my dumb question. I was trying to write my 
own function to run a different model (perform an ordered logistic regression) 
using the example in website 
http://pngu.mgh.harvard.edu/~purcell/plink/rfunc.shtml

But R returns a error `R Error in eval(expr, envir, enclos) : object 's' not 
found' when I run it. What am I doing wrong here? Here's what I got from the 
debug file.

# Input data

n<- 10
PHENO<- c( 1, 3, 2, 3, 1, 1, 1, 2, 1, 2 )
c<- c( 1, 1, 0, 0, 0, 0, 0, 1, 0, 0 )
COVAR<- matrix( c , nrow = n , byrow=T)
CLUSTER<- c( 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 )
l<- 22
g<- c( 0, 1, 1, 0, 0, 0, 1, 0, 2, 1, 0, 0, 0, 0, 0, 1, 1, 1, 0, 1, 0, 0, 1, 2, 
0, 0, 0, 2, 0, 0, 0, 1, 0, 1, 0, 1, 0, 1, 0, 2, 0, 1, 1, 0, 1, 0, 0, 1, 0, 0, 0, 
0, 0, 1, 0, 0, 1, 1, -1, -1, 1, 0, 0, 1, 1, -1, 1, 0, 1, 0, 0, 2, 0, 0, 0, 1, 0, 
0, 0, 0, 0, 1, 0, 1, 0, 0, 0, 0, 1, 2, 0, 1, 0, 0, 1, 0, 1, 0, 1, 2, 0, 1, 1, 0, 
1, 0, 2, 1, 0, 0, 0, 2, 1, 0, 1, 0, 1, 0, 1, 0, 0, 1, 0, 0, 0, 0, 0, 0, 1, 1, 0, 
0, 0, 0, 0, 0, 0, 0, 0, 0, 2, 0, 0, -1, -1, 0, 1, 0, 0, 0, 2, 0, 1, 0, 0, 0, 2, 0, 
1, 1, 2, 0, 0, 1, 0, 1, -1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0, 1, 0, 1, 0, 0, 0, 1, 0, 
1, 0, 0, 1, 0, 1, 0, 1, 0, 1, 0, 2, 0, 1, 1, 0, 0, 1, 1, 1, 0, 0, 0, 0, 1, 1, 2, 
0, 0, 0, 1, 1, 1, 0, 0 )
GENO<- matrix( g , nrow = n ,byrow=T)
GENO[GENO == -1 ]<- NA


# Function

library(ordinal)
  Rplink<- function(PHENO,GENO,CLUSTER,COVAR)
  {
   f1<- function(s)
   {
 m<- summary(clm(PHENO ~ s))


I see the error if I run the command

  Rplink(PHENO, GENO, CLUSTER, COVAR)

after sourcing the code you provided. I think clm is not implemented 
correctly; it is looking for 's' in the wrong environment. Help it along 
by providing an explicit 'data' argument. Also, PHENO is apparently 
supposed to be a 'factor'. So maybe replace the previous line with...


df <- data.frame(PHENO=factor(PHENO), s)
m <- summary(clm(PHENO ~ s, data=df))

Perhaps contact the maintainer of the 'ordinal' package (use 
packageDescription('ordinal') to report the issue.


Martin


 r<- c(m$coef)
 c( length(r) , r )
   }
  apply( GENO , 2 , f1 )
  }


Thanks,

  Debs

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



--
Computational Biology
Fred Hutchinson Cancer Research Center
1100 Fairview Ave. N. PO Box 19024 Seattle, WA 98109

Location: M1-B861
Telephone: 206 667-2793

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

2011-08-30 Thread Debs Majumdar
Here's the plik code I ran:

plink --bfile olr_try1 --pheno p3.txt --pheno-name dnum --covar p3.txt 
--covar-name a4 --missing-phenotype -9 --R olr2.R

The below function is contained in the olr2.R script.

The data which I input is contained in the binary file named olr_try1.
The response variable (PHENO) and the covariate (COVAR) is contained in the 
file p3.txt.

I added the option --R-debug to get the output below.

 Thanks,

 Debs




- Original Message -
From: Debs Majumdar 
To: "r-help@r-project.org" 
Cc: 
Sent: Tuesday, August 30, 2011 3:49 PM
Subject: Error in evalauating a function

Hi, 


  I am very new to R. So, pardon my dumb question. I was trying to write my own 
function to run a different model (perform an ordered logistic regression) 
using the example in website 
http://pngu.mgh.harvard.edu/~purcell/plink/rfunc.shtml

But R returns a error `R Error in eval(expr, envir, enclos) : object 's' not 
found' when I run it. What am I doing wrong here? Here's what I got from the 
debug file.

# Input data

n <- 10
PHENO <- c( 1, 3, 2, 3, 1, 1, 1, 2, 1, 2 ) 
c <- c( 1, 1, 0, 0, 0, 0, 0, 1, 0, 0 ) 
COVAR <- matrix( c , nrow = n , byrow=T)
CLUSTER <- c( 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 ) 
l <- 22
g <- c( 0, 1, 1, 0, 0, 0, 1, 0, 2, 1, 0, 0, 0, 0, 0, 1, 1, 1, 0, 1, 0, 0, 1, 2, 
0, 0, 0, 2, 0, 0, 0, 1, 0, 1, 0, 1, 0, 1, 0, 2, 0, 1, 1, 0, 1, 0, 0, 1, 0, 0, 
0, 0, 0, 1, 0, 0, 1, 1, -1, -1, 1, 0, 0, 1, 1, -1, 1, 0, 1, 0, 0, 2, 0, 0, 0, 
1, 0, 0, 0, 0, 0, 1, 0, 1, 0, 0, 0, 0, 1, 2, 0, 1, 0, 0, 1, 0, 1, 0, 1, 2, 0, 
1, 1, 0, 1, 0, 2, 1, 0, 0, 0, 2, 1, 0, 1, 0, 1, 0, 1, 0, 0, 1, 0, 0, 0, 0, 0, 
0, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 2, 0, 0, -1, -1, 0, 1, 0, 0, 0, 2, 0, 1, 
0, 0, 0, 2, 0, 1, 1, 2, 0, 0, 1, 0, 1, -1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0, 1, 0, 
1, 0, 0, 0, 1, 0, 1, 0, 0, 1, 0, 1, 0, 1, 0, 1, 0, 2, 0, 1, 1, 0, 0, 1, 1, 1, 
0, 0, 0, 0, 1, 1, 2, 0, 0, 0, 1, 1, 1, 0, 0 )
GENO <- matrix( g , nrow = n ,byrow=T)
GENO[GENO == -1 ] <- NA 


# Function

library(ordinal)
 Rplink <- function(PHENO,GENO,CLUSTER,COVAR)
 {
  f1 <- function(s) 
  {
    m <- summary(clm(PHENO ~ s))
    r <- c(m$coef)
    c( length(r) , r )
  }
 apply( GENO , 2 , f1 )
 }


Thanks,

 Debs

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/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] Descriptive Stats from Data Frame

2011-08-30 Thread Rich Shepard

On Tue, 30 Aug 2011, David Winsemius wrote:


That does look more workable. You might consider changing the dates with:
chemadata$samp_date <- as.Date(as.character(chemdata$sample_date) )


David,

  I was thinking that I needed to do this. Thank you. It's now done.

  Good progress for the first afternoon applying R to my own data.

Rich

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

2011-08-30 Thread David Winsemius


On Aug 30, 2011, at 6:49 PM, Debs Majumdar wrote:


Hi,


  I am very new to R. So, pardon my dumb question. I was trying to  
write my own function to run a different model (perform an ordered  
logistic regression) using the example in website http://pngu.mgh.harvard.edu/~purcell/plink/rfunc.shtml


But R returns a error `R Error in eval(expr, envir, enclos) : object  
's' not found' when I run it. What am I doing wrong here?


How can we tell? You have not offered the code that you used to run  
it. The code you offered runs without difficulty (once I change the  
T's to TRUE's, that is).




Here's what I got from the debug file.

# Input data

n <- 10
PHENO <- c( 1, 3, 2, 3, 1, 1, 1, 2, 1, 2 )
c <- c( 1, 1, 0, 0, 0, 0, 0, 1, 0, 0 )
COVAR <- matrix( c , nrow = n , byrow=T)
CLUSTER <- c( 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 )
l <- 22
g <- c( 0, 1, 1, 0, 0, 0, 1, 0, 2, 1, 0, 0, 0, 0, 0, 1, 1, 1, 0, 1,  
0, 0, 1, 2, 0, 0, 0, 2, 0, 0, 0, 1, 0, 1, 0, 1, 0, 1, 0, 2, 0, 1, 1,  
0, 1, 0, 0, 1, 0, 0, 0, 0, 0, 1, 0, 0, 1, 1, -1, -1, 1, 0, 0, 1, 1,  
-1, 1, 0, 1, 0, 0, 2, 0, 0, 0, 1, 0, 0, 0, 0, 0, 1, 0, 1, 0, 0, 0,  
0, 1, 2, 0, 1, 0, 0, 1, 0, 1, 0, 1, 2, 0, 1, 1, 0, 1, 0, 2, 1, 0, 0,  
0, 2, 1, 0, 1, 0, 1, 0, 1, 0, 0, 1, 0, 0, 0, 0, 0, 0, 1, 1, 0, 0, 0,  
0, 0, 0, 0, 0, 0, 0, 2, 0, 0, -1, -1, 0, 1, 0, 0, 0, 2, 0, 1, 0, 0,  
0, 2, 0, 1, 1, 2, 0, 0, 1, 0, 1, -1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0,  
1, 0, 1, 0, 0, 0, 1, 0, 1, 0, 0, 1, 0, 1, 0, 1, 0, 1, 0, 2, 0, 1, 1,  
0, 0, 1, 1, 1, 0, 0, 0, 0, 1, 1, 2, 0, 0, 0, 1, 1, 1, 0, 0 )

GENO <- matrix( g , nrow = n ,byrow=T)
GENO[GENO == -1 ] <- NA


# Function

library(ordinal)
 Rplink <- function(PHENO,GENO,CLUSTER,COVAR)
 {
  f1 <- function(s)
  {
m <- summary(clm(PHENO ~ s))
r <- c(m$coef)
c( length(r) , r )
  }
 apply( GENO , 2 , f1 )
 }


Thanks,

 Debs


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


David Winsemius, MD
West Hartford, CT

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


[R] Error in evalauating a function

2011-08-30 Thread Debs Majumdar
Hi, 


  I am very new to R. So, pardon my dumb question. I was trying to write my own 
function to run a different model (perform an ordered logistic regression) 
using the example in website 
http://pngu.mgh.harvard.edu/~purcell/plink/rfunc.shtml

But R returns a error `R Error in eval(expr, envir, enclos) : object 's' not 
found' when I run it. What am I doing wrong here? Here's what I got from the 
debug file.

# Input data

n <- 10
PHENO <- c( 1, 3, 2, 3, 1, 1, 1, 2, 1, 2 ) 
c <- c( 1, 1, 0, 0, 0, 0, 0, 1, 0, 0 ) 
COVAR <- matrix( c , nrow = n , byrow=T)
CLUSTER <- c( 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 ) 
l <- 22
g <- c( 0, 1, 1, 0, 0, 0, 1, 0, 2, 1, 0, 0, 0, 0, 0, 1, 1, 1, 0, 1, 0, 0, 1, 2, 
0, 0, 0, 2, 0, 0, 0, 1, 0, 1, 0, 1, 0, 1, 0, 2, 0, 1, 1, 0, 1, 0, 0, 1, 0, 0, 
0, 0, 0, 1, 0, 0, 1, 1, -1, -1, 1, 0, 0, 1, 1, -1, 1, 0, 1, 0, 0, 2, 0, 0, 0, 
1, 0, 0, 0, 0, 0, 1, 0, 1, 0, 0, 0, 0, 1, 2, 0, 1, 0, 0, 1, 0, 1, 0, 1, 2, 0, 
1, 1, 0, 1, 0, 2, 1, 0, 0, 0, 2, 1, 0, 1, 0, 1, 0, 1, 0, 0, 1, 0, 0, 0, 0, 0, 
0, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 2, 0, 0, -1, -1, 0, 1, 0, 0, 0, 2, 0, 1, 
0, 0, 0, 2, 0, 1, 1, 2, 0, 0, 1, 0, 1, -1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0, 1, 0, 
1, 0, 0, 0, 1, 0, 1, 0, 0, 1, 0, 1, 0, 1, 0, 1, 0, 2, 0, 1, 1, 0, 0, 1, 1, 1, 
0, 0, 0, 0, 1, 1, 2, 0, 0, 0, 1, 1, 1, 0, 0 )
GENO <- matrix( g , nrow = n ,byrow=T)
GENO[GENO == -1 ] <- NA 


# Function

library(ordinal)
 Rplink <- function(PHENO,GENO,CLUSTER,COVAR)
 {
  f1 <- function(s) 
  {
    m <- summary(clm(PHENO ~ s))
    r <- c(m$coef)
    c( length(r) , r )
  }
 apply( GENO , 2 , f1 )
 }


Thanks,

 Debs


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

2011-08-30 Thread Erin Hodgess
Dear R People:

Here is a question which probably has a very simple answer.  I want to
print "\end{verbatim}" in the output of a sink file.  If I put in

\end{verbatim}
I get an unrecognized escape sequence.  If I put in \\end{verbatim},
it runs fine, but the output is "\\end{verbatim}"

How do I get just one bracket, please?

Thanks,
Erin


-- 
Erin Hodgess
Associate Professor
Department of Computer and Mathematical Sciences
University of Houston - Downtown
mailto: erinm.hodg...@gmail.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] Descriptive Stats from Data Frame

2011-08-30 Thread David Winsemius


On Aug 30, 2011, at 5:38 PM, Rich Shepard wrote:


On Tue, 30 Aug 2011, David Winsemius wrote:


I think you need to go back and do your input operations again with
sep="|"


David,

 Yes, that's better. I did not know of the sep option. The new  
results:



str(chemdata)

'data.frame':   14886 obs. of  4 variables:
$ site_id: Factor w/ 148 levels "BC-0.5","BC-1",..: 104 145 126  
115 114

128 124 2 3 3 ...
$ sample_date: Factor w/ 1012 levels "1980-03-01","1980-05-01",..:  
432 410

423 405 398 408 401 360 366 407 ...
$ param  : Factor w/ 8 levels "Arsenic","Calcium",..: 1 1 1 1 1  
1 1 1 1

1 ...
$ quant  : num  0.06 0.01 0.01 0.01 0.01 0.01 0.01 0.01 0.01  
0.01 ...


 Now I can work on the commands I need.


That does look more workable. You might consider changing the dates  
with:


chemadata$samp_date <- as.Date(as.character(chemdata$sample_date) )




Many thanks,

Rich

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


David Winsemius, MD
West Hartford, CT

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


Re: [R] Descriptive Stats from Data Frame

2011-08-30 Thread Rich Shepard

On Tue, 30 Aug 2011, David Winsemius wrote:


I think you need to go back and do your input operations again with
sep="|"


David,

  Yes, that's better. I did not know of the sep option. The new results:


str(chemdata)

'data.frame':   14886 obs. of  4 variables:
 $ site_id: Factor w/ 148 levels "BC-0.5","BC-1",..: 104 145 126 115 114
128 124 2 3 3 ...
 $ sample_date: Factor w/ 1012 levels "1980-03-01","1980-05-01",..: 432 410
423 405 398 408 401 360 366 407 ...
 $ param  : Factor w/ 8 levels "Arsenic","Calcium",..: 1 1 1 1 1 1 1 1 1
1 ...
 $ quant  : num  0.06 0.01 0.01 0.01 0.01 0.01 0.01 0.01 0.01 0.01 ...

  Now I can work on the commands I need.

Many thanks,

Rich

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/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] Descriptive Stats from Data Frame

2011-08-30 Thread David Winsemius


On Aug 30, 2011, at 5:30 PM, Rich Shepard wrote:


On Tue, 30 Aug 2011, David Winsemius wrote:

It appears that your original file was delimited by "|" and your  
used something else, perhaps the default white-space setting?


David,

 Yes, the csv file separator is the pipe.


It is _not_ a csv file. You need to use read.table with sep = "|".




I think you need to go back and do your input operations again with
sep="|"

(Or you could provide str() on the data.frame rather than making us  
guess.)



str(chemdata)

'data.frame':   14886 obs. of  1 variable:
$ site_id.sample_date.param.quant: Factor w/ 14886 levels
"BC-0.5|1996-04-19|Arsenic|0.01",..: 11579 14219 13298 11982 11909  
13371

13082 111 12 23 ...

Thanks,

Rich

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


David Winsemius, MD
West Hartford, CT

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


Re: [R] Descriptive Stats from Data Frame

2011-08-30 Thread Rich Shepard

On Tue, 30 Aug 2011, David Winsemius wrote:

It appears that your original file was delimited by "|" and your used 
something else, perhaps the default white-space setting?


David,

  Yes, the csv file separator is the pipe.


I think you need to go back and do your input operations again with
sep="|"

(Or you could provide str() on the data.frame rather than making us guess.)



str(chemdata)

'data.frame':   14886 obs. of  1 variable:
 $ site_id.sample_date.param.quant: Factor w/ 14886 levels
"BC-0.5|1996-04-19|Arsenic|0.01",..: 11579 14219 13298 11982 11909 13371
13082 111 12 23 ...

Thanks,

Rich

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/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] Descriptive Stats from Data Frame

2011-08-30 Thread Rich Shepard

On Wed, 31 Aug 2011, Tal Galili wrote:


It is a bit hard to read the "summary" you are using.  Consider please
pasting the output of:
ls.str(chemdata)


Tal,

  Yes, summary() is inappropriate. I do want str() instead. And what that
shows is:


str(chemdata)

'data.frame':   14886 obs. of  1 variable:
 $ site_id.sample_date.param.quant: Factor w/ 14886 levels
"BC-0.5|1996-04-19|Arsenic|0.01",..: 11579 14219 13298 11982 11909 13371
13082 111 12 23 ...


Regarding your question, please start and see if this work (I'm not sure,
since it seems you have made some changes to the summary output, and I am
only guessing how things look):



mean(chemdata$quant[chemdata$param > =="Arsenic"])



mean(chemdata$quant[chemdata$param > =="Arsenic"])

Error: unexpected '==' in "mean(chemdata$quant[chemdata$param > =="

mean(chemdata$quant[chemdata$param =="Arsenic"])

[1] NA
Warning message:
In mean.default(chemdata$quant[chemdata$param == "Arsenic"]) :
  argument is not numeric or logical: returning NA

  I find it easy following the syntax in the half-dozen or more books I've
read, but quite difficult to apply what I read to my own real-world data.
:-)

Thanks,

Rich

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/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] Descriptive Stats from Data Frame

2011-08-30 Thread David Winsemius


On Aug 30, 2011, at 5:00 PM, Rich Shepard wrote:

 I don't find how to do what I need to do in Dalgaard or 'R  
Cookbook', so

I'm asking here.

 I have a data frame with water chemistry data and I want to start
exploring these data. There are three factors (site, date, chemical)
associated with each measurement. The data frame looks like this:


summary(chemdata)

site_id.sample_date.param.quant


It appears that your original file was delimited by "|" and your used  
something else, perhaps the default white-space setting? I think you  
need to go back and do your input operations again with sep="|"


(Or you could provide str() on the data.frame rather than making us  
guess.)

--
David


BC-0.5|1996-04-19|Arsenic|0.01  :1
BC-0.5|1996-04-19|Calcium|76.56 :1
BC-0.5|1996-04-19|Chloride|12   :1
BC-0.5|1996-04-19|Magnesium|43.23   :1
BC-0.5|1996-04-19|Sulfate|175   :1
BC-0.5|1996-04-19|Total Dissolved Solids|460:1
(Other) :14880

 I want first to calculate (and plot) descriptive stats by chemical,
ignoring site and date and telling R to ignore missing data.  
(Incorporating
those factors will occur later.) What I have not been able to figure  
out is

how to specify the command to, for example, calculate mean and sd for
Arsenic. My floundering and thrashing includes attempts like these:


mean(chemdata.param="Arsenic")

Error in is.numeric(x) : 'x' is missing

mean(chemdata.quant, param="Arsenic")

Error in mean(chemdata.quant, param = "Arsenic") :
 object 'chemdata.quant' not found

mean(chemdata$quant, param="Arsenic")

[1] NA
Warning message:
In mean.default(chemdata$quant, param = "Arsenic") :
 argument is not numeric or logical: returning NA

 As a newcomer to R I've done a lot of reading, yet all the examples  
use
nicely structured data to illustrate the point being made. I need to  
work
with my data and learn how to specify columns and write correct  
commands for

the analyses I need. Please point me in the right direction.

Rich

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


David Winsemius, MD
West Hartford, CT

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


Re: [R] Descriptive Stats from Data Frame

2011-08-30 Thread Tal Galili
Hi Rich,

It is a bit hard to read the "summary" you are using.  Consider please
pasting the output of:
ls.str(chemdata)

Regarding your question, please start and see if this work (I'm not sure,
since it seems you have made some changes to the summary output, and I am
only guessing how things look):
mean(chemdata$quant[chemdata$param =="Arsenic"])
sd(chemdata$quant[chemdata$param =="Arsenic"])


Cheers,
Tal


Contact
Details:---
Contact me: tal.gal...@gmail.com |  972-52-7275845
Read me: www.talgalili.com (Hebrew) | www.biostatistics.co.il (Hebrew) |
www.r-statistics.com (English)
--




On Wed, Aug 31, 2011 at 12:00 AM, Rich Shepard wrote:

> mean(chemdata.param="Arsenic")

[[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] Descriptive Stats from Data Frame

2011-08-30 Thread Rich Shepard

  I don't find how to do what I need to do in Dalgaard or 'R Cookbook', so
I'm asking here.

  I have a data frame with water chemistry data and I want to start
exploring these data. There are three factors (site, date, chemical)
associated with each measurement. The data frame looks like this:


summary(chemdata)

 site_id.sample_date.param.quant
 BC-0.5|1996-04-19|Arsenic|0.01  :1
 BC-0.5|1996-04-19|Calcium|76.56 :1
 BC-0.5|1996-04-19|Chloride|12   :1
 BC-0.5|1996-04-19|Magnesium|43.23   :1
 BC-0.5|1996-04-19|Sulfate|175   :1
 BC-0.5|1996-04-19|Total Dissolved Solids|460:1
 (Other) :14880

  I want first to calculate (and plot) descriptive stats by chemical,
ignoring site and date and telling R to ignore missing data. (Incorporating
those factors will occur later.) What I have not been able to figure out is
how to specify the command to, for example, calculate mean and sd for
Arsenic. My floundering and thrashing includes attempts like these:


mean(chemdata.param="Arsenic")

Error in is.numeric(x) : 'x' is missing

mean(chemdata.quant, param="Arsenic")

Error in mean(chemdata.quant, param = "Arsenic") :
  object 'chemdata.quant' not found

mean(chemdata$quant, param="Arsenic")

[1] NA
Warning message:
In mean.default(chemdata$quant, param = "Arsenic") :
  argument is not numeric or logical: returning NA

  As a newcomer to R I've done a lot of reading, yet all the examples use
nicely structured data to illustrate the point being made. I need to work
with my data and learn how to specify columns and write correct commands for
the analyses I need. Please point me in the right direction.

Rich

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/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] Fwd: ARMA show different result between eview and R

2011-08-30 Thread John C Frain
-- Forwarded message --
From: John C Frain 
Date: 30 August 2011 21:52
Subject: Re: [R] ARMA show different result between eview and R
To: Young Gyu Park 


If you check your manuals you will find that R uses full maximum
likelihood while Eviews uses an alternative non-linear method.  Many
programs use different versions of information criteria but these are
monotone transformations (ie they all have an extreme value with the
same model. Again you need to check your manuals.

Best Regards

John

On 30 August 2011 08:21, Young Gyu Park  wrote:
> When I do ARMA(2,2) using one lag of LCPIH data
>
>
>
> This is eview result
>
>>
>> *Dependent Variable: DLCPIH
>> **Method: Least Squares
>> **Date: 08/12/11   Time: 12:44
>> **Sample (adjusted): 1970Q2 2010Q2
>> **Included observations: 161 after adjustments
>> **Convergence achieved after 14 iterations
>> **MA Backcast: 1969Q4 1970Q1
>> **
>> **Variable    Coefficient    Std. Error    t-Statistic    Prob.
>> **
>> **C    0.003361    0.001814    1.853352    0.0657
>> **DLCPIH(-1)    -0.100150    0.053160    -1.883917    0.0614
>> **DLCPIH(-2)    0.870456    0.052466    16.59075    0.
>> **MA(1)    0.532252    0.100110    5.316678    0.
>> **MA(2)    -0.379383    0.099535    -3.811566    0.0002
>> **
>> **R-squared    0.512067        Mean dependent var        0.014816
>> **Adjusted R-squared    0.499556        S.D. dependent var        0.016274
>> **S.E. of regression    0.011513        Akaike info criterion
>> -6.060182
>> **Sum squared resid    0.020676        Schwarz criterion        -5.964486
>> **Log likelihood    492.8446        Hannan-Quinn criter.        -6.021326
>> **F-statistic    40.92897        Durbin-Watson stat        2.012062
>> **Prob(F-statistic)    0.00
>> **
>> **Inverted MA Roots          .40             -.94 *
>
>
>
> This is R result
>
>
>
>> *> dlcpihTsLen <- length(ausT2Ts[,4])
>> **> dlcpihArma22Fit <- arima(ausT2Ts[,4], order=c(2,1,2),
>> xreg=1:dlcpihTsLen)
>> **> dlcpiArma22hFit <- arima(ausT2Ts[,4], order=c(2,1,2))
>> **> dlcpihArma22Fit
>> *
>> *Call:
>> **arima(x = ausT2Ts[, 4], order = c(2, 1, 2), xreg = 1:dlcpihTsLen)
>> *
>> *Coefficients:
>> **          ar1     ar2     ma1      ma2  1:dlcpihTsLen
>> **      -0.1083  0.8673  0.5263  -0.3716         0.0146
>> **s.e.   0.0493  0.0484  0.0894   0.0852         0.0041
>> *
>> *sigma^2 estimated as 0.0001282:  log likelihood = 498.38,  aic = -984.76*
>
> *
> *
>
> *
> *
>
> I wonder why the coefficient values are little bit different between them.
>
> *
> *
>
> Another thing I wonder is why the AIC value is so significantly different
> each other*.*
>
> *
> *
>
> Please help me, if anyone who have experience both of eview and R is in R
> community.
>
>
> Thank you.
>
>        [[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.
>



--
John C Frain
Economics Department
Trinity College Dublin
Dublin 2
Ireland
www.tcd.ie/Economics/staff/frainj/home.html
mailto:fra...@tcd.ie
mailto:fra...@gmail.com



-- 
John C Frain
Economics Department
Trinity College Dublin
Dublin 2
Ireland
www.tcd.ie/Economics/staff/frainj/home.html
mailto:fra...@tcd.ie
mailto:fra...@gmail.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] having trouble extracting week from chron object

2011-08-30 Thread Gabor Grothendieck
On Tue, Aug 30, 2011 at 4:43 PM, Gabor Grothendieck
 wrote:
> On Tue, Aug 30, 2011 at 1:36 PM, Christopher W Ryan
>  wrote:
>> Running R 2.13.1 on Windows XP.
>> I would like to get week of the year (1-52) for each date.
>>
>> library(chron)
>> dts <- dates(c("02/27/92", "02/27/92", "01/14/92","02/28/92", "02/01/92"))
>
> Try this:
>
> as.numeric(cut(dts, "weeks"))

although that won't label the weeks from the beginning of the year but
rather the earliest date will be labelled week 1 so you need to add a
date in the first of the year if you want that.  Alternately  try
this: as.numeric(format(as.Date(dts), "%w")) or use %W.  See ?strptime
for details.


-- 
Statistics & Software Consulting
GKX Group, GKX Associates Inc.
tel: 1-877-GKX-GROUP
email: ggrothendieck at gmail.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] RPostgreSQL Loading Issues

2011-08-30 Thread Joe Conway
On 08/30/2011 10:53 AM, Rich Shepard wrote:
> Error in dyn.load(file, DLLpath = DLLpath, ...) :
>   unable to load shared object
> '/home/rshepard/R/i486-slackware-linux-gnu-library/2.13/RPostgreSQL/libs/RPostgreSQL.so':
> 
>   libR.so: cannot open shared object file: No such file or directory
> Error: package/namespace load failed for 'RPostgreSQL'
> 
>   The shared library, of course, is present:
> 
> [rshepard@salmo
> ~/R/i486-slackware-linux-gnu-library/2.13/RPostgreSQL/libs]$ ll
> -rwxr-xr-x 1 rshepard users 44385 2011-08-03 20:13 RPostgreSQL.so*
> 
>   Can someone explain to me what's going on and how I fix it?

Just a guess, but possibly because libpq.so (the postgres client
library) is not being found.

1) Do you have libpq.so installed on your system?
2) If so, where?
3) If it is not in a standard system location (e.g. /usr/lib), try
adding an entry either to /etc/ld.so.conf or a file with the appropriate
entry in /etc/ld.so.conf.d/ and then run ldconfig

HTH,

Joe


-- 
Joe Conway
credativ LLC: http://www.credativ.us
Linux, PostgreSQL, and general Open Source
Training, Service, Consulting, & 24x7 Support

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/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] having trouble extracting week from chron object

2011-08-30 Thread Gabor Grothendieck
On Tue, Aug 30, 2011 at 1:36 PM, Christopher W Ryan
 wrote:
> Running R 2.13.1 on Windows XP.
> I would like to get week of the year (1-52) for each date.
>
> library(chron)
> dts <- dates(c("02/27/92", "02/27/92", "01/14/92","02/28/92", "02/01/92"))

Try this:

as.numeric(cut(dts, "weeks"))


-- 
Statistics & Software Consulting
GKX Group, GKX Associates Inc.
tel: 1-877-GKX-GROUP
email: ggrothendieck at gmail.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] having trouble extracting week from chron object

2011-08-30 Thread David Winsemius

You did read jannis' reply didn't you?

--  
David.

On Aug 30, 2011, at 2:34 PM, Christopher W Ryan wrote:


Here it is with the output:


library(chron)
dts <- dates(c("02/27/92", "02/27/92", "01/14/92","02/28/92",  
"02/01/92"))

dts

[1] 02/27/92 02/27/92 01/14/92 02/28/92 02/01/92

dts.chron <- as.chron(dts)
dts.chron

[1] 02/27/92 02/27/92 01/14/92 02/28/92 02/01/92

class(dts.chron)

[1] "dates" "times"

# all of these component extractions work:
months(dts.chron)

[1] Feb Feb Jan Feb Feb
12 Levels: Jan < Feb < Mar < Apr < May < Jun < Jul < Aug < Sep < ...  
< Dec

weekdays(dts.chron)

[1] Thu Thu Tue Fri Sat
Levels: Sun < Mon < Tue < Wed < Thu < Fri < Sat

years(dts.chron)

[1] 1992 1992 1992 1992 1992
Levels: 1992

quarters(dts.chron)

[1] 1Q 1Q 1Q 1Q 1Q
Levels: 1Q < 2Q < 3Q < 4Q

# but weeks() doesn't seem to work
weeks(dts.chron)

Error: could not find function "weeks"

?weeks

No documentation for 'weeks' in specified packages and libraries:
you could try '??weeks'

weeks

Error: object 'weeks' not found

week

Error: object 'week' not found


sessionInfo()

R version 2.13.1 (2011-07-08)
Platform: i386-pc-mingw32/i386 (32-bit)

locale:
[1] LC_COLLATE=English_United States.1252
[2] LC_CTYPE=English_United States.1252
[3] LC_MONETARY=English_United States.1252
[4] LC_NUMERIC=C
[5] LC_TIME=English_United States.1252

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

other attached packages:
[1] chron_2.3-42

Thanks.

--Chris Ryan


On Tue, Aug 30, 2011 at 1:54 PM, David Winsemius > wrote:


On Aug 30, 2011, at 1:36 PM, Christopher W Ryan wrote:


Running R 2.13.1 on Windows XP.
I would like to get week of the year (1-52) for each date.

library(chron)
dts <- dates(c("02/27/92", "02/27/92", "01/14/92","02/28/92",  
"02/01/92"))

dts
dts.chron <- as.chron(dts)
dts.chron
class(dts.chron)
# all of these component extractions work:
months(dts.chron)
weekdays(dts.chron)
years(dts.chron)
quarters(dts.chron)
# but weeks() doesn't seem to work


It doesn't "work" for me either but since I also have the package  
lubridate
loaded, and ?weeks brings up a lubridate help page, I don't feel I  
have any

right to complain. I get an error message what did you get?:

Error in Ops.dates(pieces$week, 7) : * not defined for chron objects

If I were posting I would also have had the good sense to include  
the output

of sessionInfo().


weeks(dts.chron)


Try type just:

 weeks  # I get a lubridate function.



?chron tells me:



Bur what does ?weeks tell you?


. . . The functions days(), months(), quarters(),
years(), weeks(), weekdays(), hours(), minutes(), and seconds() take
any chron object as input and extract the corresponding time  
interval

. . . .

Any advice?

Thanks.

Chris Ryan
SUNY Upstate Medical University Clinical Campus at Binghamton
Binghamton, NY

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


David Winsemius, MD
West Hartford, CT




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


David Winsemius, MD
West Hartford, CT

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


Re: [R] Generating a sequence of diagonal matrices

2011-08-30 Thread Joshua Wiley
Hi Meddee,

Try this:

dmat <- lapply(1:100, function(d) diag(d, 2))

That will give you a list of all 100 matrices.

Cheers,

Josh

On Tue, Aug 30, 2011 at 1:00 PM, meddee  wrote:
> I am trying to generate a sequence of diagonal matrices.
>
> In the scalar case I would use something like, seq(0,100,by=1).
>
> How do I generalise the above for , say a 2 dimensional diagonal matrix. In
> other words how do I produce the series of diagonal matrices {
> diag(0,2),diag(1,2), diag(2,2),...,diag(100,2)}?
>
> Thanks
> Meddee
>
> --
> View this message in context: 
> http://r.789695.n4.nabble.com/Generating-a-sequence-of-diagonal-matrices-tp3779623p3779623.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.
>



-- 
Joshua Wiley
Ph.D. Student, Health Psychology
Programmer Analyst II, ATS Statistical Consulting Group
University of California, Los Angeles
https://joshuawiley.com/

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


Re: [R] RPostgreSQL Loading Issues

2011-08-30 Thread Rich Shepard

On Tue, 30 Aug 2011, Joe Conway wrote:


Just a guess, but possibly because libpq.so (the postgres client
library) is not being found.


Joe,

  My initial thought, too. But, that's not it.


1) Do you have libpq.so installed on your system?
2) If so, where?
3) If it is not in a standard system location (e.g. /usr/lib), try
adding an entry either to /etc/ld.so.conf or a file with the appropriate
entry in /etc/ld.so.conf.d/ and then run ldconfig


/usr/local/pgsql/lib/libpq.so
/usr/local/pgsql/lib/libpq.so.5
/usr/local/pgsql/lib/libpq.so.5.3
/usr/lib/libpq.so
/usr/lib/libpq.so.5

  The softlinks in /usr/lib/ are to /usr/local/pgsql/lib/libpq.so.5.3.

  Since postgres-9.0.4 runs quite well here there must be some other factor
in play.

Thanks,

Rich

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/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] column names with rbind loop

2011-08-30 Thread David Winsemius


On Aug 30, 2011, at 3:46 PM, Vining, Kelly wrote:

Thanks much for your help! This almost works. However, now I am  
getting the following error:



for(i in all.files) {

+ if (i==all.files[1]) new.data <- read.table(i,header=TRUE) else {
+ new.data <- rbind(new.data, read.table(i))}}
Error in match.names(clabs, names(xi)) :
 names do not match previous names


You need to decide if you are going to use the V-names or the original  
names because rbind requires that the names for its two arguments  
match. Perhaps you want to read the names in separately with  
readLines? Also look at the skip argument to read.tables.




I am wondering if this is because R adds row numbers as a numerical  
column to the table of the first file it reads?


It does so by default. It needs to have some sort of character vector  
to use, so if there is none, it makes up names. I don't understand why  
you didn't use, ... header =TRUE, for both read operations.


--
David.





From: Weidong Gu [anopheles...@gmail.com]
Sent: Tuesday, August 30, 2011 12:00 PM
To: Vining, Kelly
Cc: r-help@r-project.org
Subject: Re: [R] column names with rbind loop

How about to add a conditional statement to get the header from 1st  
file


for(i in all.files) {
if (i==all.files[1]) new.data <- read.table(i,header=TRUE) else {
new.data <- rbind(new.data, read.table(i))}}


Weidong Gu


On Tue, Aug 30, 2011 at 1:42 PM, Vining, Kelly
 wrote:

Hello R  users.

This is a fairly basic question:

I am concatenating data from sets of files in a directory using a  
loop. The column names in all files are exactly the same. My  
understanding is that rbind takes column names from the first file  
it reads. However, my output is showing that the column names are  
treated as a first data row, not treated as headers.


I compile my file names like this:


all.files <- list.files()
all.files

[1] "1.rpkm"  "10.rpkm" "11.rpkm" "12.rpkm" "13.rpkm" "14.rpkm"
[7] "15.rpkm" "16.rpkm" "17.rpkm" "18.rpkm" "19.rpkm" "2.rpkm"
[13] "3.rpkm"  "4.rpkm"  "5.rpkm"  "6.rpkm"  "7.rpkm"  "8.rpkm"
[19] "9.rpkm"

Then loop through them like this:

new.data <- NULL
for(i in all.files) {

+ in.data <- read.table(i)
+ new.data <- rbind(new.data, in.data)}

head(new.data)

   V1   V2V3 V4 V5V6 V7
1 seq_id   source  type  startend score strand
2 scaffold_1 Ptrichocarpav2_0 gene_body  12639  13384 .  +
3 scaffold_1 Ptrichocarpav2_0 gene_body  22190  22516 .  +
4 scaffold_1 Ptrichocarpav2_0 gene_body  74076 75893 .  +
5 scaffold_1 Ptrichocarpav2_0 gene_body  80207  81289 .  -
6 scaffold_1 Ptrichocarpav2_0 gene_body 105236 107712 .  +


As you can see, R is putting a "V1, V2..." header row here because  
I didn't say "header=TRUE" in my read.table command. But if I do  
this within the loop, I get an error. If I try to delete the V1, V2  
row after the fact by


new.data <- new.data[-1,]

R deletes my "real" header row.

How can I get the header that I want?

Thanks for any help,
--Kelly V.

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


David Winsemius, MD
West Hartford, CT

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


[R] Generating a sequence of diagonal matrices

2011-08-30 Thread meddee
I am trying to generate a sequence of diagonal matrices.

In the scalar case I would use something like, seq(0,100,by=1).

How do I generalise the above for , say a 2 dimensional diagonal matrix. In
other words how do I produce the series of diagonal matrices {
diag(0,2),diag(1,2), diag(2,2),...,diag(100,2)}?

Thanks
Meddee

--
View this message in context: 
http://r.789695.n4.nabble.com/Generating-a-sequence-of-diagonal-matrices-tp3779623p3779623.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] Fwd: help with "by" command

2011-08-30 Thread amalka
Thanks very much for the help.

I ended up getting it to work with one small change:

by(foo, foo$V2, function(foo) mean(foo$trust, na.rm=T)) 

thanks again,
Ari

--
View this message in context: 
http://r.789695.n4.nabble.com/help-with-by-command-tp3766285p3779622.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] gradient function in OPTIMX

2011-08-30 Thread Rubén Roa
Hi,

In my package CatDyn, which uses optimx, I included the gradients of 20 version 
of the model involved.
I estimate model parameters with numerical gradients, and at the final 
estimates I calculate the analytical gradients.
In the simplest version of the model the analytical gradients computed post hoc 
are almost identical to the numerical gradients. This shows that the analytical 
gradients (whose formulas were obtained by the CAS Maxima) are correct, at 
least for those simple versions of my model. However, if I try to pass the 
analytical gradients to optimx in a new optimization, I invariably get the 
error message that you got: "Gradient function might be wrong - check it!"
This happens regardless of the method used (BFGS, spg, Rcgmin).
Same as you, when I try to pass the gradients to optim, instead of optimx, the 
gradients are accepted and computed correctly, but then I cann't use the very 
nice other features of optimx.
I wanted to report this to Ravi and Prof. Nash but I haven't got the time for a 
full report with several examples and variations.
So now that you report it, here I am, seconding you in calling the attention to 
this apparent problem in optimx.

Rubén H. Roa-Ureta, Ph. D.
AZTI Tecnalia, Txatxarramendi Ugartea z/g,
Sukarrieta, Bizkaia, SPAIN

-Original Message-
From: r-help-boun...@r-project.org on behalf of Kathie
Sent: Mon 8/29/2011 11:10 AM
To: r-help@r-project.org
Subject: [R] gradient function in OPTIMX
 
Dear R users

When I use OPTIM with BFGS, I've got a significant result without an error
message.  However, when I use OPTIMX with BFGS( or spg), I've got the
following an error message.



>  optimx(par=theta0, fn=obj.fy, gr=gr.fy, method="BFGS",
> control=list(maxit=1))

Error: Gradient function might be wrong - check it! 



I checked and checked my gradient function line by line. I could not find
anything wrong.

Is it a bug or something?  I prefer OPTIMX, so I'd like to know why.

Thanks a lot in advance

Regards,

Kathryn Lord 

--
View this message in context: 
http://r.789695.n4.nabble.com/gradient-function-in-OPTIMX-tp3775791p3775791.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.


[[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] locate the needed columns

2011-08-30 Thread Weidong Gu
If the pattern is characterized by capital letters as your sample
suggests. The following code may help

df<-list()
names(d) = c("A.x", "B.x", "C.x", "A.y", "B.y", "C.y")
group.v<-matrix(NA,nrow=3,ncol=2) ### you may need to modify nrow and ncol
for (i in 1:3) {
group.v[i,]<-names(d)[grep(LETTERS[i],names(d))]
df[i]<-d[,names(d)%in% group.v[i]]
}


Weidong Gu

On Tue, Aug 30, 2011 at 2:31 PM, Hui Du  wrote:
>
> Hi All,
>
>                I have a data frame, whose colnames like "A.x, B.x, C.x, A.y, 
> B.y, C.y". There could be many columns like this pattern. I want to compare 
> data in columns A.x with A.y, B.x with B.y and C.x with C.y etc.
> Suppose my data frame is d,
> names(d) = c("A.x", "B.x", "C.x", "A.y", "B.y", "C.y");
>
> If I want to
> D1 = data.frame(d$A.x, d$A.y);
> D2 = data.frame(d$B.x, d$B.y); etc. or do other operation for each pair,
>
>
> What is elegant way to do it rather than use a loop?
>
> Thanks.
>
> HXD
>
>
>        [[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] column names with rbind loop

2011-08-30 Thread Vining, Kelly
Thanks much for your help! This almost works. However, now I am getting the 
following error:

> for(i in all.files) {
+ if (i==all.files[1]) new.data <- read.table(i,header=TRUE) else {
+ new.data <- rbind(new.data, read.table(i))}}
Error in match.names(clabs, names(xi)) : 
  names do not match previous names

I am wondering if this is because R adds row numbers as a numerical column to 
the table of the first file it reads?



From: Weidong Gu [anopheles...@gmail.com]
Sent: Tuesday, August 30, 2011 12:00 PM
To: Vining, Kelly
Cc: r-help@r-project.org
Subject: Re: [R] column names with rbind loop

How about to add a conditional statement to get the header from 1st file

for(i in all.files) {
if (i==all.files[1]) new.data <- read.table(i,header=TRUE) else {
new.data <- rbind(new.data, read.table(i))}}


Weidong Gu


On Tue, Aug 30, 2011 at 1:42 PM, Vining, Kelly
 wrote:
> Hello R  users.
>
> This is a fairly basic question:
>
> I am concatenating data from sets of files in a directory using a loop. The 
> column names in all files are exactly the same. My understanding is that 
> rbind takes column names from the first file it reads. However, my output is 
> showing that the column names are treated as a first data row, not treated as 
> headers.
>
> I compile my file names like this:
>
>> all.files <- list.files()
>> all.files
>  [1] "1.rpkm"  "10.rpkm" "11.rpkm" "12.rpkm" "13.rpkm" "14.rpkm"
>  [7] "15.rpkm" "16.rpkm" "17.rpkm" "18.rpkm" "19.rpkm" "2.rpkm"
> [13] "3.rpkm"  "4.rpkm"  "5.rpkm"  "6.rpkm"  "7.rpkm"  "8.rpkm"
> [19] "9.rpkm"
>
> Then loop through them like this:
>> new.data <- NULL
>> for(i in all.files) {
> + in.data <- read.table(i)
> + new.data <- rbind(new.data, in.data)}
>> head(new.data)
> V1   V2V3 V4 V5V6 V7
> 1 seq_id   source  type  startend score strand
> 2 scaffold_1 Ptrichocarpav2_0 gene_body  12639  13384 .  +
> 3 scaffold_1 Ptrichocarpav2_0 gene_body  22190  22516 .  +
> 4 scaffold_1 Ptrichocarpav2_0 gene_body  74076 75893 .  +
> 5 scaffold_1 Ptrichocarpav2_0 gene_body  80207  81289 .  -
> 6 scaffold_1 Ptrichocarpav2_0 gene_body 105236 107712 .  +
>
>
> As you can see, R is putting a "V1, V2..." header row here because I didn't 
> say "header=TRUE" in my read.table command. But if I do this within the loop, 
> I get an error. If I try to delete the V1, V2 row after the fact by
>
> new.data <- new.data[-1,]
>
> R deletes my "real" header row.
>
> How can I get the header that I want?
>
> Thanks for any help,
> --Kelly V.
>
> __
> R-help@r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/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] splitting into multiple dataframes and then create a loop to work

2011-08-30 Thread Nilaya Sharma
Thank you for the help. My focus was to split data frame for a different
function, not lm. I could provide detail of that lengthy function instead I
provided the lm function.

The comment were very helpful.

Thanks;

NIL

On Mon, Aug 29, 2011 at 3:37 PM, Dimitris Rizopoulos <
d.rizopou...@erasmusmc.nl> wrote:

> well, if a pooled estimate of the residual standard error is not desirable,
> then you just need to set argument 'pool' of lmList() to FALSE, e.g.,
>
> mlis <- lmList(yvar ~ .  - clvar | clvar, data = df, pool = FALSE)
> summary(mlis)
>
>
> Best,
> Dimitris
>
>
>
> On 8/29/2011 9:20 PM, Dennis Murphy wrote:
>
>> Hi:
>>
>> Dimitris' solution is appropriate, but it needs to be mentioned that
>> the approach I offered earlier in this thread differs from the
>> lmList() approach. lmList() uses a pooled measure of error MSE (which
>> you can see at the bottom of the output from summary(mlis) ), whereas
>> the plyr approach subdivides the data into distinct sub-data frames
>> and analyzes them as separate entities. As a result, the residual MSEs
>> will differ between the two approaches, which in turn affects the
>> significance tests on the model coefficients. You need to decide which
>> approach is better for your purposes.
>>
>> Cheers,
>> Dennis
>>
>> On Mon, Aug 29, 2011 at 12:02 PM, Dimitris Rizopoulos
>>   wrote:
>>
>>> You can do this using function lmList() from package nlme, without having
>>> to
>>> split the data frames, e.g.,
>>>
>>> library(nlme)
>>>
>>> mlis<- lmList(yvar ~ .  - clvar | clvar, data = df)
>>> mlis
>>> summary(mlis)
>>>
>>>
>>> I hope it helps.
>>>
>>> Best,
>>> Dimitris
>>>
>>>
>>> On 8/29/2011 5:37 PM, Nilaya Sharma wrote:
>>>

 Dear All

 Sorry for this simple question, I could not solve it by spending days.

 My data looks like this:

 # data
 set.seed(1234)
 clvar<- c( rep(1, 10), rep(2, 10), rep(3, 10), rep(4, 10)) # I have 100
 level for this factor var;
 yvar<-  rnorm(40, 10,6);
 var1<- rnorm(40, 10,4); var2<- rnorm(40, 10,4); var3<- rnorm(40, 5, 2);
 var4<- rnorm(40, 10, 3); var5<- rnorm(40, 15, 8) # just example
 df<- data.frame(clvar, yvar, var1, var2, var3, var4, var5)

 # manual splitting
 df1<- subset(df, clvar == 1)
 df2<- subset(df, clvar == 2)
 df3<- subset(df, clvar == 3)
 df4<- subset(df, clvar == 4)
 df5<- subset(df, clvar == 5)

 # i tried to mechanize it
 *

 for(i in 1:5) {

   df[i]<- subset(df, clvar == i)

 }

 I know it should not work as df[i] is single variable, do it did. But I
 could not find away to output multiple dataframes from this loop. My
 limited
 R knowledge, did not help at all !

 *

 # working on each of variable, just trying simple function
  a<- 3:8
 out1<- lapply(1:5, function(ind){
lm(df1$yvar ~ df1[, a[ind]])
  })
 p1<- lapply(out1, function(m)summary(m)$**coefficients[,4][2])
 p1<- do.call(rbind, p1)


 My ultimate objective is to apply this function to all the dataframes
 created (i.e. df1, df2, df3, df4, df5) and create five corresponding
 p-value
 vectors (p1, p2, p3, p4, p5). Then output would be a matrix of clvar and
 correponding p values
 clvar   var1   var2  var3  var4   var5
 1
 2
 3
 4

 Please help me !

 Thanks

 NIL

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


>>> --
>>> Dimitris Rizopoulos
>>> Assistant Professor
>>> Department of Biostatistics
>>> Erasmus University Medical Center
>>>
>>> Address: PO Box 2040, 3000 CA Rotterdam, the Netherlands
>>> Tel: +31/(0)10/7043478
>>> Fax: +31/(0)10/7043014
>>> Web: 
>>> http://www.erasmusmc.nl/**biostatistiek/
>>>
>>> __**
>>> R-help@r-project.org mailing list
>>> https://stat.ethz.ch/mailman/**listinfo/r-help
>>> PLEASE do read the posting guide http://www.R-project.org/**
>>> posting-guide.html 
>>> and provide commented, minimal, self-contained, reproducible code.
>>>
>>>
>>
> --
> Dimitris Rizopoulos
> Assistant Professor
> Department of Biostatistics
> Erasmus University Medical Center
>
> Address: PO Box 2040, 3000 CA Rotterdam, the Netherlands
> Tel: +31/(0)10/7043478
> Fax: +31/(0)10/7043014
> Web: 
> http://www.erasmusmc.nl/**biostatistiek/
>

[[al

Re: [R] Multiple Traveling Salesperson Problem

2011-08-30 Thread Michael Hahsler

Hi Ian,

There is currently no support for the mTSP in tsp.
The paper

Tolga Bektas, The multiple traveling salesman problem: an overview of 
formulations and solution procedures, Omega, 34(3), June 2006, Pages 209-219


describes some methods to reformulate a mTSP as a regular TSP. However, 
I had no time to look at those...


-Michael

--
  Dr. Michael Hahsler, Visiting Assistant Professor
  Department of Computer Science and Engineering
  Lyle School of Engineering
  Southern Methodist University, Dallas, Texas

  (214) 768-8878 * mhahs...@lyle.smu.edu * http://lyle.smu.edu/~mhahsler

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

2011-08-30 Thread Qian Liu
Hi I need some help with ploting the ROC for K-nearest neighbors. Since KNN
is a non-parametric classification methods, the predicted value will be
either 0 or 1.
It will not be able to test for different cutoff to plot ROC. What is the
package or functions I should use to plot ROC for KNN?

Thanks.
Qian

[[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] column names with rbind loop

2011-08-30 Thread Weidong Gu
How about to add a conditional statement to get the header from 1st file

for(i in all.files) {
if (i==all.files[1]) new.data <- read.table(i,header=TRUE) else {
new.data <- rbind(new.data, read.table(i))}}


Weidong Gu


On Tue, Aug 30, 2011 at 1:42 PM, Vining, Kelly
 wrote:
> Hello R  users.
>
> This is a fairly basic question:
>
> I am concatenating data from sets of files in a directory using a loop. The 
> column names in all files are exactly the same. My understanding is that 
> rbind takes column names from the first file it reads. However, my output is 
> showing that the column names are treated as a first data row, not treated as 
> headers.
>
> I compile my file names like this:
>
>> all.files <- list.files()
>> all.files
>  [1] "1.rpkm"  "10.rpkm" "11.rpkm" "12.rpkm" "13.rpkm" "14.rpkm"
>  [7] "15.rpkm" "16.rpkm" "17.rpkm" "18.rpkm" "19.rpkm" "2.rpkm"
> [13] "3.rpkm"  "4.rpkm"  "5.rpkm"  "6.rpkm"  "7.rpkm"  "8.rpkm"
> [19] "9.rpkm"
>
> Then loop through them like this:
>> new.data <- NULL
>> for(i in all.files) {
> + in.data <- read.table(i)
> + new.data <- rbind(new.data, in.data)}
>> head(new.data)
>         V1               V2        V3     V4     V5    V6     V7
> 1     seq_id           source      type  start    end score strand
> 2 scaffold_1 Ptrichocarpav2_0 gene_body  12639  13384     .      +
> 3 scaffold_1 Ptrichocarpav2_0 gene_body  22190  22516     .      +
> 4 scaffold_1 Ptrichocarpav2_0 gene_body  74076 75893     .      +
> 5 scaffold_1 Ptrichocarpav2_0 gene_body  80207  81289     .      -
> 6 scaffold_1 Ptrichocarpav2_0 gene_body 105236 107712     .      +
>
>
> As you can see, R is putting a "V1, V2..." header row here because I didn't 
> say "header=TRUE" in my read.table command. But if I do this within the loop, 
> I get an error. If I try to delete the V1, V2 row after the fact by
>
> new.data <- new.data[-1,]
>
> R deletes my "real" header row.
>
> How can I get the header that I want?
>
> Thanks for any help,
> --Kelly V.
>
> __
> R-help@r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/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] ATSP to TSP reformulation

2011-08-30 Thread Ian Deters
It worked fabulously.  Thank you so much for help and time.

--
View this message in context: 
http://r.789695.n4.nabble.com/ATSP-to-TSP-reformulation-tp3777105p3779476.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] Error in f(x, ...) : could not find function "f2"

2011-08-30 Thread Uwe Ligges



On 30.08.2011 14:31, . . wrote:

Hi all,

I am getting the erro showed in the subject. I was strange the this
becomes to happen after a computer restar. I think after the restart
another function f2 was in memory and it scape from me.

func<- Vectorize(FUN=
   function(y, frac, rate, sad, samp="Poisson", trunc=0, ...){
f0<- function(y,frac,n) {
f1<- function(y,frac,n){
dpois(y,frac*n)
}
dcom<- paste("d",deparse(substitute(sad)),sep="")
dots<- c(as.name("n"),list(...))
f2<- call(dcom,dots)
f<- function(n){
f1(y,frac,n)*f2(n)
}


". .", obviously f2 is a call rather than a function.

Uwe Ligges




myintegrate<- function() {
r<- 0
r1<- 1
x1<- 0
dx<- 20
while(r1>  10e-500) {
r1<- integrate(f,x1,x1+dx)$value
r<- r + r1
x1<- x1 + dx
}
integrate(f,x1,Inf)$valu
}
myintegrate()
}
f0(y,frac,n)/(1-f0(trunc,frac,n))
},"y")

func(10, 0.1, 0.1, exp)

Any idea?

Thanks in advance.

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/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 does loading saved/cached objects add significantly to RAM consumption?

2011-08-30 Thread Henrik Bengtsson
Hi.

On Tue, Aug 30, 2011 at 3:59 AM, Janko Thyson
 wrote:
> Dear list,
>
> I make use of cached objects extensively for time consuming computations and
> yesterday I happened to notice some very strange behavior in that respect:
> When I execute a given computation whose result I'd like to cache (tried
> both saving it as '.Rdata' and via package 'R.cache' which uses a own
> filetype '.Rcache'),

Just to clarify, it is just the filename extension that is "custom";
it uses base::save() internally.  It is very unlikely that R.cache has
to do with your problem.

> my R session consumes about 200 MB of RAM, which is
> fine. Now, when I make use of the previously cached object (i.e. loading it,
> assigning it to a certain field of a Reference Class object), I noticed that
> RAM consumption of my R process jumps to about 250 MB!
> a
> Each new loading of cached/saved objects adds to that consumption (in total,
> I have about 5-8 objects that are processed this way), so at some point I
> easily get a RAM consumption of over 2 GB where I'm only at about 200 MB of
> consumption when I compute each object directly! Object sizes (checked with
> 'object.size()') remain fairly constant. What's even stranger: after loading
> cached objects and removing them (either via 'rm()' or by assigning a
> 'fresh' empty object to the respective Reference Class field, RAM
> consumption remains at this high level and never comes down again.
>
> I checked the behavior also in a small example which is a simplification of
> my use case and which you'll find below (checked both on Win XP and Win 7 32
> bit). I couldn't quite reproduce an immediate increase in RAM consumption,

I couldn't reproduce it either using sessionInfo():

R version 2.13.1 Patched (2011-08-29 r56823)
Platform: x86_64-pc-mingw32/x64 (64-bit)
locale:
[1] LC_COLLATE=English_United States.1252
[2] LC_CTYPE=English_United States.1252
[3] LC_MONETARY=English_United States.1252
[4] LC_NUMERIC=C
[5] LC_TIME=English_United States.1252
attached base packages:
[1] stats graphics  grDevices utils datasets  methods   base
loaded via a namespace (and not attached):
[1] tools_2.13.1

> but what I still find really strange is
> a) why do repeated 'load()' calls result in an increase in RAM consumption?
> b) why does the latter not go down again after the objects have been removed
> from '.GlobalEnv'?

Removed objects may still sit in memory - it is only when R's garbage
collector (GC) comes around and removes them that the memory usage
goes down.  You can force the garbage collector to run by calling
gc(), but normally it is automatically triggered whenever needed.

Note that the GC will only be able to clean up the memory of removed
objects IFF there are no other references to that object/piece of
memory.  When you use References classes (cf. setRefClass()) and
environments, you end up keeping references internally in objects
without being aware of it.  My guess is that your other code may have
such issues, whereas the code below does not.

There is also the concept of "promises" [see 'R Language Definition'
document], which *may* also be involved.

FYI, the Sysinternals Process Explorer
[http://technet.microsoft.com/en-us/sysinternals/bb896653] is a useful
tool for studying individual processes such as R.

My $.02

Henrik

>
> Did anyone of you experience a similar behavior? Or even better, does anyone
> know why this is happening and how it might be fixed (or be worked around)?
> ;-)
>
> I really need your help on this one as it's crucial for my thesis, thanks a
> lot for anyone replying!!
>
> Regards,
> Janko
>
> # EXAMPLE #
>
> setRefClass("A", fields=list(.PRIMARY="environment"))
> setRefClass("Test", fields=list(a="A"))
>
> obj.1 <- lapply(1:5000, function(x){
>    rnorm(x)
> })
> names(obj.1) <- paste("sample", 1:5000, sep=".")
> obj.1 <- as.environment(obj.1)
>
> test <- new("Test", a=new("A", .PRIMARY=obj.1))
> test$a$.PRIMARY$sample.10
>
> #+
>
> object.size(test)
> object.size(test$a)
> object.size(obj.1)
> # RAM used by R session: 118 MB
>
> save(obj.1, file="C:/obj.1.Rdata")
> # Results in an object of ca. 94 MB
> save(test, file="C:/test.Rdata")
> # Results in an object of ca. 94 MB
>
> # START A NEW R SESSION #
>
> load("C:/test.Rdata")
> # RAM consumption still fine at 115 - 118 MB
>
> # But watch how it goes up as we repeatedly load objects
> for(x in 1:5){
>    load("C:/test.Rdata")
> }
> for(x in 1:5){
>    load("C:/obj.1.Rdata")
> }
> # Somehow there seems to be an upper limit, though
>
> # Removing the objects does not bring down RAM consumption
> rm(obj.1)
> rm(test)
>
> ##
>
>> Sys.info()
>                     sysname                      release
>                   "Windows"                         "XP"
>                     version                     nodename
> "build 2600, Service Pack 3"               "ASHB-109C-02"
>                     machine                        login
>                       "x86"            

Re: [R] having trouble extracting week from chron object

2011-08-30 Thread Christopher W Ryan
Here it is with the output:

> library(chron)
> dts <- dates(c("02/27/92", "02/27/92", "01/14/92","02/28/92", "02/01/92"))
> dts
[1] 02/27/92 02/27/92 01/14/92 02/28/92 02/01/92
> dts.chron <- as.chron(dts)
> dts.chron
[1] 02/27/92 02/27/92 01/14/92 02/28/92 02/01/92
> class(dts.chron)
[1] "dates" "times"
> # all of these component extractions work:
> months(dts.chron)
[1] Feb Feb Jan Feb Feb
12 Levels: Jan < Feb < Mar < Apr < May < Jun < Jul < Aug < Sep < ... < Dec
> weekdays(dts.chron)
[1] Thu Thu Tue Fri Sat
Levels: Sun < Mon < Tue < Wed < Thu < Fri < Sat
> years(dts.chron)
[1] 1992 1992 1992 1992 1992
Levels: 1992
> quarters(dts.chron)
[1] 1Q 1Q 1Q 1Q 1Q
Levels: 1Q < 2Q < 3Q < 4Q
> # but weeks() doesn't seem to work
> weeks(dts.chron)
Error: could not find function "weeks"
> ?weeks
No documentation for 'weeks' in specified packages and libraries:
you could try '??weeks'
> weeks
Error: object 'weeks' not found
> week
Error: object 'week' not found
>
> sessionInfo()
R version 2.13.1 (2011-07-08)
Platform: i386-pc-mingw32/i386 (32-bit)

locale:
[1] LC_COLLATE=English_United States.1252
[2] LC_CTYPE=English_United States.1252
[3] LC_MONETARY=English_United States.1252
[4] LC_NUMERIC=C
[5] LC_TIME=English_United States.1252

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

other attached packages:
[1] chron_2.3-42

Thanks.

--Chris Ryan


On Tue, Aug 30, 2011 at 1:54 PM, David Winsemius  wrote:
>
> On Aug 30, 2011, at 1:36 PM, Christopher W Ryan wrote:
>
>> Running R 2.13.1 on Windows XP.
>> I would like to get week of the year (1-52) for each date.
>>
>> library(chron)
>> dts <- dates(c("02/27/92", "02/27/92", "01/14/92","02/28/92", "02/01/92"))
>> dts
>> dts.chron <- as.chron(dts)
>> dts.chron
>> class(dts.chron)
>> # all of these component extractions work:
>> months(dts.chron)
>> weekdays(dts.chron)
>> years(dts.chron)
>> quarters(dts.chron)
>> # but weeks() doesn't seem to work
>
> It doesn't "work" for me either but since I also have the package lubridate
> loaded, and ?weeks brings up a lubridate help page, I don't feel I have any
> right to complain. I get an error message what did you get?:
>
> Error in Ops.dates(pieces$week, 7) : * not defined for chron objects
>
> If I were posting I would also have had the good sense to include the output
> of sessionInfo().
>
>> weeks(dts.chron)
>
> Try type just:
>
>  weeks  # I get a lubridate function.
>
>>
>> ?chron tells me:
>
>
> Bur what does ?weeks tell you?
>
>> . . . The functions days(), months(), quarters(),
>> years(), weeks(), weekdays(), hours(), minutes(), and seconds() take
>> any chron object as input and extract the corresponding time interval
>> . . . .
>>
>> Any advice?
>>
>> Thanks.
>>
>> Chris Ryan
>> SUNY Upstate Medical University Clinical Campus at Binghamton
>> Binghamton, NY
>>
>> __
>> R-help@r-project.org mailing list
>> https://stat.ethz.ch/mailman/listinfo/r-help
>> PLEASE do read the posting guide
>> http://www.R-project.org/posting-guide.html
>> and provide commented, minimal, self-contained, reproducible code.
>
> David Winsemius, MD
> West Hartford, CT
>
>

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


[R] locate the needed columns

2011-08-30 Thread Hui Du

Hi All,

I have a data frame, whose colnames like "A.x, B.x, C.x, A.y, 
B.y, C.y". There could be many columns like this pattern. I want to compare 
data in columns A.x with A.y, B.x with B.y and C.x with C.y etc.
Suppose my data frame is d,
names(d) = c("A.x", "B.x", "C.x", "A.y", "B.y", "C.y");

If I want to
D1 = data.frame(d$A.x, d$A.y);
D2 = data.frame(d$B.x, d$B.y); etc. or do other operation for each pair,


What is elegant way to do it rather than use a loop?

Thanks.

HXD


[[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] rpart: apply tree to new data to get "counts"

2011-08-30 Thread Stephen Milborrow

Jay  het geskryf

When I have made a decision tree with rpart, is it possible to "apply"
this tree to a new set of data in order to find out the distribution
of observations? Ideally I would like to plot my original tree, with
the counts (at each node) of the new data.


Sadly, neither plot.rpart or rpart.plot support plotting a tree trained on 
one set of data but showing results predicted for a new set of data.  Page 
21 of the vignette for the rpart.plot package has this to say


"Arguably the most serious limitation of the current implementation is its 
inability to display results on test data (on the tree derived from the 
training data)."


One way of implementing this (quite a lot of work) would be to extend the 
rpart function to include a newdata argument.  If given such an argument, 
rpart would additionally return new.frame, new.where, and new.y fields 
(corresponding to the existing frame, where, and y fields).  The plotting 
functions could then trivially be extended to use these new fields.


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

2011-08-30 Thread Michael Hahsler

Hi Ian,

I checked your example again and found the problem in tsp. fix(x) seems 
to create column names but not row names which exposes a bug in as.ATSP 
in tsp.


This code replicates your error message:

library(TSP)
x <- rbind(c(1,2,3,4), c(1,0,11,5), c(2,4,0,6), c(3,5,6,0))
colnames(x) <- 1:4
#rownames(x) <- 1:4
atsp <- ATSP(x)
tsp <- reformulate_ATSP_as_TSP(atsp)

if you uncomment the rownames line then it works. I already fixed the 
code in tsp to check for missing col/row names in the matrix. This fix 
will be part of the next release. For now please just add row names to 
the matrix.


Thanks for the bug report!

-Michael

--
  Dr. Michael Hahsler, Visiting Assistant Professor
  Department of Computer Science and Engineering
  Lyle School of Engineering
  Southern Methodist University, Dallas, Texas

  (214) 768-8878 * mhahs...@lyle.smu.edu * http://lyle.smu.edu/~mhahsler

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/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] character vector to text with returns

2011-08-30 Thread Ben qant
David,

Yes, I understand that cat() won't do what I want, but that is the only way
I can illustrate what I am after. Note the phrasing in my question:
'...cat() like...'

Regarding assigning the paste  to a variable: it produces the same error.
I've already tried that.

Thanks for your suggestion!

Ben

On Tue, Aug 30, 2011 at 11:24 AM, David Winsemius wrote:

>
> On Aug 30, 2011, at 1:09 PM, Ben qant wrote:
>
>  Hello,
>>
>> (Sorry if this is a dup post...)
>>
>> I need to clarify, Henrique's suggestion worked great for getting the text
>> that I needed via cat(), but I haven't sorted out how to get cat() like
>> output into a variable so I can pass it into the message body variable I
>> am
>> using.
>>
>
> cat() is not the right function to get text assgned to an object. It's
> entire purpose is to have a side-effect and _not_ return anything into R's
> workspace. Why are you not assigning the result of that paste operation to
> the variable?
>
>
>
>
>> Here is what I mean:
>> x
>> [1] "a" "b" "c" "d"
>> paste(x,collapse='\n')
>> [1] "a\nb\nc\nd"
>> y = paste(x,collapse='\n')
>> cat(y)
>> a
>> b
>> c
>> d
>>
>> This is the problem with 'y' has the msg body:
>>
>> paste("msg = MIMEText('",y,"')",sep="")
>> [1] "msg = MIMEText('a\nb\nc\nd')"
>>
>> This is what I am after (I think!):
>>
>> paste("msg = MIMEText('",y,"')",sep="")
>> [1] "msg = MIMEText('a
>> b
>> c
>> d')"
>>
>>
>> Here is how I am actually using it (with sensitive items generalized):
>>
>> require(rJython)
>> rJython <- rJython()
>> rJython$exec( "import smtplib" )
>> rJython$exec("from email.MIMEText import MIMEText")
>> rJython$exec("import email.utils")
>>
>> mail<-c(
>> #Email settings
>> "fromaddr = 'ccqu...@gmail.com'",
>> "toaddrs  = 'userna...@somethinghere.com'"
>> - Show quoted text -
>> jython.exec(rJython,mail)  # and here is the error I get.
>>
>> Error in ls(envir = envir, all.names = private) :
>>  invalid 'envir' argument
>>
>>
>> Just in case someone asks, I can do this:
>>
>> y = "a test"
>>
>> ...and the above email sends fine with 'a test' as the msg body.
>>
>> Any ideas?
>>
>> PS - I received lots of suggestions. Thank you very much for your
>> effort/input.
>>
>> Ben
>>
>>
>> On Mon, Aug 29, 2011 at 6:01 PM, Henrique Dallazuanna > >wrote:
>>
>>  Try:
>>>
>>> paste(c("a", "b", "c"), collapse = "\n")
>>>
>>> On Mon, Aug 29, 2011 at 8:56 PM, Ben qant  wrote:
>>>
>>>  Hello,

 Does anyone know how to convert this:

> msg
>
 [1] "a"
 [2] "b"
 [3] "c"


 To:

  msg
>
 "a
 b
 c"

 In other words, I need to convert a character vector to a single string
 with
 carriage returns for each row.

 Functionally, I'm attempting to send an email of a character vector in a
 way
 that is readable in the email body. I can only input one string as the
 message body parameter. I'm using rJython to send the email because I
 need
 authentication.

 Thanks!

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


>>>
>>>
>>> --
>>> Henrique Dallazuanna
>>> Curitiba-Paraná-Brasil
>>> 25° 25' 40" S 49° 16' 22" O
>>>
>>>
>>[[alternative HTML version deleted]]
>>
>> __**
>> R-help@r-project.org mailing list
>> https://stat.ethz.ch/mailman/**listinfo/r-help
>> PLEASE do read the posting guide http://www.R-project.org/**
>> posting-guide.html 
>> and provide commented, minimal, self-contained, reproducible code.
>>
>
> David Winsemius, MD
> West Hartford, CT
>
>

[[alternative HTML version deleted]]

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


[R] lubridate and intervals

2011-08-30 Thread Justin Haynes
Hiya,

maybe there is a native R function for this and if so please let me know!

I have 2 data.frames with start and end dates, they read in as strings and I
am converting to POSIXct.  How can I check for overlap?

The end result ideally will be a single data.frame containing all the
columns of the other two with rows where there were date overlaps.


df1<-data.frame(start=as.POSIXct(paste('2011-06-01 ',1:20,':00',sep='')),
end=as.POSIXct(paste('2011-06-01 ',1:20,':30',sep='')))
df2<-data.frame(start=as.POSIXct(paste('2011-06-01
',rep(seq(1,20,2),2),':',sample(1:19,20,replace=T),sep='')),
end=as.POSIXct(paste('2011-06-01
',rep(seq(1,20,2),2),':',sample(20:50,20),sep='')))

I tried:
library(lubridate)

df1$interval<-new_interval(df1$start,df1$end)

> df1$interval[1]
[1] 2011-06-01 01:00:00 -- 2011-06-01 01:30:00
> df2$start[1]
[1] "2011-06-01 01:17:00 PDT"

but

> df2$start[1] %in% df1$interval[1]
[1] FALSE
>

This must be fairly straight forward and I just don't know where to look!


Thanks,
Justin

[[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] RPostgreSQL Loading Issues

2011-08-30 Thread Rich Shepard

  I'm starting to seriously use R and have tried to solve this issue using
my reference books but I'm missing something simple. Running R-2.13.1 on
Slackware-13.1.

  Trying to invoke RPostgreSQL so I can copy data from a postgres table to
an R data-frame. I installed RPostgreSQL and the library() command shows
it's present:

Packages in library
'/home/rshepard/R/i486-slackware-linux-gnu-library/2.13':

DBI R Database Interface
RPostgreSQL R interface to the PostgreSQL database system

  Yet, trying to load it fails:


library(RPostgreSQL)

Loading required package: DBI
Error in dyn.load(file, DLLpath = DLLpath, ...) :
  unable to load shared object
'/home/rshepard/R/i486-slackware-linux-gnu-library/2.13/RPostgreSQL/libs/RPostgreSQL.so':
  libR.so: cannot open shared object file: No such file or directory
Error: package/namespace load failed for 'RPostgreSQL'

  The shared library, of course, is present:

[rshepard@salmo ~/R/i486-slackware-linux-gnu-library/2.13/RPostgreSQL/libs]$ ll
-rwxr-xr-x 1 rshepard users 44385 2011-08-03 20:13 RPostgreSQL.so*

  Can someone explain to me what's going on and how I fix it?

Rich

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/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] having trouble extracting week from chron object

2011-08-30 Thread David Winsemius


On Aug 30, 2011, at 1:36 PM, Christopher W Ryan wrote:


Running R 2.13.1 on Windows XP.
I would like to get week of the year (1-52) for each date.

library(chron)
dts <- dates(c("02/27/92", "02/27/92", "01/14/92","02/28/92",  
"02/01/92"))

dts
dts.chron <- as.chron(dts)
dts.chron
class(dts.chron)
# all of these component extractions work:
months(dts.chron)
weekdays(dts.chron)
years(dts.chron)
quarters(dts.chron)
# but weeks() doesn't seem to work


It doesn't "work" for me either but since I also have the package  
lubridate loaded, and ?weeks brings up a lubridate help page, I don't  
feel I have any right to complain. I get an error message what did  
you get?:


Error in Ops.dates(pieces$week, 7) : * not defined for chron objects

If I were posting I would also have had the good sense to include the  
output of sessionInfo().



weeks(dts.chron)


Try type just:

 weeks  # I get a lubridate function.



?chron tells me:



Bur what does ?weeks tell you?


. . . The functions days(), months(), quarters(),
years(), weeks(), weekdays(), hours(), minutes(), and seconds() take
any chron object as input and extract the corresponding time interval
. . . .

Any advice?

Thanks.

Chris Ryan
SUNY Upstate Medical University Clinical Campus at Binghamton
Binghamton, NY

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


David Winsemius, MD
West Hartford, CT

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


Re: [R] having trouble extracting week from chron object

2011-08-30 Thread Jannis
Well, there is no function called "weeks" in chron. Funny that the help 
mentions it.


You can, however, use normal POSIXct objects and extract the week with:

 dts <- dates(c("02/27/92", "02/27/92"))
 dts.posx <- as.POSIXct(dts)
 result   <- as.integer(format(dts.posx,format="%W"))



HTH
Jannis

--- Christopher W Ryan  schrieb am Di, 30.8.2011:

> Von: Christopher W Ryan 
> Betreff: [R] having trouble extracting week from chron object
> An: R-help@r-project.org
> Datum: Dienstag, 30. August, 2011 17:36 Uhr
> Running R 2.13.1 on Windows XP.
> I would like to get week of the year (1-52) for each date.
> 
> library(chron)
> dts <- dates(c("02/27/92", "02/27/92",
> "01/14/92","02/28/92", "02/01/92"))
> dts
> dts.chron <- as.chron(dts)
> dts.chron
> class(dts.chron)
> # all of these component extractions work:
> months(dts.chron)
> weekdays(dts.chron)
> years(dts.chron)
> quarters(dts.chron)
> # but weeks() doesn't seem to work
> weeks(dts.chron)
> 
> ?chron tells me: . . . The functions days(), months(),
> quarters(),
> years(), weeks(), weekdays(), hours(), minutes(), and
> seconds() take
> any chron object as input and extract the corresponding
> time interval
> . . . .
> 
> Any advice?
> 
> Thanks.
> 
> Chris Ryan
> SUNY Upstate Medical University Clinical Campus at
> Binghamton
> Binghamton, NY
> 
> __
> R-help@r-project.org
> mailing list
> https://stat.ethz.ch/mailman/listinfo/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] Gradient function in OPTIMX

2011-08-30 Thread Ravi Varadhan
Hi Kathie,

The gradient check in "optimx" checks if the user specified gradient (at 
starting parameters) is within roughly 1.e-05 * (1 + fval) of the numerically 
computed gradient. It is likely that you have correctly coded up the gradient, 
but still there can be significant differences b/w numerical and exact 
gradients.  This can happen when the gradients are very large.  

I would check this again separately as follows:

require(numDeriv)

mygrad <-  gr.fy(theta0)

numgrad <- grad(x=theta0, func=gr.fy)

cbind(mygrad, numgrad)

all.equal(mygrad, numgrad)

Can you report these gradients to us?

In "optimx", we should probably change this into a "warning" rather than a 
"stop". 

Ravi.

---
Ravi Varadhan, Ph.D.
Assistant Professor,
Division of Geriatric Medicine and Gerontology School of Medicine Johns Hopkins 
University

Ph. (410) 502-2619
email: rvarad...@jhmi.edu

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/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] column names with rbind loop

2011-08-30 Thread Vining, Kelly
Hello R  users.

This is a fairly basic question:

I am concatenating data from sets of files in a directory using a loop. The 
column names in all files are exactly the same. My understanding is that rbind 
takes column names from the first file it reads. However, my output is showing 
that the column names are treated as a first data row, not treated as headers.

I compile my file names like this:

> all.files <- list.files()
> all.files
 [1] "1.rpkm"  "10.rpkm" "11.rpkm" "12.rpkm" "13.rpkm" "14.rpkm"
 [7] "15.rpkm" "16.rpkm" "17.rpkm" "18.rpkm" "19.rpkm" "2.rpkm" 
[13] "3.rpkm"  "4.rpkm"  "5.rpkm"  "6.rpkm"  "7.rpkm"  "8.rpkm" 
[19] "9.rpkm" 

Then loop through them like this:
> new.data <- NULL
> for(i in all.files) {
+ in.data <- read.table(i)
+ new.data <- rbind(new.data, in.data)}
> head(new.data)
 V1   V2V3 V4 V5V6 V7
1 seq_id   source  type  startend score strand
2 scaffold_1 Ptrichocarpav2_0 gene_body  12639  13384 .  +
3 scaffold_1 Ptrichocarpav2_0 gene_body  22190  22516 .  +
4 scaffold_1 Ptrichocarpav2_0 gene_body  74076  75893 .  +
5 scaffold_1 Ptrichocarpav2_0 gene_body  80207  81289 .  -
6 scaffold_1 Ptrichocarpav2_0 gene_body 105236 107712 .  +


As you can see, R is putting a "V1, V2..." header row here because I didn't say 
"header=TRUE" in my read.table command. But if I do this within the loop, I get 
an error. If I try to delete the V1, V2 row after the fact by 

new.data <- new.data[-1,]

R deletes my "real" header row. 

How can I get the header that I want?

Thanks for any help,
--Kelly V.

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/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] "Negative length vector" error in simple merge

2011-08-30 Thread Nordlund, Dan (DSHS/RDA)
> -Original Message-
> From: r-help-boun...@r-project.org [mailto:r-help-bounces@r-
> project.org] On Behalf Of DimmestLemming
> Sent: Tuesday, August 30, 2011 10:20 AM
> To: r-help@r-project.org
> Subject: Re: [R] "Negative length vector" error in simple merge
> 
> Thanks! I'd just never heard of cbind or rbind... bit new.
> 

If you had never heard of cbind or rbind, then would be doing yourself a BIG 
favor by reading the Introduction to R that comes with every copy of R.

Dan

Daniel J. Nordlund
Washington State Department of Social and Health Services
Planning, Performance, and Accountability
Research and Data Analysis Division
Olympia, WA 98504-5204


__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/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] having trouble extracting week from chron object

2011-08-30 Thread Christopher W Ryan
Running R 2.13.1 on Windows XP.
I would like to get week of the year (1-52) for each date.

library(chron)
dts <- dates(c("02/27/92", "02/27/92", "01/14/92","02/28/92", "02/01/92"))
dts
dts.chron <- as.chron(dts)
dts.chron
class(dts.chron)
# all of these component extractions work:
months(dts.chron)
weekdays(dts.chron)
years(dts.chron)
quarters(dts.chron)
# but weeks() doesn't seem to work
weeks(dts.chron)

?chron tells me: . . . The functions days(), months(), quarters(),
years(), weeks(), weekdays(), hours(), minutes(), and seconds() take
any chron object as input and extract the corresponding time interval
. . . .

Any advice?

Thanks.

Chris Ryan
SUNY Upstate Medical University Clinical Campus at Binghamton
Binghamton, NY

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/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] character vector to text with returns

2011-08-30 Thread David Winsemius


On Aug 30, 2011, at 1:09 PM, Ben qant wrote:


Hello,

(Sorry if this is a dup post...)

I need to clarify, Henrique's suggestion worked great for getting  
the text
that I needed via cat(), but I haven't sorted out how to get cat()  
like
output into a variable so I can pass it into the message body  
variable I am

using.


cat() is not the right function to get text assgned to an object. It's  
entire purpose is to have a side-effect and _not_ return anything into  
R's workspace. Why are you not assigning the result of that paste  
operation to the variable?





Here is what I mean:
x
[1] "a" "b" "c" "d"
paste(x,collapse='\n')
[1] "a\nb\nc\nd"
y = paste(x,collapse='\n')
cat(y)
a
b
c
d

This is the problem with 'y' has the msg body:

paste("msg = MIMEText('",y,"')",sep="")
[1] "msg = MIMEText('a\nb\nc\nd')"

This is what I am after (I think!):

paste("msg = MIMEText('",y,"')",sep="")
[1] "msg = MIMEText('a
b
c
d')"


Here is how I am actually using it (with sensitive items generalized):

require(rJython)
rJython <- rJython()
rJython$exec( "import smtplib" )
rJython$exec("from email.MIMEText import MIMEText")
rJython$exec("import email.utils")

mail<-c(
#Email settings
"fromaddr = 'ccqu...@gmail.com'",
"toaddrs  = 'userna...@somethinghere.com'"
- Show quoted text -
jython.exec(rJython,mail)  # and here is the error I get.

Error in ls(envir = envir, all.names = private) :
 invalid 'envir' argument


Just in case someone asks, I can do this:

y = "a test"

...and the above email sends fine with 'a test' as the msg body.

Any ideas?

PS - I received lots of suggestions. Thank you very much for your
effort/input.

Ben


On Mon, Aug 29, 2011 at 6:01 PM, Henrique Dallazuanna >wrote:



Try:

paste(c("a", "b", "c"), collapse = "\n")

On Mon, Aug 29, 2011 at 8:56 PM, Ben qant  wrote:


Hello,

Does anyone know how to convert this:

msg

[1] "a"
[2] "b"
[3] "c"


To:


msg

"a
b
c"

In other words, I need to convert a character vector to a single  
string

with
carriage returns for each row.

Functionally, I'm attempting to send an email of a character  
vector in a

way
that is readable in the email body. I can only input one string as  
the
message body parameter. I'm using rJython to send the email  
because I need

authentication.

Thanks!

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





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



[[alternative HTML version deleted]]

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


David Winsemius, MD
West Hartford, CT

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


Re: [R] "Negative length vector" error in simple merge

2011-08-30 Thread DimmestLemming
Thanks! I'd just never heard of cbind or rbind... bit new.

--
View this message in context: 
http://r.789695.n4.nabble.com/Negative-length-vector-error-in-simple-merge-tp3778980p3779267.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] character vector to text with returns

2011-08-30 Thread Ben qant
Hello,

(Sorry if this is a dup post...)

I need to clarify, Henrique's suggestion worked great for getting the text
that I needed via cat(), but I haven't sorted out how to get cat() like
output into a variable so I can pass it into the message body variable I am
using.

Here is what I mean:
 x
[1] "a" "b" "c" "d"
 paste(x,collapse='\n')
[1] "a\nb\nc\nd"
 y = paste(x,collapse='\n')
 cat(y)
a
b
c
d

This is the problem with 'y' has the msg body:

paste("msg = MIMEText('",y,"')",sep="")
[1] "msg = MIMEText('a\nb\nc\nd')"

This is what I am after (I think!):

paste("msg = MIMEText('",y,"')",sep="")
[1] "msg = MIMEText('a
b
c
d')"


Here is how I am actually using it (with sensitive items generalized):

 require(rJython)
 rJython <- rJython()
 rJython$exec( "import smtplib" )
 rJython$exec("from email.MIMEText import MIMEText")
 rJython$exec("import email.utils")

 mail<-c(
 #Email settings
 "fromaddr = 'ccqu...@gmail.com'",
 "toaddrs  = 'userna...@somethinghere.com'"
- Show quoted text -
jython.exec(rJython,mail)  # and here is the error I get.

Error in ls(envir = envir, all.names = private) :
  invalid 'envir' argument


Just in case someone asks, I can do this:

y = "a test"

...and the above email sends fine with 'a test' as the msg body.

Any ideas?

PS - I received lots of suggestions. Thank you very much for your
effort/input.

Ben


On Mon, Aug 29, 2011 at 6:01 PM, Henrique Dallazuanna wrote:

> Try:
>
> paste(c("a", "b", "c"), collapse = "\n")
>
> On Mon, Aug 29, 2011 at 8:56 PM, Ben qant  wrote:
>
>> Hello,
>>
>> Does anyone know how to convert this:
>> > msg
>>  [1] "a"
>>  [2] "b"
>>  [3] "c"
>>
>>
>> To:
>>
>> > msg
>> "a
>>  b
>>  c"
>>
>> In other words, I need to convert a character vector to a single string
>> with
>> carriage returns for each row.
>>
>> Functionally, I'm attempting to send an email of a character vector in a
>> way
>> that is readable in the email body. I can only input one string as the
>> message body parameter. I'm using rJython to send the email because I need
>> authentication.
>>
>> Thanks!
>>
>>[[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.
>>
>
>
>
> --
> Henrique Dallazuanna
> Curitiba-Paraná-Brasil
> 25° 25' 40" S 49° 16' 22" O
>

[[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] R cmd build error -- "running 'zip' failed"

2011-08-30 Thread Duncan Murdoch

On 30/08/2011 11:05 AM, Pitt, Joel wrote:

Hi All,

My attempts to build an R package on my Windows 7 computer using R V13.0 ir R 
V13.1 using

R CMD build --binary

have  been failing at the penultimate step with the error message "running 'zip' 
failed" coming after the procedure has completed the MD5 sums step.The same build 
command on the same package completes successfully on my older Vista computer.

Since I would prefer to do the builds on the Windows 7 computer I would 
appreciate any thoughts on why this maybe happening and what I can do to fix 
the problem.


Sounds like a problem with your PATH.

Duncan Murdoch



Thanks and best regards,
Joel Pitt


[[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] algorithm to merge same entries in a matrix

2011-08-30 Thread Martin Batholdy
Hi,

I have the following, rather unorthodox problem:


I have a matrix that looks like this:

m1 <- matrix(c('a','b','d',NA,'c','c'), 2,3, byrow=TRUE)


[,1] [,2] [,3]
[1,]  "a"  "b"  "d" 
[2,] NA   "c"  "c" 


now I would like to transform this matrix into this matrix:

[,1] [,2] [,3] [,4]
[1,]  "a"  "b"  "c"  "d" 
[2,] NA NA NA NA


so the rule is:

if I find the same value (above: 'c') in neighbored cells (here: row wise) put 
this value in row 1 in a new column between
column of neighbor a and column of neighbor b.





too make it even more complicated:
the definition of neighbored cells is not exclusively row wise.




So for example I could encounter this kind of matrix:

m2 <- matrix(c('a','b','d',NA,NA,'c',NA, 'c', NA), 3,3, byrow=TRUE)


   [,1] [,2] [,3]
[1,] "a"  "b"  "d" 
[2,] NA NA  "c" 
[3,] NA "c"  NA  

which should also be transformed into:

[,1] [,2] [,3] [,4]
[1,]  "a"  "b"  "c"  "d" 
[2,] NA NA NA NA


(or m3 <- matrix(c('a','b','d',NA,'c',NA,NA, NA, 'c'), 3,3, byrow=TRUE) ).



Can perhaps someone give me some hints how to solve this efficiently?

I think I could solve that with some loops … but I also need to make sure that 
it is efficient / not taking too much time.


thanks!

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


Re: [R] "Negative length vector" error in simple merge

2011-08-30 Thread David Winsemius


On Aug 30, 2011, at 11:08 AM, DimmestLemming wrote:


Hi,

I'm trying to take a vector (length almost 2,000,000) and merge it  
with a
data frame of the same length. I'm trying to do it solely based on  
index,

and not any other factors.

The vector is called "offense", and the data frame is just called  
"data".


Bad name. There is a function named 'data'.


I
went with the simplest option:

merge(data,offense)


It wouldn't make much sense to merge a vector with a dataframe. The  
matching column should not appear any different except perhaps  
shorter. Sounds like you want cbind() rather than merge.


(You really should have posted str(.) on both objects.)

--
David.



but it always gives me the same error:

Error in rep.int(rep.int(seq_len(nx), rep.int(rep.fac, nx)), orep) :
 negative length vectors are not allowed

Solutions that haven't worked:
- Changing offense into a data frame
- Data doesn't exceed the 2^31 (2 billion) limit for length. When  
combined

with offense, it will have about 68 million items total

Thanks! DL

--
View this message in context: 
http://r.789695.n4.nabble.com/Negative-length-vector-error-in-simple-merge-tp3778980p3778980.html
Sent from the R help mailing list archive at Nabble.com.

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


David Winsemius, MD
West Hartford, CT

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


[R] R crash

2011-08-30 Thread Ivan Calandra

Dear users,

By running the script below, R crashes systematically at the last 
command, namely dev.off(), on Windows 7, but not on Windows XP.
I therefore don't provide a reproducible example and do not really 
extract the relevant parts of the script because it has most likely 
nothing to do with the script itself. I can do it though if you think it 
might be relevant.


R crashes on Windows 7, sessionInfo():
R version 2.13.1 (2011-07-08)
Platform: i386-pc-mingw32/i386 (32-bit)

locale:
[1] LC_COLLATE=German_Germany.1252  LC_CTYPE=German_Germany.1252
[3] LC_MONETARY=German_Germany.1252 LC_NUMERIC=C
[5] LC_TIME=German_Germany.1252

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

other attached packages:
 [1] doBy_4.4.0 MASS_7.3-13snow_0.3-7 
lme4_0.999375-41
 [5] Matrix_0.9996875-3 lattice_0.19-30multcomp_1.2-7 
mvtnorm_0.9-9991
 [9] R2HTML_2.2 survival_2.36-9RSvgDevice_0.6.4.1 
R.utils_1.7.8

[13] R.oo_1.8.1 R.methodsS3_1.2.1

loaded via a namespace (and not attached):
[1] grid_2.13.1   nlme_3.1-101  stats4_2.13.1

But it works perfectly on Windows XP, sessionInfo():
R version 2.13.1 (2011-07-08)
Platform: i386-pc-mingw32/i386 (32-bit)

locale:
[1] LC_COLLATE=English_United States.1252
[2] LC_CTYPE=English_United States.1252
[3] LC_MONETARY=English_United States.1252
[4] LC_NUMERIC=C
[5] LC_TIME=English_United States.1252

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

other attached packages:
 [1] doBy_4.4.0 MASS_7.3-14snow_0.3-6 
lme4_0.999375-41
 [5] Matrix_0.9996875-3 lattice_0.19-33multcomp_1.2-7 
mvtnorm_0.9-9991
 [9] R2HTML_2.2 survival_2.36-9RSvgDevice_0.6.4.1 
R.utils_1.7.8

[13] R.oo_1.8.1 R.methodsS3_1.2.1

loaded via a namespace (and not attached):
[1] grid_2.13.1   nlme_3.1-102  stats4_2.13.1

Except the locale, I don't see any difference and I don't really 
understand how that would make R crash by running dev.off(). Is there 
anything else than sessionInfo()?


Thank you for your help,
Ivan



 script -

library(R.utils)
library(RSvgDevice)
library(doBy)
primate_med <- loadObject("primate_med.Rbin")

select <- primate_med   #data object to use
seq.yvar <- c(5,12,8,9)
ind.xvar <- 4

 filename <- paste("regression", names(datobj)[ind.xvar], 
paste(names(datobj)[seq.yvar],collapse="_"), 
paste(selvarstr,collapse="_"), sep="_")

 filename <- gsub(".median", "", filename)

 select_mean <- 
summaryBy(as.formula(paste(".~",names(select)[ind.xvar])), data=select, 
FUN=mean)


 devSVG(file=paste(filename, ".svg", sep=""))
 par(mfrow=c(2,2))
 diff_len <- length(select)-length(select_mean)

 for (i in seq_along(seq.yvar)){
  k <- seq.yvar[i]
  plot(select[[k]]~select[[ind.xvar]], type="p", pch=1, 
xlab=names(select)[ind.xvar], ylab=names(select)[k], las=1)
  points(select_mean[[ind.xvar-diff_len]], select_mean[[k-diff_len]], 
pch=18, cex=2)

  two_reg(dat=select, xvar=ind.xvar, yvar=k)
 }

 dev.off()

-

--
Ivan CALANDRA
PhD Student
University of Hamburg
Biozentrum Grindel und Zoologisches Museum
Dept. Mammalogy
Martin-Luther-King-Platz 3
D-20146 Hamburg, GERMANY
+49(0)40 42838 6231
ivan.calan...@uni-hamburg.de

**
http://www.for771.uni-bonn.de
http://webapp5.rrz.uni-hamburg.de/mammals/eng/1525_8_1.php

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


Re: [R] Exception while using NeweyWest function with doMC

2011-08-30 Thread Simon Zehnder
Hi Jay,

first: thank u very much for your comments! U made some very important points 
clear. I tried immediately to write directly the sample function from 

trade<-as.big.matrix(matrix(sample(c(1,-1), (N+1)*K, replace=TRUE),ncol=K), 
backingpath=backingpath, backingfile="trade.bin",descriptorfile="trade.desc")

into the big matrix:

trade<-big.matrix(sample(c(1,-1), (10+1), replace=TRUE),nrow=(10+1), ncol=10, 
type="double",backingpath="/Users/simon/Documents/R/BigMTest/", 
backingfile="terminaltest.bin", descriptorfile="terminaltest.desc")

But I either get only 1s:

trade[,]  [,1] [,2] [,3] [,4] [,5] [,6] [,7] [,8] [,9] [,10]
 [1,]111111111 1
 [2,]111111111 1
 [3,]111111111 1
 [4,]111111111 1
 [5,]111111111 1
 [6,]111111111 1
 [7,]111111111 1
 [8,]111111111 1
 [9,]111111111 1
[10,]111111111 1
[11,]111111111 1

or only -1s:

trade[,]  [,1] [,2] [,3] [,4] [,5] [,6] [,7] [,8] [,9] [,10]
 [1,]   -1   -1   -1   -1   -1   -1   -1   -1   -1-1
 [2,]   -1   -1   -1   -1   -1   -1   -1   -1   -1-1
 [3,]   -1   -1   -1   -1   -1   -1   -1   -1   -1-1
 [4,]   -1   -1   -1   -1   -1   -1   -1   -1   -1-1
 [5,]   -1   -1   -1   -1   -1   -1   -1   -1   -1-1
 [6,]   -1   -1   -1   -1   -1   -1   -1   -1   -1-1
 [7,]   -1   -1   -1   -1   -1   -1   -1   -1   -1-1
 [8,]   -1   -1   -1   -1   -1   -1   -1   -1   -1-1
 [9,]   -1   -1   -1   -1   -1   -1   -1   -1   -1-1
[10,]   -1   -1   -1   -1   -1   -1   -1   -1   -1-1
[11,]   -1   -1   -1   -1   -1   -1   -1   -1   -1-1

Is there another possibility? In addition I found under ?as.big.matrix, for the 
second example the usage of matrix() inside of as.big.matrix(). But if I 
understood u correctly: usage is possible but does not save memory? I used the 
big.memory package because I always got  - using simply matrix() - exceptions, 
telling me, that memory has reached its limits. After using big.memory all 
worked fine, BUT running http://pastebin.com/UxSkzrae and  
http://pastebin.com/MErGQsQd , I got this: http://pastebin.com/KrEncrSz. It 
seems, as there is a problem with memory allocation inside the underlying 
C-code, maybe a result from my matrix generation inside of the big matrix?

Any suggestions?

 

On Aug 29, 2011, at 6:24 PM, Jay Emerson wrote:

> Simon,
> 
> Though we're please to see another use of bigmemory, it really isn't
> clear that it is gaining you
> anything in your example; anything like as.big.matrix(matrix(...))
> still consumes full RAM for both
> the inner matrix() and the new big.matrix -- is the filebacking really
> necessary.  It also doesn't
> appear that you are making use of shared memory, so I'm unsure what
> the gains are.  However,
> I don't have any particular insight as to the subsequent problem with
> NeweyWest (which doesn't
> seem to be using the big.matrix objects).
> 
> Jay
> 
> --
> Message: 32
> Date: Sat, 27 Aug 2011 21:37:55 +0200
> From: Simon Zehnder 
> To: r-help@r-project.org
> Subject: [R] Exception while using NeweyWest function with doMC
> Message-ID:
>   
> Content-Type: text/plain
> 
> Dear R users,
> 
> I am using R right now for a simulation of a model that needs a lot of
> memory. Therefore I use the *bigmemory* package and - to make it faster -
> the *doMC* package. See my code posted on http://pastebin.com/dFRGdNrG
> 
> < snip >
> -
> 
> -- 
> John W. Emerson (Jay)
> Associate Professor of Statistics
> Department of Statistics
> Yale University
> http://www.stat.yale.edu/~jay


[[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] GMM with panel data

2011-08-30 Thread Cecilia Carmo
Hi everyone,

 

I´m starting with GMM estimator for panel data in R. In fact I’m starting
with GMM estimation with panel data, my research area is accounting and
finance, so I’ve been reading many «econometric» books but I have some
difficulties in applying GMM estimation. 

 

I’ve also read the article «Panel data econometrics in R: the plm package»
(Croissant & Millo) and my question is: 

Does the pggm() function performs the estimation based in Arellano and Bond
(1991)? If yes, is there any way to perform the estimation based in Blundell
and Bond (1998) (that seems to be a better estimator)?

 

Thank you,

Cecília Carmo (Universidade de Aveiro)

 

 


[[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] Help with the 'reshape' package

2011-08-30 Thread Gabor Grothendieck
On Tue, Aug 30, 2011 at 7:42 AM, Filipe Leme Botelho
 wrote:
> Hi all,
>
> I am reading previous posts and guidance on the 'reshape' package in order to 
> solve the simple problem below. Thinking that this might be very trivial for 
> most of you, I thought there could be a fast solution coming from you guys, 
> and I´d be very thankful for that.
>


Here is a zoo solution:

# first set up input

Lines <- "DateCompany Price
set-11  A   3
dez-11  A   3,2
jan-12  A   3,3
fev-12  A   2,7
mar-12  A   2,7
abr-12  A   2,8
mai-12  A   2,9
jun-12  A   3
jul-12  A   3,1
mar-12  B   5
abr-12  B   5,5
mai-12  B   5,7
jun-12  B   7
jul-12  B   6,6
dez-11  C   1
jan-12  C   1,1
fev-12  C   1,11
mar-12  C   1,2
abr-12  C   1,3"

Sys.setlocale("LC_ALL", "Portuguese")

library(zoo)

# The read.zoo command converts first column to yearmon class
# and reads it into a zoo object.

#  in next line we would normally
# replace textConnection(Lines) with file name, e.g. "myfile.txt"
# but here we do it this way to keep it self contained

z <- read.zoo(textConnection(Lines), header = TRUE, dec = ",",
   split = 2, FUN = function(x) as.yearmon(x, format = "%b-%y"))

This gives the following zoo object:

> z
  A   BC
set 2011 3.0  NA   NA
dez 2011 3.2  NA 1.00
jan 2012 3.3  NA 1.10
fev 2012 2.7  NA 1.11
mar 2012 2.7 5.0 1.20
abr 2012 2.8 5.5 1.30
mai 2012 2.9 5.7   NA
jun 2012 3.0 7.0   NA

It may be more convenient to keep as a zoo object so you can do other
time series manipulations, e.g.

plot(z)
plot(z, screen = 1)

but you want it as a data frame:

DF <- data.frame(Date = time(z), coredata(z))

-- 
Statistics & Software Consulting
GKX Group, GKX Associates Inc.
tel: 1-877-GKX-GROUP
email: ggrothendieck at gmail.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] test message

2011-08-30 Thread Gabor Grothendieck
Please ignore this message.

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/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] "Negative length vector" error in simple merge

2011-08-30 Thread DimmestLemming
Hi,

I'm trying to take a vector (length almost 2,000,000) and merge it with a
data frame of the same length. I'm trying to do it solely based on index,
and not any other factors.

The vector is called "offense", and the data frame is just called "data". I
went with the simplest option:

merge(data,offense)

but it always gives me the same error:

Error in rep.int(rep.int(seq_len(nx), rep.int(rep.fac, nx)), orep) : 
  negative length vectors are not allowed

Solutions that haven't worked:
- Changing offense into a data frame
- Data doesn't exceed the 2^31 (2 billion) limit for length. When combined
with offense, it will have about 68 million items total

Thanks! DL

--
View this message in context: 
http://r.789695.n4.nabble.com/Negative-length-vector-error-in-simple-merge-tp3778980p3778980.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] character vector to text with returns

2011-08-30 Thread Ben qant
Hello,

I need to clarify, Henrique's suggestion worked great for getting the text
that I needed via cat(), but I haven't sorted out how to get cat() like
output into a variable so I can pass it into the message body variable I am
using.

Here is what I mean:
 x
[1] "a" "b" "c" "d"
 paste(x,collapse='\n')
[1] "a\nb\nc\nd"
 y = paste(x,collapse='\n')
 cat(y)
a
b
c
d

This is the problem with 'y' has the msg body:

paste("msg = MIMEText('",y,"')",sep="")
[1] "msg = MIMEText('a\nb\nc\nd')"

This is what I am after (I think!):

paste("msg = MIMEText('",y,"')",sep="")
[1] "msg = MIMEText('a
b
c
d')"


Here is how I am actually using it (with sensitive items generalized):

 require(rJython)
 rJython <- rJython()
 rJython$exec( "import smtplib" )
 rJython$exec("from email.MIMEText import MIMEText")
 rJython$exec("import email.utils")

 mail<-c(
 #Email settings
 "fromaddr = 'ccqu...@gmail.com'",
 "toaddrs  = 'userna...@somethinghere.com'",
 #"msg = MIMEText('test message from R')",
 paste("msg = MIMEText('",y,"')",sep=""),# my message in this example is
'y'
 "msg['From'] = email.utils.formataddr(('gmail acct', fromaddr))",
 "msg['To'] = email.utils.formataddr(('cc email!', toaddrs))",
 "msg['Subject'] = 'test with y'",

 #SMTP server credentials
 "username = 'ccqu...@gmail.com'",
 "password = 'a password here'",

 #Set SMTP server and send email, e.g., google mail SMTP server
 "server = smtplib.SMTP('smtp.gmail.com:587')",
 "server.ehlo()",
 "server.starttls()",
 "server.ehlo()",
 "server.login(username,password)",
 "server.sendmail(fromaddr, toaddrs, msg.as_string())",
 "server.quit()")

jython.exec(rJython,mail)  # and here is the error I get.
Error in ls(envir = envir, all.names = private) :
  invalid 'envir' argument


Just in case someone asks, I can do this:

y = "a test"

...and the above email sends fine with 'a test' as the msg body.

Any ideas?

PS - I received lots of suggestions. Thank you very much for your
effort/input.

Ben

On Mon, Aug 29, 2011 at 9:29 PM, Bert Gunter  wrote:

> Is something like this what you want?
>
> x <- letters[1:4]
> x
> y <-do.call(paste,c( paste('"',x[1]), as.list(x[2:3]),
> paste(x[4],'"'),sep="\n"))
> y
> cat(y,"\n")
>
> -- Bert
>
>
> On Mon, Aug 29, 2011 at 6:59 PM, Ben qant  wrote:
> > Unfortunately that didn't work. I just says the text is an invalid
> argument.
> > I also tried saving it in a variable name and passed that in, but that
> > didn't work. I get:
> >
> > Error in ls(envir = envir, all.names = private) :
> >  invalid 'envir' argument
> >
> > ...when I try to send the message.
> >
> > Any other ideas?
> >
> > Thanks,
> > Ben
> >
> > On Mon, Aug 29, 2011 at 6:01 PM, Henrique Dallazuanna  >wrote:
> >
> >> Try:
> >>
> >> paste(c("a", "b", "c"), collapse = "\n")
> >>
> >> On Mon, Aug 29, 2011 at 8:56 PM, Ben qant  wrote:
> >>
> >>> Hello,
> >>>
> >>> Does anyone know how to convert this:
> >>> > msg
> >>>  [1] "a"
> >>>  [2] "b"
> >>>  [3] "c"
> >>>
> >>>
> >>> To:
> >>>
> >>> > msg
> >>> "a
> >>>  b
> >>>  c"
> >>>
> >>> In other words, I need to convert a character vector to a single string
> >>> with
> >>> carriage returns for each row.
> >>>
> >>> Functionally, I'm attempting to send an email of a character vector in
> a
> >>> way
> >>> that is readable in the email body. I can only input one string as the
> >>> message body parameter. I'm using rJython to send the email because I
> need
> >>> authentication.
> >>>
> >>> Thanks!
> >>>
> >>>[[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.
> >>>
> >>
> >>
> >>
> >> --
> >> Henrique Dallazuanna
> >> Curitiba-Paraná-Brasil
> >> 25° 25' 40" S 49° 16' 22" O
> >>
> >
> >[[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.
> >
> >
>
>
>
> --
> "Men by nature long to get on to the ultimate truths, and will often
> be impatient with elementary studies or fight shy of them. If it were
> possible to reach the ultimate truths without the elementary studies
> usually prefixed to them, these would not be preparatory studies but
> superfluous diversions."
>
> -- Maimonides (1135-1204)
>
> Bert Gunter
> Genentech Nonclinical Biostatistics
>

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

[R] multi-response regression with random forest

2011-08-30 Thread Cédric Mondy
Dear list,

I performed a multivariate analysis on freshwater invertebrates data. So
I obtained coordinates of my samples on the axes defining the first
factorial plane (F1 and F2).

I would like to see if the positions on my factorial plan could be
linked to levels of impairment ('low' vs 'significant') for several
water quality pressure categories and which pressure categories were the
most important to explain my data.

I first used random forests (package randomForest) to independently
regressed the F1 and F2 coordinates against my pressures levels. These
models explained around 13% of the variability for the first axis and
1.5% or the second axis. 

I heard about multi-response modelizations and tried to model the
bi-variate response F1+F2 from the same set of pressure levels. This
time, the model explained around 37% of the variability, that was great.

But I don't understand what is precisely modeled in such multi-response
regressions with random forest, when I used the predict() function on my
data I obtained only one value for each sample. What correspond to this
prediction? F1, F2, some combination of the both?

Any advice and links to helpful litterature would be appreciated,

Thanks,

Cédric

___

Here is a small extract of my input data :

ID  F1   F2  WQ1  WQ2  WQ3  WQ4
423007 -0.181720936 -0.031683254 Impaired Impaired Impaired Impaired
423432 -0.013823243 -0.044562244 Good Good Impaired Good
382886 -0.062171083  0.095592402 Good Impaired Good Impaired
349067  0.165199490 -0.006247771 Impaired Good Impaired Good
350787 -0.086522253 -0.001156491 Good Good Impaired Good
423700 -0.094519496  0.058552236 Good Good Impaired Good
1473   -0.030547960  0.041201208 Good Good Impaired Good
422893 -0.381074618 -0.108488149 Good Good Good Good
424323 -0.200710868  0.008960769 Good Impaired Impaired Impaired
351117 -0.026336697 -0.011788642 Good Good Impaired Good
423356 -0.095307898  0.032821813 Good Good Impaired Good
52  0.181933163 -0.070008234 Good Good Good Good
529 0.201013553 -0.039925550 Good Good Good Good
123 0.049202307 -0.255373209 Good Good Good Good
424332 -0.201756587 -0.007161893 Good Good Impaired Good
423925  0.182053115 -0.163286598 Good Good Good Good
422967  0.009489423  0.078132841 Good Good Impaired Good
423899  0.042904501  0.022193773 Good Good Good Good
350912  0.031308796  0.066608196 Good Good Good Good
422988 -0.049664431  0.063449869 Good Good Impaired Good

This is the formula I used for my model:

mod=randomForest((F1+F2)~., data=data, ntree = 500, mtry =
sqrt(ncol(data)-1))

The model summary:

Call:
 randomForest(formula = (F1 + F2) ~ ., data = data, ntree = 500,
mtry = sqrt(ncol(data) - 1)) 

   Type of random forest: regression
 Number of trees: 500
No. of variables tried at each split: 4

  Mean of squared residuals: 0.01772612
% Var explained: 37.98


And finally the predictions:

  prediction
423007  -0.256445319
423432  -0.078636802
382886  -0.088890538
349067  -0.118654211
350787  -0.112655013
423700   0.018815905
1473-0.032085983
422893  -0.303123232
424323  -0.226793376
351117   0.008599632
423356  -0.038947801
52   0.120712909
529  0.043381647
123 -0.087297539
424332  -0.180140229
423925   0.078654535
422967  -0.012138644
423899   0.078367004
350912   0.078654535
422988   0.014915818

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/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] url prep function (backslash issue)

2011-08-30 Thread Tyler Rinker

Duncan, Thanks.  Combined with what Brian Ripley wrote it all works.   For 
future thread searchers this worked: oldstring <- readline()
C:\Users\Rinker\Desktop\Research& Law\Data\School Data 09-10
chartr("\\", "/",oldstring) Thank you both,Tyler
 #> Date: Tue, 30 Aug 2011 09:35:58 
-0400
> From: murdoch.dun...@gmail.com
> To: tyler_rin...@hotmail.com
> CC: r-help@r-project.org
> Subject: Re: [R] url prep function (backslash issue)
> 
> Brian Ripley told you how to do the translation, but there's another 
> problem:
> 
> On 30/08/2011 8:14 AM, Tyler Rinker wrote:
> 
> [ much deleted ]
> > When I try
> > the function the backslash gets me again:
> >
> > >
> > readyPath("C:\Users\Rinker\Desktop\Research&  Law\Data\School Data
> > 09-10")
> 
> The problem is that you haven't entered a string containing backslashes, 
> you've tried to enter a string containing escapes.  The parser sees a 
> single backslash and attaches it to the next letter, so \U is taken to 
> be the start of a Unicode character, and you get the error
> > Error: '\U' used without hex digits in character string starting
> > "C:\U"
> >
> 
> The way around this is to avoid the parser, by something like this:
> 
> oldstring <- readline()
> 
> C:\Users\Rinker\Desktop\Research&  Law\Data\School Data 09-10
> 
> 
> and then applying chartr to oldstring.
> 
> Duncan Murdoch
> 
> 
> > This is
> > what I'd like the function to return:
> >
> > [1]
> > "C:/Users/Rinker/Desktop/Research&  Law/Data/School Data 09-10"
> >
> > I want a
> > function in which I enter a path and it returns the path with backslashes
> >
> > replaced
> > with forward slashes. Is there a way to make a function to do this?
> >
> > Windows 7
> > user
> >
> > R version
> > 2.14 beta
> >
> > Thank you,
> >
> > Tyler
> > Rinker
> >
> >
> >
> > 
> > [[alternative HTML version deleted]]
> >
> > __
> > R-help@r-project.org mailing list
> > https://stat.ethz.ch/mailman/listinfo/r-help
> > PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> > and provide commented, minimal, self-contained, reproducible code.
> 
  
[[alternative HTML version deleted]]

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


Re: [R] Exception while using NeweyWest function with doMC

2011-08-30 Thread David Winsemius


On Aug 30, 2011, at 11:29 AM, Simon Zehnder wrote:


Hi David,

thank you very much for your advice! I updated R and all my  
packages. Regrettably it doesn't work yet. But, I think, that the  
parallel processing (using 32bit) does improve time, especially when  
it comes to higher dimensions:


system.time(simuFunctionSeq(0.03, 0.015, 1, 5, 1000, 100,"/Users/ 
simon/Documents/R/BigMTest"))
  system.time(simuFunctionPar(0.03, 0.015, 1, 5, 1000, 100,"/Users/ 
simon/Documents/R/BigMTest"))

[1] "Sequential Processing with N =  1000  and K =  100"
  user  system elapsed
 5.157   0.086   5.587
[1] "Parallel Processing with N =  1000  and K =  100"
  user  system elapsed
 6.069   0.220   3.895

:> system.time(simuFunctionSeq(0.03, 0.015, 1, 5, 1, 100,"/Users/ 
simon/Documents/R/BigMTest"))
  system.time(simuFunctionPar(0.03, 0.015, 1, 5, 1, 100,"/Users/ 
simon/Documents/R/BigMTest"))

[1] "Sequential Processing with N =  1  and K =  100"
  user  system elapsed
 8.129   0.689  12.747
[1] "Parallel Processing with N =  1  and K =  100"
  user  system elapsed
 8.387   0.772  12.005

:> system.time(simuFunctionSeq(0.03, 0.015, 1, 5, 1, 1000,"/ 
Users/simon/Documents/R/BigMTest"))
  system.time(simuFunctionPar(0.03, 0.015, 1, 5, 1, 1000,"/Users/ 
simon/Documents/R/BigMTest"))

[1] "Sequential Processing with N =  1  and K =  1000"
  user  system elapsed
71.295   6.330 109.656
[1] "Parallel Processing with N =  1  and K =  1000"
  user  system elapsed
50.943   6.347  89.115

Or are the times negligible?


I would think that for most applications getting a gain of efficiency  
of 20% would be considered unworthy of the effort at setting up and  
maintaining. I suppose if a simulation ran for 18 hours in sequential  
mode and you would be happier if it were done in the morning after  
leaving overnight and  finding it had completed in 15 hours, it might  
be worth the effort.


What happens if I use a supercomputer with several cores and much  
more memory?


Or even a MacPro with 4 or 8 cores and 32-64 GB?. Generally you hope  
to see halving or quartering in times when you apply these techniques.


--
David.



Thanks again!

Simon



On Aug 29, 2011, at 6:59 PM, David Winsemius wrote:



On Aug 27, 2011, at 3:37 PM, Simon Zehnder wrote:


Dear R users,

I am using R right now for a simulation of a model that needs a  
lot of
memory. Therefore I use the *bigmemory* package and - to make it  
faster -

the *doMC* package. See my code posted on http://pastebin.com/dFRGdNrG

Now, if I use the foreach loop with the addon %do% (for sequential  
run) I

have no problems at all - only here and there some singularities in
regressor matrices which should be ok.
BUT if I run the loop on multiple cores I get very often a bad  
exception. I
have posted the exception on http://pastebin.com/eMWF4cu0 The  
exception
comes from the NeweyWest function loaded within the sandwich  
library.


I have no clue, what it want to say me and why it is so weirdly  
printed to
the terminal. I am used to receive here and there errorsbut  
the messages

never look like this.

Does anyone have a useful answer for me, where to look for the  
cause of this

weird error?

Here some additional information:

Hardware: MacBook Pro 2.66 GHz Intel Core Duo, 4 GB Memory 1067  
MHz DDR3

Software System: Mac Os X Lion 10.7.1 (11B26)
Software App: R64 version 2.11.1 run via Mac terminal


Using the R64 version in a 4GB environment will reduce the  
effective memory capacity since the larger pointers take up more  
space, and using parallel methods is unlikely to improve  
performance very much with only two cores. It also seems likely  
that there have been several bug fixes in the last couple of years  
since that version of R was released, so the package authors are  
unlikely to be very interested in segfault errors thrown by  
outdated software.



I hope someone has a good suggestion!


Update R. Don't use features that only reduce performance and make  
unstable a machine that has limited resources.


--

David Winsemius, MD
West Hartford, CT





David Winsemius, MD
West Hartford, CT

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


[R] R cmd build error -- "running 'zip' failed"

2011-08-30 Thread Pitt, Joel
Hi All,
 
My attempts to build an R package on my Windows 7 computer using R V13.0 ir R 
V13.1 using 
 
R CMD build --binary  
 
have  been failing at the penultimate step with the error message "running 
'zip' failed" coming after the procedure has completed the MD5 sums step.The 
same build command on the same package completes successfully on my older Vista 
computer. 
 
Since I would prefer to do the builds on the Windows 7 computer I would 
appreciate any thoughts on why this maybe happening and what I can do to fix 
the problem.
 
Thanks and best regards,
Joel Pitt
 

[[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] ATSP to TSP reformulation

2011-08-30 Thread Ian Deters
Dr. Hahsler,

Thank you so much for looking at my code.  I made sure that I had TSP_1.0-3
install and ran the code again (this time with "<-" instead of "=" for my
assignments).  I received the same response.  I checked my sessionInfo and
did not see anything out of the ordinary.  Does anything look out of place
to you?  Thank you for your time.  Here is my sessionInfo:

R version 2.13.1 (2011-07-08)
Platform: i386-pc-mingw32/i386 (32-bit)

locale:
[1] LC_COLLATE=English_United States.1252 
[2] LC_CTYPE=English_United States.1252   
[3] LC_MONETARY=English_United States.1252
[4] LC_NUMERIC=C  
[5] LC_TIME=English_United States.1252

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

other attached packages:
[1] TSP_1.0-3

--
View this message in context: 
http://r.789695.n4.nabble.com/ATSP-to-TSP-reformulation-tp3777105p3778959.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] RES: Help with the 'reshape' package

2011-08-30 Thread Filipe Leme Botelho
Petr, many thanks. It´s very straightforward to to deal with the package, I had 
different sources of revenues for same company, same month, like below, and 
just by adding "sum" at the end of the function it collapsed values from all 
sources. Very useful! Cheers

cast(dta, Data~Company, value="Revenues", sum)

> Date  Company Revenues
> set-11A   3
> dez-11A   3,2
> jan-12A   3,3
> fev-12A   2,7
> mar-12A   2,7
> abr-12A   2,8
> mai-12A   2,9
> jun-12A   3
> jul-12A   3,1
> mar-12B   5
> abr-12B   5,5
> mai-12B   5,7
> jun-12B   7
> jul-12B   6,6
> dez-11C   1
> jan-12C   1,1
> fev-12C   1,11
> mar-12C   1,2
> abr-12C   1,3
> dez-11A   0,2
> jan-12A   4,3
> fev-12A   2,1
> mar-12A   2,2

A   B   C
01/09/2011  3   0   0
01/12/2011  3,4 0   1
01/01/2012  7,6 0   1,1
01/02/2012  4,8 0   1,11
01/03/2012  4,9 5   1,2
01/04/2012  2,8 5,5 1,3
01/05/2012  2,9 5,7 0
01/06/2012  3   7   0
01/07/2012  3,1 6,6 0

-Mensagem original-
De: Petr PIKAL [mailto:petr.pi...@precheza.cz] 
Enviada em: terça-feira, 30 de agosto de 2011 09:28
Para: Filipe Leme Botelho
Cc: r-help@r-project.org
Assunto: Re: [R] Help with the 'reshape' package

Hi
> Hi all,
> 
> I am reading previous posts and guidance on the 'reshape' package in 
order
> to solve the simple problem below. Thinking that this might be very 
> trivial for most of you, I thought there could be a fast solution coming 

> from you guys, and I´d be very thankful for that.
> 
> I have a matrix with dates, companies, prices, just like
> 
> Date   Company   Price
> set-11   A   3
> dez-11   A   3,2
> jan-12   A   3,3
> fev-12   A   2,7
> mar-12   A   2,7
> abr-12   A   2,8
> mai-12   A   2,9
> jun-12   A   3
> jul-12   A   3,1
> mar-12   B   5
> abr-12   B   5,5
> mai-12   B   5,7
> jun-12   B   7
> jul-12   B   6,6
> dez-11   C   1
> jan-12   C   1,1
> fev-12   C   1,11
> mar-12   C   1,2
> abr-12   C   1,3
> 
> and I want to convert it into something like below (missing data can be 
> zeros or NAs)
> 
>   A   B   C
> set-11   3   NA   NA
> dez-11   3,2   NA   1
> jan-12   3,3   NA   1,1
> fev-12   2,7   NA   1,11
> mar-12   2,7   5   1,2
> abr-12   2,8   5,5   1,3
> mai-12   2,9   5,7   NA
> jun-12   3   7   NA
> jul-12   3,1   6,6   NA



You have already melted data (long format). So simply cast

 cast(test, Date~Company)
Using Price as value column.  Use the value argument to cast to override 
this choice
Date   A   BC
1 abr-12 2.8 5.5 1.30
2 dez-11 3.2  NA 1.00
3 fev-12 2.7  NA 1.11
4 jan-12 3.3  NA 1.10
5 jul-12 3.1 6.6   NA
6 jun-12 3.0 7.0   NA
7 mai-12 2.9 5.7   NA
8 mar-12 2.7 5.0 1.20
9 set-11 3.0  NA   NA

Shall be OK.

Regards
Petr



> 
> Workspace is attached. Thanks in advance.
> 
> "This message and its attachments may contain confidential and/or 
> privileged information. If you are not the addressee, please, advise the 

> sender immediately by replying to the e-mail and delete this message."
> 
> "Este mensaje y sus anexos pueden contener información confidencial o 
> privilegiada. Si ha recibido este e-mail por error por favor bórrelo y 
> envíe un mensaje al remitente."
> 
> "Esta mensagem e seus anexos podem conter informação confidencial ou 
> privilegiada. Caso não seja o destinatário, solicitamos a imediata 
> notificação ao remetente e exclusão da 
> mensagem."__
> R-help@r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide 
http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.


"This message and its attachments may contain confidential and/or privileged 
information. If you are not the addressee, please, advise the sender 
immediately by replying to the e-mail and delete this message."

"Este mensaje y sus anexos pueden contener información confidencial o 
privilegiada. Si ha recibido este e-mail por error por favor bórrelo y envíe un 
mensaje al remitente."

"Esta mensagem e seus anexos podem conter informação confidencial ou 
privilegiada. Caso não seja o destinatário, solicitamos a imediata notificação 
ao remetente e exclusão da mensagem."

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

Re: [R] Showing zero frequencies with xtabs

2011-08-30 Thread Luca Meyer
Thanks Peter & Petr,

It was indeed an issue of having some character variables in there. Now it 
works just fine.

Cheers,
Luca

Il giorno 30/ago/2011, alle ore 10.15, peter dalgaard ha scritto:

> 
> On Aug 30, 2011, at 10:04 , Luca Meyer wrote:
> 
>> Hi,
>> 
>> Does anyone know how to show zero frequencies variable levels with the xtabs 
>> command? They show with the table(x,y) command but I need to apply weight to 
>> frequency tables and I also need to cbind several tables together, which 
>> implies that they all need to show the same number of rows. 
> 
> Are you sure you are doing the same thing as with table(). I'd expect it to 
> work if you ensure that the variables are factors:
> 
>> library(ISwR)
>> xtabs(~sex+menarche,data=juul)
>   menarche
> sex   1   2
>  2 369 335
> 
>> juul$sex <- factor(juul$sex,levels=1:2)
>> xtabs(~sex+menarche,data=juul)
>   menarche
> sex   1   2
>  1   0   0
>  2 369 335
> 
> 
> 
>> 
>> Alternatively, do you know how to column bind tables with different number 
>> of rows? I cannot use merge as it requires daata.frame and that modifies the 
>> look of the banner table I am trying to create...
>> 
>> Thanks,
>> Luca
>> 
>> 
>> Mr. Luca Meyer
>> www.lucameyer.com
>> R version 2.13.1 (2011-07-08)
>> Mac OS X 10.6.8
>> 
>> 
>> 
>> 
>> 
>> 
>> 
>>  [[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.
> 
> -- 
> Peter Dalgaard, Professor
> Center for Statistics, Copenhagen Business School
> Solbjerg Plads 3, 2000 Frederiksberg, Denmark
> Phone: (+45)38153501
> Email: pd@cbs.dk  Priv: pda...@gmail.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] url prep function (backslash issue)

2011-08-30 Thread Duncan Murdoch
Brian Ripley told you how to do the translation, but there's another 
problem:


On 30/08/2011 8:14 AM, Tyler Rinker wrote:

[ much deleted ]

When I try
the function the backslash gets me again:

>
readyPath("C:\Users\Rinker\Desktop\Research&  Law\Data\School Data
09-10")


The problem is that you haven't entered a string containing backslashes, 
you've tried to enter a string containing escapes.  The parser sees a 
single backslash and attaches it to the next letter, so \U is taken to 
be the start of a Unicode character, and you get the error

Error: '\U' used without hex digits in character string starting
"C:\U"



The way around this is to avoid the parser, by something like this:

oldstring <- readline()

C:\Users\Rinker\Desktop\Research&  Law\Data\School Data 09-10


and then applying chartr to oldstring.

Duncan Murdoch



This is
what I'd like the function to return:

[1]
"C:/Users/Rinker/Desktop/Research&  Law/Data/School Data 09-10"

I want a
function in which I enter a path and it returns the path with backslashes

replaced
with forward slashes. Is there a way to make a function to do this?

Windows 7
user

R version
2.14 beta

Thank you,

Tyler
Rinker




[[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] Configuring Proxy: Proxy Authentication Required with --internet2

2011-08-30 Thread Duncan Murdoch

On 30/08/2011 3:48 AM, behave wrote:

That was my first guess as well, but unfortunately this doesn't solve the
problem.

I is remarkably that IE requires authentification for every new instance I
open (even if another instance is already open)...

Any other hints?


You can read about how WinINet can be made to  handle authentication on 
this page:


http://msdn.microsoft.com/en-us/library/aa384220%28v=vs.85%29.aspx

(If that URL doesn't work, search for WinINet on microsoft.com, and 
navigate to "Handling Authentication".)


To do any of this would require changes to the file 
https://svn.r-project.org/R/trunk/src/modules/internet/internet.c.  The 
USE_WININET_ASYNC macro is *not* defined, so ignore code in those 
ifdefs.  You could try changing the error handling code around line 791.


Since I don't use a proxy I can't test any of this and won't attempt it 
myself, but if you are able to make the changes and test them and they 
are reasonable looking, I'll consider incorporating them.


Duncan Murdoch

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/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] url prep function (backslash issue)

2011-08-30 Thread Tyler Rinker

Thank you Brian. When I wrote the email I typed url into the subject line by 
accident.  I mean path.   Thank you,Tyler

 > Date: Tue, 30 Aug 2011 14:00:22 +0100
> From: rip...@stats.ox.ac.uk
> To: tyler_rin...@hotmail.com
> CC: r-help@r-project.org
> Subject: Re: [R] url prep function (backslash issue)
> 
> You seem to be looking for chartr("\\", "/", path) (and FAQ Q7.8)
> 
> What does any of this have to do with 'url prep': URLs are never 
> written with backslashes?
> 
> On Tue, 30 Aug 2011, Tyler Rinker wrote:
> 
> >
> >
> >
> > Greeting R
> > Community,
> >
> > I am a
> > windows user so this problem may be specific to windows. I often want to 
> > source
> > files from within R
> >
> > such as:
> > C:\Users\Rinker\Desktop\Research & Law\Data\School Data 09-10. To source
> > this file I need to go
> >
> > through the
> > path and replace all the backslashes (\) with forward slashes (/). I 
> > usually do
> > this in MS Word
> >
> > using the
> > replace option, however, I'd like to do this in R. Attempting to write a
> > function to do this runs into
> >
> > problems:
> >
> > When I
> > enter the following:
> >
> > readyPath
> > <- function(path){
> >
> > z <- gsub("\", "/", path)
> >
> > return(z)
> >
> > }
> >
> > I get:
> >
> >>
> > readyPath <- function(path){
> >
> > + z <- gsub("\", "/", path)
> >
> > + return(z)
> >
> > + }
> >
> > +
> >
> > ...meaning
> > R can't close the sequence (presumably because of the backslash which has
> > special meaning).
> >
> > So I tried
> > (\\):
> >
> >
> >
> > readyPath <- function(path){
> >
> > z <- gsub("\\", "/", path)
> >
> > return(z)
> >
> > }This allows
> > the function to be stored as an object but I'm not sure if this is correct.
> 
> It isn't: please do read the help for gsub (\ is a metacharacter).
> 
> > When I try
> > the function the backslash gets me again:
> >
> >>
> > readyPath("C:\Users\Rinker\Desktop\Research & Law\Data\School Data
> > 09-10")
> >
> > Error: '\U' used without hex digits in character string starting
> > "C:\U"
> 
> You cannot do that: you have to scan a file or escape \
> 
> > This is
> > what I'd like the function to return:
> >
> > [1]
> > "C:/Users/Rinker/Desktop/Research & Law/Data/School Data 09-10"
> >
> > I want a
> > function in which I enter a path and it returns the path with backslashes
> >
> > replaced
> > with forward slashes. Is there a way to make a function to do this?
> 
> ?normalizePath
> chartr("\\", "/", path)
> 
> > Windows 7
> > user
> >
> > R version
> > 2.14 beta
> >
> > Thank you,
> >
> > Tyler
> > Rinker
> >
> >
> >
> >
> > [[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
  
[[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] ATSP to TSP reformulation

2011-08-30 Thread Michael Hahsler

Hi Ian,

Your example runs for me without problems. It seems that you are using 
an older version of TSP. Please upgrade to the latest version TSP 
(update to TSP_1.0-3). I am using:


> sessionInfo()
R version 2.13.1 (2011-07-08)
Platform: i686-pc-linux-gnu (32-bit)

locale:
 [1] LC_CTYPE=en_US.UTF-8   LC_NUMERIC=C
 [3] LC_TIME=en_US.UTF-8LC_COLLATE=en_US.UTF-8
 [5] LC_MONETARY=C  LC_MESSAGES=en_US.UTF-8
 [7] LC_PAPER=en_US.UTF-8   LC_NAME=C
 [9] LC_ADDRESS=C   LC_TELEPHONE=C
[11] LC_MEASUREMENT=en_US.UTF-8 LC_IDENTIFICATION=C

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

other attached packages:
[1] TSP_1.0-3

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



Hint: use '<-' instead of '=' for assignments.


Regards,
Michael

--
  Dr. Michael Hahsler, Visiting Assistant Professor
  Department of Computer Science and Engineering
  Lyle School of Engineering
  Southern Methodist University, Dallas, Texas

  (214) 768-8878 * mhahs...@lyle.smu.edu * http://lyle.smu.edu/~mhahsler

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

2011-08-30 Thread samuel-rosa
Dear Julien

It is exactly what I need.

Thanks a lot.

-
Bc.Sc.Agri. Alessandro Samuel-Rosa
Postgraduate Program in Soil Science
Federal University of Santa Maria
Av. Roraima, nº 1000, Bairro Camobi, CEP 97105-970
Santa Maria, Rio Grande do Sul, Brazil
--
View this message in context: 
http://r.789695.n4.nabble.com/Conditional-plots-in-the-soiltexture-package-tp383p3778562.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] Saving a graph

2011-08-30 Thread Jannis
Chang Cheng,


this question has been asked on this list for several times. I would suggest 
you search the list archive (http://r.789695.n4.nabble.com/R-help-f789696.html 
or www.rseek.com) prior to posting in the future. "graph size many points pdf" 
would give you at least 10 threads with detailed description. There are 
numerous solutions and most of them point into Dieters or Brian Ripleys 
directions.


Jannis

--- Dieter Menne  schrieb am Di, 30.8.2011:

> Von: Dieter Menne 
> Betreff: Re: [R] Saving a graph
> An: r-help@r-project.org
> Datum: Dienstag, 30. August, 2011 05:57 Uhr
> 
> Gang Chen-4 wrote:
> > 
> > However, my problem is that the file generated
> > from a graph of fixed size is too large (in the order
> of 10MB) because of
> > many data points in multiple scatterplots. Any
> suggestions?
> > 
> 
> Generate pdf, open and save it in Adobe Acrobat which does
> a compression
> when the setting are correct.
> 
> Dieter
>   
> 
> 
> --
> View this message in context: 
> http://r.789695.n4.nabble.com/Saving-a-graph-tp3777456p3778015.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] url prep function (backslash issue)

2011-08-30 Thread Prof Brian Ripley

You seem to be looking for chartr("\\", "/", path) (and FAQ Q7.8)

What does any of this have to do with 'url prep': URLs are never 
written with backslashes?


On Tue, 30 Aug 2011, Tyler Rinker wrote:





Greeting R
Community,

I am a
windows user so this problem may be specific to windows. I often want to source
files from within R

such as:
C:\Users\Rinker\Desktop\Research & Law\Data\School Data 09-10. To source
this file I need to go

through the
path and replace all the backslashes (\) with forward slashes (/). I usually do
this in MS Word

using the
replace option, however, I'd like to do this in R. Attempting to write a
function to do this runs into

problems:

When I
enter the following:

readyPath
<- function(path){

z <- gsub("\", "/", path)

return(z)

}

I get:




readyPath <- function(path){

+ z <- gsub("\", "/", path)

+ return(z)

+ }

+

...meaning
R can't close the sequence (presumably because of the backslash which has
special meaning).

So I tried
(\\):



readyPath <- function(path){

z <- gsub("\\", "/", path)

return(z)

}This allows
the function to be stored as an object but I'm not sure if this is correct.


It isn't: please do read the help for gsub (\ is a metacharacter).


When I try
the function the backslash gets me again:




readyPath("C:\Users\Rinker\Desktop\Research & Law\Data\School Data
09-10")

Error: '\U' used without hex digits in character string starting
"C:\U"


You cannot do that: you have to scan a file or escape \


This is
what I'd like the function to return:

[1]
"C:/Users/Rinker/Desktop/Research & Law/Data/School Data 09-10"

I want a
function in which I enter a path and it returns the path with backslashes

replaced
with forward slashes. Is there a way to make a function to do this?


?normalizePath
chartr("\\", "/", path)


Windows 7
user

R version
2.14 beta

Thank you,

Tyler
Rinker




[[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] Error in f(x, ...) : could not find function "f2"

2011-08-30 Thread . .
Hi all,

I am getting the erro showed in the subject. I was strange the this
becomes to happen after a computer restar. I think after the restart
another function f2 was in memory and it scape from me.

func <- Vectorize(FUN=
  function(y, frac, rate, sad, samp="Poisson", trunc=0, ...){
f0 <- function(y,frac,n) {
f1 <- function(y,frac,n){
dpois(y,frac*n)
}
dcom <- paste("d",deparse(substitute(sad)),sep="")
dots <- c(as.name("n"),list(...))
f2 <- call(dcom,dots)
f <- function(n){
f1(y,frac,n)*f2(n)
}
myintegrate <- function() {
r <- 0
r1 <- 1
x1 <- 0
dx <- 20
while(r1 > 10e-500) {
r1 <- integrate(f,x1,x1+dx)$value
r <- r + r1
x1 <- x1 + dx
}
integrate(f,x1,Inf)$valu
}
myintegrate()
}
f0(y,frac,n)/(1-f0(trunc,frac,n))
},"y")

func(10, 0.1, 0.1, exp)

Any idea?

Thanks in advance.

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


  1   2   >