Re: [R] Change database in SQL Server using RODBC

2014-06-30 Thread Ira Sharenow

Thanks for everyone’s help.

I followed the instruction given on a variety of web pages in order to 
set up the connection. The problem is trying to use the first connection 
for a second database and doing so from within R.


It seems to me that an easy workaround is to simply set up another 
connection and use a second database as the default.


In Windows 7 the basic strategy is do the following:

Control Panel

Administrative Tools

Data Sources (ODBC)

In the ODBC Data Source Administrator pop up select SQL 2012 and then 
click on Add.


Since I do not have to work with a large number of databases, I consider 
this to be a satisfactory work around.


On 6/30/2014 8:17 AM, Frede Aakmann Tøgersen wrote:

Hi

I can see that you do have troubles understanding how all this works 
using the RODBC package. Peter wasn't really being helpful to you.


This is something that is quite difficult to help with not sitting 
beside you. Do you not having some local help from e.g. the IT department?


However for a start please let me know how you managed to get

con = odbcConnect("SQLServer2012")

to work.

It seems like that some DSN was set up.

From there we can probably find a solution.

Br. Frede


Sendt fra Samsung mobil


 Oprindelig meddelelse 
Fra: Ira Sharenow
Dato:30/06/2014 16.42 (GMT+01:00)
Til: Peter Crowther ,R list
Emne: Re: [R] Change database in SQL Server using RODBC

Thanks for everyone’s feedback.

library(RODBC)

con = odbcConnect("SQLServer2012")

orders1 = sqlFetch(con,"dbo.orders")

odbcClose(con)

Allowed me to close the connection properly. Thanks.

However, I still cannot figure out how to connect to the second database
and table.

library(RODBC)

>con2 = odbcConnect("[sportsDB].dbo.sports")

Warning messages:

1: In odbcDriverConnect("DSN=[sportsDB].dbo.sports") :

   [RODBC] ERROR: state IM002, code 0, message [Microsoft][ODBC Driver 
Manager] Data source name not found and no default driver specified


2: In odbcDriverConnect("DSN=[sportsDB].dbo.sports") :

   ODBC connection failed

>con2 = odbcConnect("[sportsDB].[dbo].sports")

Warning messages:

1: In odbcDriverConnect("DSN=[sportsDB].[dbo].sports") :

   [RODBC] ERROR: state IM002, code 0, message [Microsoft][ODBC Driver 
Manager] Data source name not found and no default driver specified


2: In odbcDriverConnect("DSN=[sportsDB].[dbo].sports") :

   ODBC connection failed

>con2 = odbcConnect("[sportsDB].[dbo].[sports]")

Warning messages:

1: In odbcDriverConnect("DSN=[sportsDB].[dbo].[sports]") :

   [RODBC] ERROR: state IM002, code 0, message [Microsoft][ODBC Driver 
Manager] Data source name not found and no default driver specified


2: In odbcDriverConnect("DSN=[sportsDB].[dbo].[sports]") :

   ODBC connection failed

>con3 = odbcConnect("SQLServer2012")

>orders3 =   sqlFetch(con3, "sportsDB.dbo.sports")

Error in odbcTableExists(channel, sqtable) :

   ‘sportsDB.dbo.sports’: table not found on channel

On 6/30/2014 1:34 AM, Peter Crowther wrote:
> On 30 June 2014 02:44, Ira Sharenow  wrote:
>> I wish to query tables that are NOT in the default SQL Server 2012 
database.

>> Now for the problem. I also want to read in the table dbo.sports. That
>> table is in the database sportsDB. I did not see any way to do so from
>> within R.
> Can you not use sportsDB.dbo.sports to reference the table?
>
> In general, table reference syntax is [ [ [ serverName '.' ]
> databaseName '.' ] [schema ] '.' ] tableName, where the names need
> only be surrounded by [...] if they are not valid SQL Server
> identifiers.  Many people may suggest you reference
> [sportsDB].[dbo].[sports]; this is unnecessary verbiage.
>
> Cheers,
>
> - Peter
>


[[alternative HTML version deleted]]



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


[R] 1-dinemsional point process

2014-06-30 Thread Doobs
Hi,
As a new user, is it possible to look at clustering/dispersion processes of
a 1D point process (i.e. points along a transect)?
My limited  understanding is that spatstat is for 2&3D point patterns.

Thanks



--
View this message in context: 
http://r.789695.n4.nabble.com/1-dinemsional-point-process-tp4693315.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] What are the other Options for hiddenActFunc in the RSNNS r package?

2014-06-30 Thread meg
I am trying to figure out the options for hiddenActFunc..any help would be
great!!



--
View this message in context: 
http://r.789695.n4.nabble.com/What-are-the-other-Options-for-hiddenActFunc-in-the-RSNNS-r-package-tp4693313.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] New editions of R Books from Chapman & Hall/CRC

2014-06-30 Thread Calver, Rob
Take advantage of a 20% discount on new editions of the most recent R books 
from Chapman & Hall/CRC! 

June and July will be very busy for us, with new editions of some of our most 
popular R books publishing. We are pleased to offer a 20% discount on these 
titles through our website. To take advantage of this offer, simply visit 
www.crcpress.com, choose your titles, and insert code AJL01 in the Promotion 
Code field at checkout. Standard Shipping is always FREE on all orders from 
CRCPress.com!

***

Linear Models with R, Second Edition
Julian Faraway

ISBN: 978-1-4398-8733-2
Publication Date: July 17, 2014
Number of pages: 286

New to the Second Edition
* Reorganized material on interpreting linear models, which distinguishes the 
main applications of prediction and explanation and introduces elementary 
notions of causality 
* Additional topics, including QR decomposition, splines, additive models, 
Lasso, multiple imputation, and false discovery rates
* Extensive use of the ggplot2 graphics package in addition to base graphics 

List Price: $89.95 / £57.99

For more details and to order: 
http://www.crcpress.com/product/isbn/9781439887332

***

Using R for Introductory Statistics, Second Edition
John Verzani

ISBN: 978-1-4665-9073-1
Publication Date: June 26, 2014
Number of pages: 518

New to the Second Edition:
* Increased emphasis on more idiomatic R provides a grounding in the 
functionality of base R
* Discussions of the use of RStudio helps new R users avoid as many pitfalls as 
possible
* Use of knitr package makes code easier to read and therefore easier to reason 
about
* Additional information on computer-intensive approaches motivates the 
traditional approach
* Updated examples and data make the information current and topical

List Price: $59.95 / £38.99

For more details and to order: 
http://www.crcpress.com/product/isbn/9781466590731

***

A Handbook of Statistical Analyses using R, Third Edition
Torsten Hothorn & Brian S. Everitt

ISBN: 978-1-4822-0458-2
Publication Date: June 25, 2014
Number of pages: 448 Pages

New to the Third Edition:
* Three new chapters on quantile regression, missing values, and Bayesian 
inference
* Extra material in the logistic regression chapter that describes a regression 
model for ordered categorical response variables
* Additional exercises
* More detailed explanations of R code
* New section in each chapter summarizing the results of the analyses 
* Updated version of the HSAUR package (HSAUR3), which includes some slides 
that can be used in introductory statistics courses

List Price: $64.95 / £39.99

For more details and to order: 
http://www.crcpress.com/product/isbn/9781482204582

***

SAS and R: Data Management, Statistical Analysis, and Graphics, Second Edition
Ken Kleinman & Nicholas J. Horton

ISBN: 978-1-4665-8449-5
Publication Date: July 9, 2014
Number of pages: 468

New to the Second Edition:
This edition now covers RStudio, a powerful and easy-to-use interface for R. It 
incorporates a number of additional topics, including using application program 
interfaces (APIs), accessing data through database management systems, using 
reproducible analysis tools, and statistical analysis with Markov chain Monte 
Carlo (MCMC) methods and finite mixture models. It also includes extended 
examples of simulations and many new examples.

List Price: $79.95 / £49.99

For more details and to order: 
http://www.crcpress.com/product/isbn/9781466584495

***

Introduction to Scientific Programming and Simulation Using R, Second Edition
Owen Jones, Robert Maillardet, Andrew Robinson

ISBN: 978-1-4665-6999-7
Publication Date: June 12, 2014
Number of pages: 600

New to the Second Edition:
In a new chapter on systems of ordinary differential equations (ODEs), the 
authors cover the Euler, midpoint, and fourth-order Runge-Kutta (RK4) schemes 
for solving systems of first-order ODEs. They compare the numerical efficiency 
of the different schemes experimentally and show how to improve the RK4 scheme 
by using an adaptive step size. There is also a new chapter focuses on both 
discrete- and continuous-time Markov chains. It describes transition and rate 
matrices, classification of states, limiting behaviour, Kolmogorov forward and 
backward equations, finite absorbing chains, and expected hitting times. It 
also presents methods for simulating discrete- and continuous-time chains as 
well as techniques for defining the state space, including lumping states and 
supplementary variables.

List Price: $79.95 / £49.99

For more details and to order: 
http://www.crcpress.com/product/isbn/9781466569997

***

Linear Mixed Models: A Practical Guide Using Statistical Software, Second 
Edition
Brady T. West, Kathleen B. Welch, Andrzej T Galecki

ISBN: 978-1-4665-6099-4
Publication Date: July 24, 2014
Number of pages: 440 

New to the Second Edition 
* A new chapter on models with crossed random effects that uses a case study to 
illustrate software procedures capable of fi

Re: [R] From long to wide format

2014-06-30 Thread arun
HI Jorge,

I was able to reproduce the error.  The link below provides a way to adjust the 
stack. I didn't test it.  


http://stackoverflow.com/questions/14719349/error-c-stack-usage-is-too-close-to-the-limit
Also check this link

http://stackoverflow.com/questions/13245019/how-to-change-the-stack-size-using-ulimit-or-per-process-on-mac-os-x-for-a-c-or


A.K.

On Monday, June 30, 2014 10:08 PM, Jorge I Velez  
wrote:



Hi Arun,

Thank you very much for your suggestion.   

While running some tests, I came across the following:

# sample data
n <- 2000
p <- 1000
x2 <- data.frame(variable = rep(paste0('x', 1:p), each = n), id = 
rep(paste0('p', 1:p), n), outcome = sample(0:2, n*p, TRUE), rate = runif(n*p, 
0.5, 1))
str(x2)

library(dplyr)
library(tidyr)

# Arun's suggestion
system.time({wide1 <- x2%>%
        select(-rate) %>%
        mutate(variable=factor(variable, levels=unique(variable)),id=factor(id, 
levels=unique(id))) %>%                 
            spread(variable,outcome)
colnames(wide1)[-1] <- paste("outcome",colnames(wide1)[-1],sep=".")
})

# Error: C stack usage  18920219 is too close to the limit
# Timing stopped at: 13.833 0.251 14.085


Do you happen to know what can be done to avoid this?

Thank you.

Best,
Jorge.-



On Mon, Jun 30, 2014 at 6:51 PM, arun  wrote:


>
>Hi Jorge,
>
>You may try:
>library(dplyr)
>library(tidyr)
>
>#Looks like this is faster than the other methods.
>system.time({wide1 <- x2%>%
>        select(-rate) %>%
>        mutate(variable=factor(variable, 
>levels=unique(variable)),id=factor(id, levels=unique(id))) %>% 
>    spread(variable,outcome)
>colnames(wide1)[-1] <- paste("outcome",colnames(wide1)[-1],sep=".")
>})
>
> #user  system elapsed
> #  0.006    0.00    0.006
>
>
>
>system.time(wide <- reshape(x2[, -4], v.names = "outcome", idvar = "id",
>   timevar = "variable", direction = "wide"))
> #user  system elapsed
> # 0.169   0.000   0.169
>
>
>
>system.time({
>sel <- unique(x2$variable)
>id <- unique(x2$id)
>
>X <- matrix(NA, ncol = length(sel) + 1, nrow = length(id))
>X[, 1] <- id
>colnames(X) <- c('id', sel)
>r <- mclapply(seq_along(sel), function(i){
>    out <- x2[x2$variable == sel[i], ][, 3]
>    }, mc.cores = 4)
>X[, -1] <- do.call(rbind, r)
>X
>})
>
># user  system elapsed
>#  0.125   0.011   0.074
>
>
> wide2 <- wide1
>wide2$id <- as.character(wide2$id)
> wide$id <- as.character(wide$id)
>all.equal(wide, wide2, check.attributes=F)
>#[1] TRUE
>
>A.K.
>
>
>
>
>On Sunday, June 29, 2014 11:48 PM, Jorge I Velez  
>wrote:
>Dear R-help,
>
>I am working with some data stored as "filename.txt.gz" in my working
>directory.
>After reading the data in using read.table(), I can see that each of them
>has four columns (variable, id, outcome, and rate) and the following
>structure:
>
># sample data
>x2 <- data.frame(variable = rep(paste0('x', 1:100), each = 100), id =
>rep(paste0('p', 1:100), 100), outcome = sample(0:2, 1, TRUE), rate =
>runif(1, 0.5, 1))
>str(x2)
>
>Each variable, i.e., x1, x2,..., x100 is repeated as many times as the
>number of unique IDs (100 in this example).  What I would like to do is to
>transform the data above
>in a long format.  I can do this by using
>
># reshape
>wide <- reshape(x2[, -4], v.names = "outcome", idvar = "id",
>                timevar = "variable", direction = "wide")
>str(wide)
>
># or a "hack" with mclapply:
>
>require(parallel)
>sel <- as.character(unique(x2$variable))
>id <- as.character(unique(x2$id))
>X <- matrix(NA, ncol = length(sel) + 1, nrow = length(id))
>X[, 1] <- id
>colnames(X) <- c('id', sel)
>r <- mclapply(seq_along(sel), function(i){
>                        out <- x2[x2$variable == sel[i], ][, 3]
>                        }, mc.cores = 4)
>X[, -1] <- do.call(rbind, r)
>X
>
>However, I was wondering if it is possible to come up with another solution
>, hopefully faster than these
>.  Unfortunately, either one of these takes a very long time to process,
>specially when the number of variables is very large
>(> 250,000) and the number of ids is ~2000.
>
>I would very much appreciate your suggestions.   At the end of this message
>is my sessionInfo().
>
>Thank you very much in advance.
>
>Best regards,
>Jorge Velez.-
>
>
>R>  sessionInfo()
>
>R version 3.0.2 Patched (2013-12-11 r64449)
>Platform: x86_64-apple-darwin10.8.0 (64-bit)
>
>locale:
>[1] en_AU.UTF-8/en_AU.UTF-8/en_AU.UTF-8/C/en_AU.UTF-8/en_AU.UTF-8
>
>attached base packages:
>[1] graphics  grDevices utils     datasets  parallel  compiler  stats
>[8] methods   base
>
>other attached packages:
>[1] knitr_1.6.3            ggplot2_1.0.0          slidifyLibraries_0.3.1
>[4] slidify_0.3.52
>
>loaded via a namespace (and not attached):
>[1] colorspace_1.2-4 digest_0.6.4     evaluate_0.5.5   formatR_0.10
>[5] grid_3.0.2       gtable_0.1.2     markdown_0.7.1   MASS_7.3-33
>[9] munsell_0.4.2    plyr_1.8.1       proto_0.3-10     Rcpp_0.11.2
>[13] reshape2_1.4     scales_0.2.4     

Re: [R] matrix

2014-06-30 Thread arun
Hi Izhak,
If the position of the elements to be replaced follow the pattern below:
seq(1,length(t), by=7)
#[1]  1  8 15

t[seq(1,length(t), by=7)] <- c(50,90,100)
A.K.






On Monday, June 30, 2014 4:19 PM, "Adams, Jean"  wrote:
t[1, 1] <- 50
t[3, 2] <- 90
t[5, 3] <- 100

Jean


On Mon, Jun 30, 2014 at 10:27 AM, IZHAK shabsogh 
wrote:

>
>
> kindly guide me on how i can delete and replace an element from a matrix t
> below
>
> for example delete first element in column one and replace it with 50,
> third element in column 2 by 90 and fifth element in column 3 by 100
>
>
> t1<-c(1,2,3,4,5)
> t2<-c(6,7,8,9,10)
> t3<-c(11,12,13,14,15)
> t<-cbind(t1,t2,t3)
>
>
> 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.
>

    [[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] R Console Output

2014-06-30 Thread Cheryl Johnson
Thank you for your response. I would like to produce Flash animation with
code such as what is below.

saveSWF({



}, img.name = "file",swf.name = "file2.swf" , single.opts = "'utf8':
false", autoplay = FALSE ,

interval = 0.1, imgdir = "directory", htmlfile = "random.html", ani.height
= 500,

ani.width = 500, title = "groups",

description = c("group1", "group2"))

Usually there is output in the console where the Flash animation has been
produced such as:

Flash has been created at:
C:\Users\CHERYL\AppData\Local\Temp\RtmpqayKkJ\file2.swf



When I run my code, there is the output below. Yet, the Flash file is not
produced, and there is no error message. I am still able to enter commands.
Thanks in advance for your help.



Executing: "C:\Program Files (x86)\SWFTools\png2swf.exe"
"C:\Users\CHERYL\AppData\Local\Temp\RtmpqayKkJ/file1.png"
"C:\Users\CHERYL\AppData\Local\Temp\RtmpqayKkJ/file2.png"
"C:\Users\CHERYL\AppData\Local\Temp\RtmpqayKkJ/file3.png"
"C:\Users\CHERYL\AppData\Local\Temp\RtmpqayKkJ/file4.png"
"C:\Users\CHERYL\AppData\Local\Temp\RtmpqayKkJ/file5.png"
"C:\Users\CHERYL\AppData\Local\Temp\RtmpqayKkJ/file6.png"
"C:\Users\CHERYL\AppData\Local\Temp\RtmpqayKkJ/file7.png"
"C:\Users\CHERYL\AppData\Local\Temp\RtmpqayKkJ/file8.png"
"C:\Users\CHERYL\AppData\Local\Temp\RtmpqayKkJ/file9.png"
"C:\Users\CHERYL\AppData\Local\Temp\RtmpqayKkJ/file00010.png"
"C:\Users\CHERYL\AppData\Local\Temp\RtmpqayKkJ/file00011.png"
"C:\Users\CHERYL\AppData\Local\Temp\RtmpqayKkJ/file00012.png"
"C:\Users\CHERYL\AppData\Local\Temp\RtmpqayKkJ/file00013.png"
"C:\Users\CHERYL\AppData\Local\Temp\RtmpqayKkJ/file00014.png"
"C:\Users\CHERYL\AppData\Local\Temp\RtmpqayKkJ/file00015.png"
"C:\Users\CHERYL\AppData\Local\Temp\RtmpqayKkJ/file00016.png"
"C:\Users\CHERYL\AppData\Local\Temp\RtmpqayKkJ/file00017.png"
"C:\Users\CHERYL\AppData\Local\Temp\RtmpqayKkJ/file00018.png"
"C:\Users\CHERYL\AppData\Local\Temp\RtmpqayKkJ/file00019.png"
"C:\Users\CHERYL\AppData\Local\Temp\RtmpqayKkJ/file00020.png"
"C:\Users\CHERYL\AppData\Local\Temp\RtmpqayKkJ/file00021.png"
"C:\Users\CHERYL\AppData\Local\Temp\RtmpqayKkJ/file00022.png"
"C:\Users\CHERYL\AppData\Local\Temp\RtmpqayKkJ/file00023.png"
"C:\Users\CHERYL\AppData\Local\Temp\RtmpqayKkJ/file00024.png"
"C:\Users\CHERYL\AppData\Local\Temp\RtmpqayKkJ/file00025.png"
"C:\Users\CHERYL\AppData\Local\Temp\RtmpqayKkJ/file00026.png"
"C:\Users\CHERYL\AppData\Local\Temp\RtmpqayKkJ/file00027.png"
"C:\Users\CHERYL\AppData\Local\Temp\RtmpqayKkJ/file00028.png"
"C:\Users\CHERYL\AppData\Local\Temp\RtmpqayKkJ/file00029.png"
"C:\Users\CHERYL\AppData\Local\Temp\RtmpqayKkJ/file00030.png"
"C:\Users\CHERYL\AppData\Local\Temp\RtmpqayKkJ/file00031.png"
"C:\Users\CHERYL\AppData\Local\Temp\RtmpqayKkJ/file00032.png"
"C:\Users\CHERYL\AppData\Local\Temp\RtmpqayKkJ/file00033.png"
"C:\Users\CHERYL\AppData\Local\Temp\RtmpqayKkJ/file00034.png"
"C:\Users\CHERYL\AppData\Local\Temp\RtmpqayKkJ/file00035.png"
"C:\Users\CHERYL\AppData\Local\Temp\RtmpqayKkJ/file00036.png"
"C:\Users\CHERYL\AppData\Local\Temp\RtmpqayKkJ/file00037.png"
"C:\Users\CHERYL\AppData\Local\Temp\RtmpqayKkJ/file00038.png"
"C:\Users\CHERYL\AppData\Local\Temp\RtmpqayKkJ/file00039.png"
"C:\Users\CHERYL\AppData\Local\Temp\RtmpqayKkJ/file00040.png"
"C:\Users\CHERYL\AppData\Local\Temp\RtmpqayKkJ/file00041.png"
"C:\Users\CHERYL\AppData\Local\Temp\RtmpqayKkJ/file00042.png"
"C:\Users\CHERYL\AppData\Local\Temp\RtmpqayKkJ/file00043.png"
"C:\Users\CHERYL\AppData\Local\Temp\RtmpqayKkJ/file00044.png"
"C:\Users\CHERYL\AppData\Local\Temp\RtmpqayKkJ/file00045.png"
"C:\Users\CHERYL\AppData\Local\Temp\RtmpqayKkJ/file00046.png"
"C:\Users\CHERYL\AppData\Local\Temp\RtmpqayKkJ/file00047.png"
"C:\Users\CHERYL\AppData\Local\Temp\RtmpqayKkJ/file00048.png"
"C:\Users\CHERYL\AppData\Local\Temp\RtmpqayKkJ/file00049.png"
"C:\Users\CHERYL\AppData\Local\Temp\RtmpqayKkJ/file00050.png"
"C:\Users\CHERYL\AppData\Local\Temp\RtmpqayKkJ/file00051.png"
"C:\Users\CHERYL\AppData\Local\Temp\RtmpqayKkJ/file00052.png"
"C:\Users\CHERYL\AppData\Local\Temp\RtmpqayKkJ/file00053.png"
"C:\Users\CHERYL\AppData\Local\Temp\RtmpqayKkJ/file00054.png"
"C:\Users\CHERYL\AppData\Local\Temp\RtmpqayKkJ/file00055.png"
"C:\Users\CHERYL\AppData\Local\Temp\RtmpqayKkJ/file00056.png"
"C:\Users\CHERYL\AppData\Local\Temp\RtmpqayKkJ/file00057.png"
"C:\Users\CHERYL\AppData\Local\Temp\RtmpqayKkJ/file00058.png"
"C:\Users\CHERYL\AppData\Local\Temp\RtmpqayKkJ/file00059.png"
"C:\Users\CHERYL\AppData\Local\Temp\RtmpqayKkJ/file00060.png"
"C:\Users\CHERYL\AppData\Local\Temp\RtmpqayKkJ/file00061.png"
"C:\Users\CHERYL\AppData\Local\Temp\RtmpqayKkJ/file00062.png"
"C:\Users\CHERYL\AppData\Local\Temp\RtmpqayKkJ/file00063.png"
"C:\Users\CHERYL\AppData\Local\Temp\RtmpqayKkJ/file00064.png"
"C:\Users\CHERYL\AppData\Local\Temp\RtmpqayKkJ/file00065.png"
"C:\Users\CHERYL\AppData\Local\Temp\RtmpqayKkJ/file00066.png"
"C:\Users\CHERYL\AppData\Local\Temp\RtmpqayKkJ/file00067.png"
"C:\Users\CHERYL\AppData\Local\Temp\RtmpqayKkJ/file00

[R] Must array methods be defined for user defined classes?

2014-06-30 Thread Dan Murphy
Here's a simple example:

setClass("foo", contains="numeric")
x <- new("foo", 4)

# Division by scalar works
> x / 2
An object of class "foo"
[1] 2

# Division by array blows up
y <- array(2, c(2, 2))
> x / y
Error in getDataPart(c(2, 2, 2, 2)) : node stack overflow

# Not sure I understand the error message, but in any case, based on
the success of ...
> x / as.numeric(y)
[1] 2 2 2 2

# ... wrote a division method for arrays, which worked.
> setMethod("/", signature = c("foo", "array"), function(e1, e2) e1 / 
> as.numeric(e2))
[1] "/"
> x / y
[1] 2 2 2 2

Is it always necessary to define "array" methods for arithmetic on
user defined classes? Maybe the answer has to do with the error
message I did not understand.

Thanks,
Dan Murphy

> sessionInfo()
R version 3.1.0 (2014-04-10)
Platform: x86_64-w64-mingw32/x64 (64-bit)

locale:
[1] LC_COLLATE=English_United States.1252  LC_CTYPE=English_United
States.1252LC_MONETARY=English_United States.1252 LC_NUMERIC=C
  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_3.1.0
>

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

2014-06-30 Thread Jorge I Velez
Hi Arun,

Thank you very much for your suggestion.

While running some tests, I came across the following:

# sample data
n <- 2000
p <- 1000
x2 <- data.frame(variable = rep(paste0('x', 1:p), each = n), id =
rep(paste0('p', 1:p), n), outcome = sample(0:2, n*p, TRUE), rate =
runif(n*p, 0.5, 1))
str(x2)

library(dplyr)
library(tidyr)

# Arun's suggestion
system.time({wide1 <- x2%>%
select(-rate) %>%
mutate(variable=factor(variable,
levels=unique(variable)),id=factor(id, levels=unique(id))) %>%

spread(variable,outcome)
colnames(wide1)[-1] <- paste("outcome",colnames(wide1)[-1],sep=".")
})

# Error: C stack usage  18920219 is too close to the limit
# Timing stopped at: 13.833 0.251 14.085


Do you happen to know what can be done to avoid this?

Thank you.

Best,
Jorge.-


On Mon, Jun 30, 2014 at 6:51 PM, arun  wrote:

>
>
> Hi Jorge,
>
> You may try:
> library(dplyr)
> library(tidyr)
>
> #Looks like this is faster than the other methods.
> system.time({wide1 <- x2%>%
> select(-rate) %>%
> mutate(variable=factor(variable,
> levels=unique(variable)),id=factor(id, levels=unique(id)))
> %>%
> spread(variable,outcome)
> colnames(wide1)[-1] <- paste("outcome",colnames(wide1)[-1],sep=".")
> })
>
>  #user  system elapsed
>  #  0.0060.000.006
>
>
>
> system.time(wide <- reshape(x2[, -4], v.names = "outcome", idvar = "id",
>timevar = "variable", direction = "wide"))
>  #user  system elapsed
>  # 0.169   0.000   0.169
>
>
>
> system.time({
> sel <- unique(x2$variable)
> id <- unique(x2$id)
> X <- matrix(NA, ncol = length(sel) + 1, nrow = length(id))
> X[, 1] <- id
> colnames(X) <- c('id', sel)
> r <- mclapply(seq_along(sel), function(i){
> out <- x2[x2$variable == sel[i], ][, 3]
> }, mc.cores = 4)
> X[, -1] <- do.call(rbind, r)
> X
> })
>
> # user  system elapsed
> #  0.125   0.011   0.074
>
>
>  wide2 <- wide1
> wide2$id <- as.character(wide2$id)
>  wide$id <- as.character(wide$id)
> all.equal(wide, wide2, check.attributes=F)
> #[1] TRUE
>
> A.K.
>
>
>
> On Sunday, June 29, 2014 11:48 PM, Jorge I Velez 
> wrote:
> Dear R-help,
>
> I am working with some data stored as "filename.txt.gz" in my working
> directory.
> After reading the data in using read.table(), I can see that each of them
> has four columns (variable, id, outcome, and rate) and the following
> structure:
>
> # sample data
> x2 <- data.frame(variable = rep(paste0('x', 1:100), each = 100), id =
> rep(paste0('p', 1:100), 100), outcome = sample(0:2, 1, TRUE), rate =
> runif(1, 0.5, 1))
> str(x2)
>
> Each variable, i.e., x1, x2,..., x100 is repeated as many times as the
> number of unique IDs (100 in this example).  What I would like to do is to
> transform the data above
> in a long format.  I can do this by using
>
> # reshape
> wide <- reshape(x2[, -4], v.names = "outcome", idvar = "id",
> timevar = "variable", direction = "wide")
> str(wide)
>
> # or a "hack" with mclapply:
>
> require(parallel)
> sel <- as.character(unique(x2$variable))
> id <- as.character(unique(x2$id))
> X <- matrix(NA, ncol = length(sel) + 1, nrow = length(id))
> X[, 1] <- id
> colnames(X) <- c('id', sel)
> r <- mclapply(seq_along(sel), function(i){
> out <- x2[x2$variable == sel[i], ][, 3]
> }, mc.cores = 4)
> X[, -1] <- do.call(rbind, r)
> X
>
> However, I was wondering if it is possible to come up with another solution
> , hopefully faster than these
> .  Unfortunately, either one of these takes a very long time to process,
> specially when the number of variables is very large
> (> 250,000) and the number of ids is ~2000.
>
> I would very much appreciate your suggestions.   At the end of this message
> is my sessionInfo().
>
> Thank you very much in advance.
>
> Best regards,
> Jorge Velez.-
>
>
> R>  sessionInfo()
>
> R version 3.0.2 Patched (2013-12-11 r64449)
> Platform: x86_64-apple-darwin10.8.0 (64-bit)
>
> locale:
> [1] en_AU.UTF-8/en_AU.UTF-8/en_AU.UTF-8/C/en_AU.UTF-8/en_AU.UTF-8
>
> attached base packages:
> [1] graphics  grDevices utils datasets  parallel  compiler  stats
> [8] methods   base
>
> other attached packages:
> [1] knitr_1.6.3ggplot2_1.0.0  slidifyLibraries_0.3.1
> [4] slidify_0.3.52
>
> loaded via a namespace (and not attached):
> [1] colorspace_1.2-4 digest_0.6.4 evaluate_0.5.5   formatR_0.10
> [5] grid_3.0.2   gtable_0.1.2 markdown_0.7.1   MASS_7.3-33
> [9] munsell_0.4.2plyr_1.8.1   proto_0.3-10 Rcpp_0.11.2
> [13] reshape2_1.4 scales_0.2.4 stringr_0.6.2tools_3.0.2
> [17] whisker_0.4  yaml_2.1.13
>
> [[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-containe

Re: [R] Getting data from Table in RStudio

2014-06-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 Shanae Clarke
> Sent: Monday, June 30, 2014 1:58 PM
> To: r-help@r-project.org
> Subject: [R] Getting data from Table in RStudio
> 
> Hello,
> 
> I am new to R progaming and have just started using this program since
> last week. What i want to achieve is to use R to determine patterns in
> sales/ customer complaint etc. information located in a mysql database.
> I am not sure how to approach this or which technique i should use to
> do so. However, i had proceeded to add a dataset to RStudio using the
> following code:
> library(RODBC)
> dsn.name <- "MySQLlocal"
> user.name <- "orange"
> pwd <- ""
> ch <- odbcConnect(dsn=dsn.name,uid=user.name,pwd = pwd)
> res <- sqlFetch(ch, "")
> odbcQuery(ch, "Select * from ")
> odbcClose(ch)
> 
> When the code is run all that is returned is
> > library (RODBC)
> > dsn.name <- "MySQLlocal"
>  > user.name <- "orange"
> > pwd <- ""
> > ch <- odbcConnect(dsn=dsn.name,uid=user.name,pwd = pwd)
> > res <- sqlFetch(ch, "")
> > odbcQuery(ch, "Select * from ")
>  [1] 1
> > odbcClose(ch)
> 
> No other results.
> I was expecting to see the table values or some other data. Not that.
> Maybe I am misunderstanding the whole concept of how R works.
> If so could someone please help me to clarify what the problem is and
> perhaps point me to a tutorial or somewhere i can get a information and
> get a better understanding.
> 
> Thank you. Your Help will be greatly appreciated.
> 
> Gayon Clarke
>   [[alternative HTML version deleted]]

1. For future reference, you should read the posting guide linked at the bottom 
of each email, and post only in plain text (no HTML).  

2. You should read the help files for each of the functions you are trying use.

3. Did you try to look at the object, res, that you created?  That should have 
contained the table that you fetched from the MySQL database.  You could have 
typed res and the table would have printed out.  You also could have used 
head(res) to look at the first few records, or used str(res) to examine the 
structure of res.

There is also an R-sig-DB list where you can get more specific help with 
database connectivity questions.
 https://stat.ethz.ch/mailman/listinfo/r-sig-db


Hope this is helpful,

Dan

Daniel J. Nordlund
Research and Data Analysis Division
Services & Enterprise Support Administration
Washington State Department of Social and Health Services


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

2014-06-30 Thread Jim Lemon
On Mon, 30 Jun 2014 11:13:18 PM Jim Lemon wrote:
> Hi all,
> I have managed, with the help of glob2rx() to get two parts of a text
> manipulation working. I have successfully gotten rid of the first and
> second bits, but I have hit the wall trying to get rid of the last bit.
> Here's an example:
> 
> initString<-
>  "\"Delete this\":value1,\"Delete this too\":value2},Delete last bit"
> sub("\"Delete this too\":","",
>  sub(glob2rx("*this\":*"),"",initString),fixed=TRUE)
> 
> This gives me:
> 
> [1] "value1,value2},Delete last bit"
> 
> and glob2rx("},*") just won't get rid of the last bit. I throw myself upon
> the mercy of the regular expression gurus.
> 
Hi again,
Sorry, but my "minimal reproducible example" was apparently 
misleading. "value1" and "value2" are not fixed strings, but varying 
numbers. After a night's sleep I solved the problem using strsplit(), which 
gave me a big list of strings that I could process without wearing out the 
"\" key. Thanks for the suggestions.

Jim

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

2014-06-30 Thread Shanae Clarke
Hello,

I am new to R progaming and have just started using this program since last 
week. What i want to achieve is to use R to determine patterns in sales/ 
customer complaint etc. information located in a mysql database. I am not sure 
how to approach this or which technique i should use to do so. However, i had 
proceeded to add a dataset to RStudio using the following code:
library(RODBC) 
dsn.name <- "MySQLlocal" 
user.name <- "orange"
pwd <- ""
ch <- odbcConnect(dsn=dsn.name,uid=user.name,pwd = pwd)
res <- sqlFetch(ch, "") 
odbcQuery(ch, "Select * from ")
odbcClose(ch)

When the code is run all that is returned is 
> library (RODBC)
> dsn.name <- "MySQLlocal"
 > user.name <- "orange" 
> pwd <- "" 
> ch <- odbcConnect(dsn=dsn.name,uid=user.name,pwd = pwd)
> res <- sqlFetch(ch, "") 
> odbcQuery(ch, "Select * from ")
 [1] 1 
> odbcClose(ch)

No other results.
I was expecting to see the table values or some other data. Not that.
Maybe I am misunderstanding the whole concept of how R works. 
If so could someone please help me to clarify what the problem is and perhaps 
point me to a tutorial or somewhere i can get a information and get a better 
understanding. 

Thank you. Your Help will be greatly appreciated. 

Gayon Clarke
[[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] Delaunay triangles with LONG/LAT + biomass

2014-06-30 Thread Rolf Turner

On 01/07/14 04:31, Trevor Davies wrote:

Hello,

I was hoping someone could point me in the direction towards a package
where I can use delaunay triangulation to create a polygon set where the
inside of the triangles are tagged with an estimate of a mean value of the
points making up the points of the triangle.  This is fisheries trawl data
if that helps add context.

For those familiar with the system, it's to make plots similar to those
made by the Dept of Fisheries and Oceans Canada in ACON (which has now
stopped being maintained).  Although freely available, I'm on a mac and it
would be nice to just get it sorted out in R going forward.

Ref here:
http://www2.mar.dfo-mpo.gc.ca/science/acon/Examples/ShadedContours.html


The deldir package has the capacity to tag points with values, and the 
triang.list() function creates a list of data frames corresponding to 
each triangle, the last column of these data frames (named "z") being 
the "values" associated with the corners of the triangles.


The means of these values can be calculated using sapply().

E.g.:

set.seed(42)
x <- runif(20)
y <- runif(20)
z <- sample(1:5,20,TRUE)
dxy <- deldir(x,y,z=z)
txy <- triang.list(dxy)
mxy <- sapply(txy,function(u){mean(u[["z"]])})

You could "tag" the triangles with these mean values by assigning the 
values as attributes of the components of txy, using lapply(), possibly.


Note that deldir() treats coordinates as ***Euclidean*** coordinates. 
This is only an approximation to a triangulation on a sphere.  Whether 
the approximation is good enough is up to you, I guess.


cheers,

Rolf Turner

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


Re: [R] How to combine/join/merge etc PCA and Cluster?

2014-06-30 Thread David L Carlson
Insert

data(dune)
data(dune.env)

after library(vegan)

David C.

-Original Message-
From: r-help-boun...@r-project.org [mailto:r-help-boun...@r-project.org] On 
Behalf Of David L Carlson
Sent: Monday, June 30, 2014 4:47 PM
To: Jackson Rodrigues; r-help@r-project.org
Subject: Re: [R] How to combine/join/merge etc PCA and Cluster?

This is a long way from being a reproducible example with no data. You also 
don't mention that you are using package vegan. I'll use the dune, dune.env 
data included in that package:

library(vegan)
mydata.pca <- rda(dune)
mydata.w <- hclust(dist(dune), "ward")
plot(mydata.w, hang=-1)
rect.hclust(mydata.w, 5)
gr <- cutree(mydata.w, k=5)
# Don't need grl <- levels(factor(gr))
sit.sc1 <- scores(mydata.pca, display="w", scaling=3)
p <- plot(mydata.pca,  display="wa", scaling=3, type="n",
   main="Mydata PCA and clusters")
# Don't need either abline() functions since plot() adds these.
# symbol = cluster (5 groups), color = Moisture (4 groups)
# Note, pch=16 and pch=19 are the same symbol so you don't want pch=15:19
points(sit.sc1, pch=as.numeric(gr), col=as.numeric(dune.env$Moisture))
# or 
points(sit.sc1, pch=as.numeric(gr)+20, bg=as.numeric(dune.env$Moisture))
# I'll skip the text labels
The legend will be complicated since there are groups*ecosytems combinations.

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





-Original Message-
From: r-help-boun...@r-project.org [mailto:r-help-boun...@r-project.org] On 
Behalf Of Jackson Rodrigues
Sent: Monday, June 30, 2014 9:03 AM
To: r-help@r-project.org
Subject: [R] How to combine/join/merge etc PCA and Cluster?

Hello everybody,

I Would like to get some help to plot together, Principal Components
Analysis (PCA) and clusters.
I am handling environmental data from 25 locations spread across 5
different ecosystems.When grouped into 5 clusters, locations from different
ecosystems are arranged in the same group.

So, I want to plot together PCA and Clusters, in a such way that  locations
belonging to the same ecosystem are displayed with the same COLORS, and
locations grouped in the same cluster, have the same SHAPE. For example:
I have 1 site from Savanna and 1 site from Serengeti  that are in the same
cluster, Thus I would like to plot both with different colors blue and
green, respectively due different ecosystem classification and with the
same shape (triangle) because they are in the same group. So, I would have
a cluster with 2 triangles one green and another blue.

How to make this combination?
There is command lines below that I'm using to make my combination, as
presented by Bocard in Numerical Ecology Analysis with R chapter 4 or 5.
with this code, it is possible to join PCA and Cluster however, without
differentiating the colors of each ecosystem.

#PCA
mydata.pca<-rda(mydata)
#Cluster
mydata.w <- hclust(dist(Sqchord.mydata), "ward")
plot(mydata.w, hang=-1)
rect.hclust(mydata.w, 5)

# Cut the dendrogram to yield 5 groups
gr <- cutree(mydata.w, k=5)
grl <- levels(factor(gr))

# Get the site scores, scaling 1
sit.sc1 <- scores(mydata.pca, display="w", scaling=3)

# Plot the sites with cluster symbols and colours (scaling 3)
p <- plot(mydata.pca,  display="wa", scaling=3, type="n",
  main="Mydata PCA and clusters")
abline(v=0, lty="dotted")
abline(h=0, lty="dotted")
for (i in 1:length(grl))
{  points(sit.sc1[gr==i,], pch=(14+i), cex=2.5, col=i+1)}
text(sit.sc1, row.names(Pre_euro_veg.1.all), cex=0.7, pos=3)

# Add legend interactively
legend(locator(1), paste("Cluster", c(1:length(grl))),
pch=14+c(1:length(grl)),
   col=1+c(1:length(grl)), pt.cex=2)

Thank you for any help.

Jackson Rodrigues

[[alternative HTML version deleted]]

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

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

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


Re: [R] How to combine/join/merge etc PCA and Cluster?

2014-06-30 Thread David L Carlson
This is a long way from being a reproducible example with no data. You also 
don't mention that you are using package vegan. I'll use the dune, dune.env 
data included in that package:

library(vegan)
mydata.pca <- rda(dune)
mydata.w <- hclust(dist(dune), "ward")
plot(mydata.w, hang=-1)
rect.hclust(mydata.w, 5)
gr <- cutree(mydata.w, k=5)
# Don't need grl <- levels(factor(gr))
sit.sc1 <- scores(mydata.pca, display="w", scaling=3)
p <- plot(mydata.pca,  display="wa", scaling=3, type="n",
   main="Mydata PCA and clusters")
# Don't need either abline() functions since plot() adds these.
# symbol = cluster (5 groups), color = Moisture (4 groups)
# Note, pch=16 and pch=19 are the same symbol so you don't want pch=15:19
points(sit.sc1, pch=as.numeric(gr), col=as.numeric(dune.env$Moisture))
# or 
points(sit.sc1, pch=as.numeric(gr)+20, bg=as.numeric(dune.env$Moisture))
# I'll skip the text labels
The legend will be complicated since there are groups*ecosytems combinations.

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





-Original Message-
From: r-help-boun...@r-project.org [mailto:r-help-boun...@r-project.org] On 
Behalf Of Jackson Rodrigues
Sent: Monday, June 30, 2014 9:03 AM
To: r-help@r-project.org
Subject: [R] How to combine/join/merge etc PCA and Cluster?

Hello everybody,

I Would like to get some help to plot together, Principal Components
Analysis (PCA) and clusters.
I am handling environmental data from 25 locations spread across 5
different ecosystems.When grouped into 5 clusters, locations from different
ecosystems are arranged in the same group.

So, I want to plot together PCA and Clusters, in a such way that  locations
belonging to the same ecosystem are displayed with the same COLORS, and
locations grouped in the same cluster, have the same SHAPE. For example:
I have 1 site from Savanna and 1 site from Serengeti  that are in the same
cluster, Thus I would like to plot both with different colors blue and
green, respectively due different ecosystem classification and with the
same shape (triangle) because they are in the same group. So, I would have
a cluster with 2 triangles one green and another blue.

How to make this combination?
There is command lines below that I'm using to make my combination, as
presented by Bocard in Numerical Ecology Analysis with R chapter 4 or 5.
with this code, it is possible to join PCA and Cluster however, without
differentiating the colors of each ecosystem.

#PCA
mydata.pca<-rda(mydata)
#Cluster
mydata.w <- hclust(dist(Sqchord.mydata), "ward")
plot(mydata.w, hang=-1)
rect.hclust(mydata.w, 5)

# Cut the dendrogram to yield 5 groups
gr <- cutree(mydata.w, k=5)
grl <- levels(factor(gr))

# Get the site scores, scaling 1
sit.sc1 <- scores(mydata.pca, display="w", scaling=3)

# Plot the sites with cluster symbols and colours (scaling 3)
p <- plot(mydata.pca,  display="wa", scaling=3, type="n",
  main="Mydata PCA and clusters")
abline(v=0, lty="dotted")
abline(h=0, lty="dotted")
for (i in 1:length(grl))
{  points(sit.sc1[gr==i,], pch=(14+i), cex=2.5, col=i+1)}
text(sit.sc1, row.names(Pre_euro_veg.1.all), cex=0.7, pos=3)

# Add legend interactively
legend(locator(1), paste("Cluster", c(1:length(grl))),
pch=14+c(1:length(grl)),
   col=1+c(1:length(grl)), pt.cex=2)

Thank you for any help.

Jackson Rodrigues

[[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] R Console Output

2014-06-30 Thread jim holtman
What do you mean by "stops"?  Can you at least show what was on the
console.  Can you continue to enter commands?  It is not clear what you are
talking about.


Jim Holtman
Data Munger Guru

What is the problem that you are trying to solve?
Tell me what you want to do, not how you want to do it.


On Mon, Jun 30, 2014 at 10:56 AM, Cheryl Johnson <
johnson.cheryl...@gmail.com> wrote:

> When I run code in R, my R console output stops before all the code has
> complied. There are no error messages, but there must be an error
> somewhere. Thanks in advance for any guidance.
>
> [[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] matrix

2014-06-30 Thread Adams, Jean
t[1, 1] <- 50
t[3, 2] <- 90
t[5, 3] <- 100

Jean


On Mon, Jun 30, 2014 at 10:27 AM, IZHAK shabsogh 
wrote:

>
>
> kindly guide me on how i can delete and replace an element from a matrix t
> below
>
> for example delete first element in column one and replace it with 50,
> third element in column 2 by 90 and fifth element in column 3 by 100
>
>
> t1<-c(1,2,3,4,5)
> t2<-c(6,7,8,9,10)
> t3<-c(11,12,13,14,15)
> t<-cbind(t1,t2,t3)
>
>
> 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.
>

[[alternative HTML version deleted]]

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


[R] R Console Output

2014-06-30 Thread Cheryl Johnson
When I run code in R, my R console output stops before all the code has
complied. There are no error messages, but there must be an error
somewhere. Thanks in advance for any guidance.

[[alternative HTML version deleted]]

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


[R] How to combine/join/merge etc PCA and Cluster?

2014-06-30 Thread Jackson Rodrigues
Hello everybody,

I Would like to get some help to plot together, Principal Components
Analysis (PCA) and clusters.
I am handling environmental data from 25 locations spread across 5
different ecosystems.When grouped into 5 clusters, locations from different
ecosystems are arranged in the same group.

So, I want to plot together PCA and Clusters, in a such way that  locations
belonging to the same ecosystem are displayed with the same COLORS, and
locations grouped in the same cluster, have the same SHAPE. For example:
I have 1 site from Savanna and 1 site from Serengeti  that are in the same
cluster, Thus I would like to plot both with different colors blue and
green, respectively due different ecosystem classification and with the
same shape (triangle) because they are in the same group. So, I would have
a cluster with 2 triangles one green and another blue.

How to make this combination?
There is command lines below that I'm using to make my combination, as
presented by Bocard in Numerical Ecology Analysis with R chapter 4 or 5.
with this code, it is possible to join PCA and Cluster however, without
differentiating the colors of each ecosystem.

#PCA
mydata.pca<-rda(mydata)
#Cluster
mydata.w <- hclust(dist(Sqchord.mydata), "ward")
plot(mydata.w, hang=-1)
rect.hclust(mydata.w, 5)

# Cut the dendrogram to yield 5 groups
gr <- cutree(mydata.w, k=5)
grl <- levels(factor(gr))

# Get the site scores, scaling 1
sit.sc1 <- scores(mydata.pca, display="w", scaling=3)

# Plot the sites with cluster symbols and colours (scaling 3)
p <- plot(mydata.pca,  display="wa", scaling=3, type="n",
  main="Mydata PCA and clusters")
abline(v=0, lty="dotted")
abline(h=0, lty="dotted")
for (i in 1:length(grl))
{  points(sit.sc1[gr==i,], pch=(14+i), cex=2.5, col=i+1)}
text(sit.sc1, row.names(Pre_euro_veg.1.all), cex=0.7, pos=3)

# Add legend interactively
legend(locator(1), paste("Cluster", c(1:length(grl))),
pch=14+c(1:length(grl)),
   col=1+c(1:length(grl)), pt.cex=2)

Thank you for any help.

Jackson Rodrigues

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

2014-06-30 Thread IZHAK shabsogh


kindly guide me on how i can delete and replace an element from a matrix t below

for example delete first element in column one and replace it with 50, third 
element in column 2 by 90 and fifth element in column 3 by 100


t1<-c(1,2,3,4,5)
t2<-c(6,7,8,9,10)
t3<-c(11,12,13,14,15)
t<-cbind(t1,t2,t3)


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.


Re: [R] yet another regular expression

2014-06-30 Thread arun
Hi Jim,
May be this helps:

library(stringr)
paste(str_extract_all(initString, 
perl('(?<=\\:)[[:alnum:]]+,?'))[[1]],collapse="")
#[1] "value1,value2"
A.K.




On Monday, June 30, 2014 9:58 AM, Jim Lemon  wrote:
Hi all,
I have managed, with the help of glob2rx() to get two parts of a text 
manipulation working. I have successfully gotten rid of the first and 
second bits, but I have hit the wall trying to get rid of the last bit. Here's 
an example:

initString<-
"\"Delete this\":value1,\"Delete this too\":value2},Delete last bit"
sub("\"Delete this too\":","",
sub(glob2rx("*this\":*"),"",initString),fixed=TRUE)

This gives me:

[1] "value1,value2},Delete last bit"

and glob2rx("},*") just won't get rid of the last bit. I throw myself upon 
the mercy of the regular expression gurus.

Jim

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/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] Delaunay triangles with LONG/LAT + biomass

2014-06-30 Thread MacQueen, Don
One place to start would be the "Spatial" task view on CRAN.
The other would be to ask on R-sig-geo, where people who specialize in
spatial data "hang out".

Delaunay triangulation is available in several packages. A simple search
for "delaunay" on the CRAN packages page will easily find at least one.
You will also need the sp package for sure.

Assigning a value to each triangle may or may not be easy, it will depend,
probably among other things, on the data structure returned by whatever
function you end up using to create the triangles.

Based on a quick look at your acon web page, you might be happy with
   akima::interp   Gridded Bivariate Interpolation for Irregular Data

-Don

-- 
Don MacQueen

Lawrence Livermore National Laboratory
7000 East Ave., L-627
Livermore, CA 94550
925-423-1062





On 6/30/14 9:31 AM, "Trevor Davies"  wrote:

>Hello,
>
>I was hoping someone could point me in the direction towards a package
>where I can use delaunay triangulation to create a polygon set where the
>inside of the triangles are tagged with an estimate of a mean value of the
>points making up the points of the triangle.  This is fisheries trawl data
>if that helps add context.
>
>For those familiar with the system, it's to make plots similar to those
>made by the Dept of Fisheries and Oceans Canada in ACON (which has now
>stopped being maintained).  Although freely available, I'm on a mac and it
>would be nice to just get it sorted out in R going forward.
>
>Ref here:
>http://www2.mar.dfo-mpo.gc.ca/science/acon/Examples/ShadedContours.html
>
>Thanks for the help.
>Cheers,
>Trevor
>
>   [[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] mixing grid and traditional graphics

2014-06-30 Thread Spencer Graves

Hi, Greg:  Thanks.  Just what I asked. Spencer


On 6/30/2014 10:24 AM, Greg Snow wrote:

If you really want to mix base and grid graphics (they don't play
nicely together as you have noticed) then you should really use the
gridBase package.  There is at least one package for doing maps using
grid (ggmap or ggMaps or something similar) and there is the regular
text function for adding text to a base graph, either of those may be
easier than mixing.

Since you are plotting the map after the text, whether the text is
visible or not depends on the background drawn for the map, I expect
that this differs for the different devices.  Would you be surprised
if you wrote some text on a piece of paper, then layed a paper map
over the top and could not read the paper?  If you want the text
visible on top of the map, do the text after the map.

On Sun, Jun 29, 2014 at 5:56 PM, Spencer Graves
 wrote:

   I'm confused with the results I'm getting from mixing grid and
traditional graphics.  A toy example appears below:  The png file created by
gridFn() shows "a label" over Africa, as expected. However, when run
interactively, "a label" appears for roughly half a second, then disappears.


   Can someone explain these results?


   Thanks,
   Spencer


gridFn <- function(){
   pushViewport(plotViewport())
   grid.text(label='a label')
   popViewport()
   map()
}

library(grid)
library(maps)
gridFn()

png('gridTst.png')
gridFn()
dev.off()



sessionInfo()

R version 3.1.0 (2014-04-10)
Platform: i386-w64-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] grid  stats graphics  grDevices utils datasets methods
[8] base

other attached packages:
[1] maps_2.3-7

loaded via a namespace (and not attached):
[1] tools_3.1.0
__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/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] standard error of survfit.coxph()

2014-06-30 Thread array chip
Thank you Terry for the explanation!

John




 From: "Therneau, Terry M., Ph.D." 

Sent: Monday, June 30, 2014 6:04 AM
Subject: Re:  standard error of survfit.coxph()


1. The computations "behind the scenes" produce the variance of the cumulative 
hazard. 
This is true for both an ordinary Kaplan-Meier and a Cox model.  
Transformations to other 
scales are done using simple Taylor series.

   H = cumulative hazard = log(S);  S=survival
   var(H) = var(log(S))  = the starting point
   S = exp(log(S)), so  var(S) is approx [deriv of exp(x)]^2 * var(log(S)) = 
S^2 var(H)
   var(log(log(S)) is approx (1/S^2) var(H)

2. At the time it was written, summary.survfit was used only for printing out 
the survival 
curve at selected times, and the audience for the printout wanted std(S).   
True, that was 
20 years ago, but I don't recall anyone ever asking for summary to do anything 
else.  Your 
request is not a bad idea.
   Note however that the primary impact of using log(S) or S or log(log(S)) 
scale is is on 
the confidence intervals, and they do appear per request in the summary output.

Terry T.


On 06/28/2014 05:00 AM, r-help-requ...@r-project.org wrote:
> Message: 9
> Date: Fri, 27 Jun 2014 12:39:29 -0700

> To:"r-help@r-project.org"  
> Subject: [R] standard error of survfit.coxph()
> Message-ID:
>     <1403897969.91269.yahoomail...@web122906.mail.ne1.yahoo.com>
> Content-Type: text/plain
>
> Hi, can anyone help me to understand the standard errors printed in the 
> output of survfit.coxph()?
>
> time<-sample(1:15,100,replace=T)
>
> status<-as.numeric(runif(100,0,1)<0.2)
> x<-rnorm(100,10,2)
>
> fit<-coxph(Surv(time,status)~x)
> ??? ### method 1
>
> survfit(fit, newdata=data.frame(time=time,status=status,x=x)[1:5,], 
> conf.type='log')$std.err
>
>  [,1]??? [,2]??? [,3]??? [,4]?? [,5]
> ?[1,] 0.0 0.0 0.0 0.0 0.
> ?[2,] 0.008627644 0.008567253 0.008773699 0.009354788 0.01481819
> ?[3,] 0.008627644 0.008567253 0.008773699 0.009354788 0.01481819
> ?[4,] 0.013800603 0.013767977 0.013889971 0.014379928 0.02353371
> ?[5,] 0.013800603 0.013767977 0.013889971 0.014379928 0.02353371
> ?[6,] 0.013800603 0.013767977 0.013889971 0.014379928 0.02353371
> ?[7,] 0.030226811 0.030423883 0.029806263 0.028918817 0.05191161
> ?[8,] 0.030226811 0.030423883 0.029806263 0.028918817 0.05191161
> ?[9,] 0.036852571 0.037159980 0.036186931 0.034645002 0.06485394
> [10,] 0.044181716 0.044621159 0.043221145 0.040872939 0.07931028
> [11,] 0.044181716 0.044621159 0.043221145 0.040872939 0.07931028
> [12,] 0.055452631 0.056018832 0.054236881 0.051586391 0.10800413
> [13,] 0.070665160 0.071363749 0.069208056 0.066655730 0.14976433
> [14,] 0.124140400 0.125564637 0.121281571 0.118002021 0.30971860
> [15,] 0.173132357 0.175309455 0.168821266 0.164860523 0.46393111
>
> survfit(fit, newdata=data.frame(time=time,status=status,x=x)[1:5,], 
> conf.type='log')$time
> ?[1]? 1? 2? 3? 4? 5? 6? 7? 8? 9 10 11 12 13 14 15
>
> ??? ### method 2
>
> summary(survfit(fit, newdata=data.frame(time=time,status=status,x=x)[1:5,], 
> conf.type='log'),time=10)$std.err
>
> ? 1? 2? 3? 4? 5
> [1,] 0.04061384 0.04106186 0.03963184 0.03715246 0.06867532
>
> By reading the help of ?survfit.object and ?summary.survfit, the standard 
> error provided in the output of method 1 (survfit()) was for cumulative 
> hazard-log(survival), while the standard error provided in the output of 
> method 2 (summary.survfit()) was for survival itself, regardless of how you 
> choose the value for "conf.type" ('log', 'log-log' or 'plain'). This explains 
> why the standard error output is different between method 1 (10th row) and 
> method 2.
>
> My question is how do I get standard error estimates for log(-log(survival))?
>
> Thanks!
>
> John
[[alternative HTML version deleted]]

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


Re: [R] How to plot individual pdf files for each wrapped plot with ggplot2?

2014-06-30 Thread Trevor Davies
I think the easiest most straight forward way would be to just throw it
into a loop and subset the data on each loop around (untested code below
but I'm sure you get the gist).  ~Trevor

sex1<-unique(tips$sex)
day1<-unique(tips$day)
for (i in 1:length(sex1)){
   for (j in 1:length(day1)){


pdf(paste('example_',sex1[i],day1[j],'.pdf',sep=''))

data1<-subset(tips, sex==sex1[i] & day==day1[j])
sp <- ggplot(data1,aes(x=total_bill, y = tip/total_bill)) +
geom_point(shape=1)
plot(sp)
dev.off()
}
}



On Mon, Jun 30, 2014 at 10:23 AM, Bea GD  wrote:

> Hi,
>
> I'm working with tips data from reshape package.
>
> library(reshape2)
>
> I'm saving my plots as pdf and I was wondering whether it was possible
> to print a different pdf for each 'wrapped' plot. Using the code below
> as an example, I'd like to get 8 independent pdf files for each sex ~
> day combination.
>
> sp <- ggplot(tips,aes(x=total_bill, y = tip/total_bill)) +
> geom_point(shape=1) +
> facet_grid(sex ~ day)
> plot(sp)
>
> Thanks a lot for your help!
>
> [[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] mixing grid and traditional graphics

2014-06-30 Thread Greg Snow
If you really want to mix base and grid graphics (they don't play
nicely together as you have noticed) then you should really use the
gridBase package.  There is at least one package for doing maps using
grid (ggmap or ggMaps or something similar) and there is the regular
text function for adding text to a base graph, either of those may be
easier than mixing.

Since you are plotting the map after the text, whether the text is
visible or not depends on the background drawn for the map, I expect
that this differs for the different devices.  Would you be surprised
if you wrote some text on a piece of paper, then layed a paper map
over the top and could not read the paper?  If you want the text
visible on top of the map, do the text after the map.

On Sun, Jun 29, 2014 at 5:56 PM, Spencer Graves
 wrote:
>   I'm confused with the results I'm getting from mixing grid and
> traditional graphics.  A toy example appears below:  The png file created by
> gridFn() shows "a label" over Africa, as expected. However, when run
> interactively, "a label" appears for roughly half a second, then disappears.
>
>
>   Can someone explain these results?
>
>
>   Thanks,
>   Spencer
>
>
> gridFn <- function(){
>   pushViewport(plotViewport())
>   grid.text(label='a label')
>   popViewport()
>   map()
> }
>
> library(grid)
> library(maps)
> gridFn()
>
> png('gridTst.png')
> gridFn()
> dev.off()
>
>
>> sessionInfo()
> R version 3.1.0 (2014-04-10)
> Platform: i386-w64-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] grid  stats graphics  grDevices utils datasets methods
> [8] base
>
> other attached packages:
> [1] maps_2.3-7
>
> loaded via a namespace (and not attached):
> [1] tools_3.1.0
>>
>
> __
> R-help@r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.



-- 
Gregory (Greg) L. Snow Ph.D.
538...@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] How to plot individual pdf files for each wrapped plot with ggplot2?

2014-06-30 Thread Bea GD
Hi,

I'm working with tips data from reshape package.

library(reshape2)

I'm saving my plots as pdf and I was wondering whether it was possible 
to print a different pdf for each 'wrapped' plot. Using the code below 
as an example, I'd like to get 8 independent pdf files for each sex ~ 
day combination.

sp <- ggplot(tips,aes(x=total_bill, y = tip/total_bill)) +
geom_point(shape=1) +
facet_grid(sex ~ day)
plot(sp)

Thanks a lot for your help!

[[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] Delaunay triangles with LONG/LAT + biomass

2014-06-30 Thread Trevor Davies
Hello,

I was hoping someone could point me in the direction towards a package
where I can use delaunay triangulation to create a polygon set where the
inside of the triangles are tagged with an estimate of a mean value of the
points making up the points of the triangle.  This is fisheries trawl data
if that helps add context.

For those familiar with the system, it's to make plots similar to those
made by the Dept of Fisheries and Oceans Canada in ACON (which has now
stopped being maintained).  Although freely available, I'm on a mac and it
would be nice to just get it sorted out in R going forward.

Ref here:
http://www2.mar.dfo-mpo.gc.ca/science/acon/Examples/ShadedContours.html

Thanks for the help.
Cheers,
Trevor

[[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] A Question about read.table and Data Frames in R

2014-06-30 Thread David L Carlson
You are also missing the fact that loops are often not required in R. In this 
case print() has a method for printing data frames and that method is 
automatically used when you simply type the data.frame name or if you 
explicitly call it with print(stockList):

> stockList <- read.table(text="symbol,shares
+ XOM,1000
+ APA,400
+ CVX,200", header = T, sep=",")
> 
> stockList
  symbol shares
1XOM   1000
2APA400
3CVX200

You will save yourself hours of frustration by reading some of the official and 
unofficial documentation for R:

http://cran.r-project.org/manuals.html
http://www.r-project.org/other-docs.html
http://cran.r-project.org/other-docs.html

David Carlson

-Original Message-
From: r-help-boun...@r-project.org [mailto:r-help-boun...@r-project.org] On 
Behalf Of David Winsemius
Sent: Sunday, June 29, 2014 5:58 PM
To: Robert Sherry
Cc: r-help@r-project.org
Subject: Re: [R] A Question about read.table and Data Frames in R


On Jun 29, 2014, at 3:22 PM, Robert Sherry wrote:

> I created the following file:
>
> symbol,shares
> XOM,1000
> APA,400
> CVX,200
>
> I then read the file in R using the command:
>   stockList=read.table("/NotesOnR/stockList", header = T, sep=",")
>
> I would then expect the following expression to evaluate to the simple
> string APA:
>   stockList$symbol[2]
> However when I type that in on the command line, I get:
> [1] APA
> Levels: APA CVX XOM
>
> I would also expect to be able to print out the table by using the  
> command:
>   for( i in 1:3 ) {
>   print( stockList$symbol[i] )
>   print ( stockList$shares[i] )
>   }
>
> However, as part of the output I get:
>   Levels: APA CVX XOM
> I do not understand what is going on. Also, when I try passing the
> expression stockList$symbol to a standard function in R, it does not  
> work.
>
> I think that I am missing something here but I am not sure what I am
> missing.

You are missing the fact that a factor variable was created. If you  
had added stringsAsFactors=FALSE to your read.table code, you would  
ahve gotten what you expected.


> Should I be writing code like:
>   for  ( i in stockList$smybol )
> However,  given the symbol, I am not sure how to get the share count  
> that is
> in the same row.
>
> I thank the group in advance for their responses.
>
> Bob
>
> __
> R-help@r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/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
Alameda, CA, USA

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

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/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] Change database in SQL Server using RODBC

2014-06-30 Thread Frede Aakmann Tøgersen
Hi

I can see that you do have troubles understanding how all this works using the 
RODBC package. Peter wasn't really being helpful to you.

This is something that is quite difficult to help with not sitting beside you. 
Do you not having some local help from e.g. the IT department?

However for a start please let me know how you managed to get

con = odbcConnect("SQLServer2012")

to work.

It seems like that some DSN was set up.

From there we can probably find a solution.

Br. Frede


Sendt fra Samsung mobil


 Oprindelig meddelelse 
Fra: Ira Sharenow
Dato:30/06/2014 16.42 (GMT+01:00)
Til: Peter Crowther ,R list
Emne: Re: [R] Change database in SQL Server using RODBC

Thanks for everyone’s feedback.

library(RODBC)

con = odbcConnect("SQLServer2012")

orders1 = sqlFetch(con,"dbo.orders")

odbcClose(con)

Allowed me to close the connection properly. Thanks.

However, I still cannot figure out how to connect to the second database
and table.

library(RODBC)

>con2 = odbcConnect("[sportsDB].dbo.sports")

Warning messages:

1: In odbcDriverConnect("DSN=[sportsDB].dbo.sports") :

   [RODBC] ERROR: state IM002, code 0, message [Microsoft][ODBC Driver Manager] 
Data source name not found and no default driver specified

2: In odbcDriverConnect("DSN=[sportsDB].dbo.sports") :

   ODBC connection failed

>con2 = odbcConnect("[sportsDB].[dbo].sports")

Warning messages:

1: In odbcDriverConnect("DSN=[sportsDB].[dbo].sports") :

   [RODBC] ERROR: state IM002, code 0, message [Microsoft][ODBC Driver Manager] 
Data source name not found and no default driver specified

2: In odbcDriverConnect("DSN=[sportsDB].[dbo].sports") :

   ODBC connection failed

>con2 = odbcConnect("[sportsDB].[dbo].[sports]")

Warning messages:

1: In odbcDriverConnect("DSN=[sportsDB].[dbo].[sports]") :

   [RODBC] ERROR: state IM002, code 0, message [Microsoft][ODBC Driver Manager] 
Data source name not found and no default driver specified

2: In odbcDriverConnect("DSN=[sportsDB].[dbo].[sports]") :

   ODBC connection failed

>con3 = odbcConnect("SQLServer2012")

>orders3 =   sqlFetch(con3, "sportsDB.dbo.sports")

Error in odbcTableExists(channel, sqtable) :

   ‘sportsDB.dbo.sports’: table not found on channel

On 6/30/2014 1:34 AM, Peter Crowther wrote:
> On 30 June 2014 02:44, Ira Sharenow  wrote:
>> I wish to query tables that are NOT in the default SQL Server 2012 database.
>> Now for the problem. I also want to read in the table dbo.sports. That
>> table is in the database sportsDB. I did not see any way to do so from
>> within R.
> Can you not use sportsDB.dbo.sports to reference the table?
>
> In general, table reference syntax is [ [ [ serverName '.' ]
> databaseName '.' ] [schema ] '.' ] tableName, where the names need
> only be surrounded by [...] if they are not valid SQL Server
> identifiers.  Many people may suggest you reference
> [sportsDB].[dbo].[sports]; this is unnecessary verbiage.
>
> Cheers,
>
> - Peter
>


[[alternative HTML version deleted]]


[[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] Change database in SQL Server using RODBC

2014-06-30 Thread Jeff Newmiller
Please post here using the plain text option in your email software because the 
HTML is not coming through undamaged.

The first argument to the odbcConnect function is never SQL syntax... for SQL 
Server it is always a "Data Source Name" (DSN) that has been predefined in the 
ODBC administration tool (control panel on Windows).

If the databases you are trying to access are managed by the same server and 
your authentication gives you access to all the databases and tables that you 
need access to, then you can construct SQL queries that refer to other tables 
in other databases on that server using the "dot" notation mentioned by Peter, 
and pass all those queries through the same DSN.

Something like

library(RODBC)
con <- odbcConnect("SQLServer2012")
orders1 <- sqlFetch(con,"sportsDB.dbo.sports")
odbcClose(con)
---
Jeff NewmillerThe .   .  Go Live...
DCN:Basics: ##.#.   ##.#.  Live Go...
  Live:   OO#.. Dead: OO#..  Playing
Research Engineer (Solar/BatteriesO.O#.   #.O#.  with
/Software/Embedded Controllers)   .OO#.   .OO#.  rocks...1k
--- 
Sent from my phone. Please excuse my brevity.

On June 30, 2014 7:39:25 AM PDT, Ira Sharenow  wrote:
>Thanks for everyone���s feedback.
>
>library(RODBC)
>
>con = odbcConnect("SQLServer2012")
>
>orders1 = sqlFetch(con,"dbo.orders")
>
>odbcClose(con)
>
>Allowed me to close the connection properly. Thanks.
>
>However, I still cannot figure out how to connect to the second
>database 
>and table.
>
>library(RODBC)
>
>>con2 = odbcConnect("[sportsDB].dbo.sports")
>
>Warning messages:
>
>1: In odbcDriverConnect("DSN=[sportsDB].dbo.sports") :
>
>[RODBC] ERROR: state IM002, code 0, message [Microsoft][ODBC Driver
>Manager] Data source name not found and no default driver specified
>
>2: In odbcDriverConnect("DSN=[sportsDB].dbo.sports") :
>
>   ODBC connection failed
>
>>con2 = odbcConnect("[sportsDB].[dbo].sports")
>
>Warning messages:
>
>1: In odbcDriverConnect("DSN=[sportsDB].[dbo].sports") :
>
>[RODBC] ERROR: state IM002, code 0, message [Microsoft][ODBC Driver
>Manager] Data source name not found and no default driver specified
>
>2: In odbcDriverConnect("DSN=[sportsDB].[dbo].sports") :
>
>   ODBC connection failed
>
>>con2 = odbcConnect("[sportsDB].[dbo].[sports]")
>
>Warning messages:
>
>1: In odbcDriverConnect("DSN=[sportsDB].[dbo].[sports]") :
>
>[RODBC] ERROR: state IM002, code 0, message [Microsoft][ODBC Driver
>Manager] Data source name not found and no default driver specified
>
>2: In odbcDriverConnect("DSN=[sportsDB].[dbo].[sports]") :
>
>   ODBC connection failed
>
>>con3 = odbcConnect("SQLServer2012")
>
>>orders3 =   sqlFetch(con3, "sportsDB.dbo.sports")
>
>Error in odbcTableExists(channel, sqtable) :
>
>   ���sportsDB.dbo.sports���: table not found on channel
>
>On 6/30/2014 1:34 AM, Peter Crowther wrote:
>> On 30 June 2014 02:44, Ira Sharenow  wrote:
>>> I wish to query tables that are NOT in the default SQL Server 2012
>database.
>>> Now for the problem. I also want to read in the table dbo.sports.
>That
>>> table is in the database sportsDB. I did not see any way to do so
>from
>>> within R.
>> Can you not use sportsDB.dbo.sports to reference the table?
>>
>> In general, table reference syntax is [ [ [ serverName '.' ]
>> databaseName '.' ] [schema ] '.' ] tableName, where the names need
>> only be surrounded by [...] if they are not valid SQL Server
>> identifiers.  Many people may suggest you reference
>> [sportsDB].[dbo].[sports]; this is unnecessary verbiage.
>>
>> Cheers,
>>
>> - Peter
>>
>
>
>   [[alternative HTML version deleted]]
>
>
>
>
>
>__
>R-help@r-project.org mailing list
>https://stat.ethz.ch/mailman/listinfo/r-help
>PLEASE do read the posting guide
>http://www.R-project.org/posting-guide.html
>and provide commented, minimal, self-contained, reproducible code.

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/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] Change database in SQL Server using RODBC

2014-06-30 Thread Ira Sharenow
Thanks for everyone’s feedback.

library(RODBC)

con = odbcConnect("SQLServer2012")

orders1 = sqlFetch(con,"dbo.orders")

odbcClose(con)

Allowed me to close the connection properly. Thanks.

However, I still cannot figure out how to connect to the second database 
and table.

library(RODBC)

>con2 = odbcConnect("[sportsDB].dbo.sports")

Warning messages:

1: In odbcDriverConnect("DSN=[sportsDB].dbo.sports") :

   [RODBC] ERROR: state IM002, code 0, message [Microsoft][ODBC Driver Manager] 
Data source name not found and no default driver specified

2: In odbcDriverConnect("DSN=[sportsDB].dbo.sports") :

   ODBC connection failed

>con2 = odbcConnect("[sportsDB].[dbo].sports")

Warning messages:

1: In odbcDriverConnect("DSN=[sportsDB].[dbo].sports") :

   [RODBC] ERROR: state IM002, code 0, message [Microsoft][ODBC Driver Manager] 
Data source name not found and no default driver specified

2: In odbcDriverConnect("DSN=[sportsDB].[dbo].sports") :

   ODBC connection failed

>con2 = odbcConnect("[sportsDB].[dbo].[sports]")

Warning messages:

1: In odbcDriverConnect("DSN=[sportsDB].[dbo].[sports]") :

   [RODBC] ERROR: state IM002, code 0, message [Microsoft][ODBC Driver Manager] 
Data source name not found and no default driver specified

2: In odbcDriverConnect("DSN=[sportsDB].[dbo].[sports]") :

   ODBC connection failed

>con3 = odbcConnect("SQLServer2012")

>orders3 =   sqlFetch(con3, "sportsDB.dbo.sports")

Error in odbcTableExists(channel, sqtable) :

   ‘sportsDB.dbo.sports’: table not found on channel

On 6/30/2014 1:34 AM, Peter Crowther wrote:
> On 30 June 2014 02:44, Ira Sharenow  wrote:
>> I wish to query tables that are NOT in the default SQL Server 2012 database.
>> Now for the problem. I also want to read in the table dbo.sports. That
>> table is in the database sportsDB. I did not see any way to do so from
>> within R.
> Can you not use sportsDB.dbo.sports to reference the table?
>
> In general, table reference syntax is [ [ [ serverName '.' ]
> databaseName '.' ] [schema ] '.' ] tableName, where the names need
> only be surrounded by [...] if they are not valid SQL Server
> identifiers.  Many people may suggest you reference
> [sportsDB].[dbo].[sports]; this is unnecessary verbiage.
>
> Cheers,
>
> - Peter
>


[[alternative HTML version deleted]]

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


Re: [R] yet another regular expression

2014-06-30 Thread Jeff Newmiller
If everything Regular Expressions could do could be done with globbing then RE 
would likely not exist.

I have interpreted your problem as:

Start at the beginning of the string ("^")
match stuff that is not a colon ("[^:]")
match a colon (":')
keep stuff that is not a comma ("([^,]*)")
match a comma (",")
keep stuff that is not a right brace ("([^}]*)")
match a right brace and comma ("},")
match any characters (".*")
up to the end of the string ("$")

and then substitute that whole matched string with

the first kept match ("\\1")
a comma (",")
the second kept match ("\\2")

which gives

sub("^[^:]*:([^,]*),[^:]*:([^}]*)},.*$","\\1,\\2",initString)

The separator comma could be wrapped with the first and second kept matches in 
this case to make a single kept match.. I was just methodically working my way 
through your pattern finding pieces of interest.
---
Jeff NewmillerThe .   .  Go Live...
DCN:Basics: ##.#.   ##.#.  Live Go...
  Live:   OO#.. Dead: OO#..  Playing
Research Engineer (Solar/BatteriesO.O#.   #.O#.  with
/Software/Embedded Controllers)   .OO#.   .OO#.  rocks...1k
--- 
Sent from my phone. Please excuse my brevity.

On June 30, 2014 6:13:18 AM PDT, Jim Lemon  wrote:
>Hi all,
>I have managed, with the help of glob2rx() to get two parts of a text 
>manipulation working. I have successfully gotten rid of the first and 
>second bits, but I have hit the wall trying to get rid of the last bit.
>Here's 
>an example:
>
>initString<-
> "\"Delete this\":value1,\"Delete this too\":value2},Delete last bit"
>sub("\"Delete this too\":","",
> sub(glob2rx("*this\":*"),"",initString),fixed=TRUE)
>
>This gives me:
>
>[1] "value1,value2},Delete last bit"
>
>and glob2rx("},*") just won't get rid of the last bit. I throw myself
>upon 
>the mercy of the regular expression gurus.
>
>Jim
>
>__
>R-help@r-project.org mailing list
>https://stat.ethz.ch/mailman/listinfo/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] yet another regular expression

2014-06-30 Thread Duncan Mackay
Hi Jim

What about trying to use what you want to keep

m=gregexpr('\\":value[12]+[}]?,', initString)
regmatches(initString, m)
[[1]]
[1] "\":value1,"  "\":value2},"

Duncan

Duncan Mackay
Department of Agronomy and Soil Science
University of New England
Armidale NSW 2351
Email: home: mac...@northnet.com.au

-Original Message-
From: r-help-boun...@r-project.org [mailto:r-help-boun...@r-project.org] On
Behalf Of Jim Lemon
Sent: Monday, 30 June 2014 23:13
To: r-help@r-project.org
Subject: [R] yet another regular expression

Hi all,
I have managed, with the help of glob2rx() to get two parts of a text 
manipulation working. I have successfully gotten rid of the first and 
second bits, but I have hit the wall trying to get rid of the last bit.
Here's 
an example:

initString<-
 "\"Delete this\":value1,\"Delete this too\":value2},Delete last bit"
sub("\"Delete this too\":","",
 sub(glob2rx("*this\":*"),"",initString),fixed=TRUE)

This gives me:

[1] "value1,value2},Delete last bit"

and glob2rx("},*") just won't get rid of the last bit. I throw myself upon 
the mercy of the regular expression gurus.

Jim

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

2014-06-30 Thread C Lin
Hi, Bill

Thank you so much for your kind explanation. It's very clear too for someone 
like me.
I should've remember this but somehow forgot that [] have a special meaning in 
regular expression.

Lin


> From: wdun...@tibco.com
> Date: Sun, 29 Jun 2014 13:16:26 -0700
> Subject: Re: [R] regular expression help
> To: bac...@hotmail.com
> CC: dwinsem...@comcast.net; r-help@r-project.org
>
>> what's the difference between [:space:]+ and[[:space:]]+ ?
>
> The pattern '[:space:]' matches any of ':', 's', 'p', 'a', 'c', and
> 'e' (the second colon is superfluous). I.e., it has no magic meaning.
> Inside of [] it does have a special meaning.
>
> The pattern '[[:space:]]' matches a space, a newline, and other
> whitespace characters. The pattern '[a-c[:space:]z[:digit:]]' matches
> 'a', 'b', 'c', any decimal digit, and any whitespace character.
> Bill Dunlap
> TIBCO Software
> wdunlap tibco.com
>
>
> On Fri, Jun 27, 2014 at 6:27 AM, C Lin  wrote:
>> Thank you all for your help.
>>
>> Bill, thanks for making it compact and I did mean any amount of whitespace.
>>
>> To break it down, so I know why this pattern work:
>> The first parenthesis means that before AARSD1 it can be
>> ^: begins with nothing
>> |: or
>> //: double slash or
>> [[:space:]]+: one or more whitespace character
>>
>> For the second parenthesis:
>> $: ending with nothing
>>
>> Do this sound correct?
>>
>> I missed the fact that I need the ^ and $ and I always do [:space:]+ instead 
>> of [[:space:]]+
>> what's the difference between [:space:]+ and[[:space:]]+ ?
>>
>> Thanks so much!
>> Lin
>>
>> 
>>> From: wdun...@tibco.com
>>> Date: Fri, 27 Jun 2014 02:35:54 -0700
>>> Subject: Re: [R] regular expression help
>>> To: dwinsem...@comcast.net
>>> CC: bac...@hotmail.com; r-help@r-project.org
>>>
>>> You can use parentheses to factor out the common string in David's
>>> pattern, as in
>>> grep(value=TRUE, "(^|//|[[:space:]]+)AARSD1($|//|[[:space:]]+)", test)
>>>
>>> (By 'whitespace' I could not tell if you meant any amount of
>>> whitespace or a single
>>> whitespace character. I use '+' to match one or more whitespace characters.)
>>>
>>> Bill Dunlap
>>> TIBCO Software
>>> wdunlap tibco.com
>>>
>>>
>>> On Thu, Jun 26, 2014 at 10:12 PM, David Winsemius
>>>  wrote:

 On Jun 26, 2014, at 6:11 PM, C Lin wrote:

> Hi Duncan,
>
> Thanks for trying to help. Sorry for not being clear.
> The string I'd like to get is 'AARSD1'
> It can be followed or preceded by white space or // or nothing
>
> so, from test <- c('AARSD11','AARSD1-','AARSD1//','AARSD1 
> //','//AARSD1','AARSD1');
>
> I want to match only 'AARSD1//','AARSD1 //','//AARSD1','AARSD1'

 Perhaps you want jsut

 grepl('^AARSD1//$|^AARSD1 //$|^//AARSD1$|^AARSD1', test)

> grepl('^AARSD1//$|^AARSD1 //$|^//AARSD1$|^AARSD1$', test)
 [1] FALSE FALSE TRUE TRUE TRUE TRUE

 --
 David.

>

> Thanks,
> Lin
>
> 
>> From: dulca...@bigpond.com
>> To: bac...@hotmail.com; r-help@r-project.org
>> Subject: RE: [R] regular expression help
>> Date: Fri, 27 Jun 2014 10:59:29 +1000
>>
>> Hi
>>
>> You only have a vector of length 5 and I am not quite sure of the string 
>> you
>> are testing
>> so try this
>>
>> grep('[/]*\\[/]*',test)
>>
>> Duncan
>>
>> Duncan Mackay
>> Department of Agronomy and Soil Science
>> University of New England
>> Armidale NSW 2351
>> Email: home: mac...@northnet.com.au
>>
>> -Original Message-
>> From: r-help-boun...@r-project.org [mailto:r-help-boun...@r-project.org] 
>> On
>> Behalf Of C Lin
>> Sent: Friday, 27 June 2014 10:05
>> To: r-help@r-project.org
>> Subject: [R] regular expression help
>>
>> Dear R users,
>>
>> I need to match a string. It can be followed or preceded by whitespace 
>> or //
>> or nothing.
>> How do I code it in R?
>>
>> For example:
>> test <- c('AARSD11','AARSD1-','AARSD1//','AARSD1 //','//AARSD1');
>> grep('AARSD1(\\s*//*)',test);
>>
>> should return 3,4,5 and 6.
>>
>


 David Winsemius
 Alameda, CA, USA

 __
 R-help@r-project.org mailing list
 https://stat.ethz.ch/mailman/listinfo/r-help
 PLEASE do read the posting guide 
 http://www.R-project.org/posting-guide.html
 and provide commented, minimal, self-contained, reproducible code.
>>
  
__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/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] Population growthrate with Euler-Lotka

2014-06-30 Thread Mark Christjani

   Thank you Simon and David for your suggestions. They were most helpful. The
   Skript is now working as it was originally planed.

   Greetings
   Mark

   Gesendet: Montag, 30. Juni 2014 um 13:06 Uhr
   Von: "Simon Blomberg" 
   An: "Mark Christjani" 
   Cc: "r-help@r-project.org" 
   Betreff: Re: Aw: Re: [R] Population growthrate with Euler-Lotka
   Hmm. Try setting extendInt="yes" in the call to uniroot. You should also
   look at the help page for uniroot. help(uniroot) May give you a clue. It's
   difficult for me to debug code on my iphone. Well, more difficult than
   usual.

   Best,

   Simon.
   Sent from my iPhone
   On 30 Jun 2014, at 8:53 pm, "Mark Christjani" <[1]m_christj...@gmx.de>
   wrote:

   Thank you, Simon, for your input.

   Data import works fine now, but the final equation still won`t work.

   Console reads now:

   > setwd("c:/Mark")
   >
   > table <- read.table("r-TCO-Scene-Kontrolle.csv", header=TRUE, sep=";")
   >
   > table
   x  lx  mx
   1   1 1.0 0.0
   2   2 1.0 0.0
   3   3 1.0 0.0
   4   4 1.0 0.0
   5   5 1.0 0.0
   6   6 1.0 0.0
   7   7 1.0 0.0
   8   8 1.0 0.0
   9   9 1.0 0.0
   10 10 1.0 0.0
   11 11 0.2 3.5
   >
   > x <- c(table$x)
   > L <- c(table$lx)
   > m <- c(table$mx)
   > r.range<- c(0, 5)
   >
   > eulerlotka <- function(r) sum(L * m * exp(-r * x)) - 1
   > res <- uniroot(f = eulerlotka, interval = r.range, tol = 1e-8)
   Error in uniroot(f = eulerlotka, interval = r.range, tol = 1e-08) :
 f() values at end points not of opposite sign
   >
   > res$root
   Error: object 'res' not found

   Any idea on this "Error in uniroot(f = eulerlotka, interval = r.range, tol =
   1e-08) :
 f() values at end points not of opposite sign"-matter?

   Kind regards,
   Mark



   Gesendet: Montag, 30. Juni 2014 um 12:41 Uhr
   Von: "Simon Blomberg" <[2]s.blombe...@uq.edu.au>
   An: "Mark Christjani" <[3]m_christj...@gmx.de>
   Cc: "[4]r-help@r-project.org" <[5]r-help@r-project.org>
   Betreff: Re: [R] Population growthrate with Euler-Lotka
   Your script is failing at the first hurdle because you data are not being
   imported properly. You should include
   header=TRUE. sep=";"
   In the call to read.table.
   Cheers.
   Simon.
   Sent from my iPhone
   Sent from my iPhone
   > On 30 Jun 2014, at 7:10 pm, "Mark Christjani" <[6]m_christj...@gmx.de>
   wrote:
   >
   >
   > Hi everybody,
   >
   >  I`m  Mark  and I do my PhD in biology. I try using R to calculate a
   population
   > growth rate of animals grown on different types of food. Our workgroup has
   a
   > R-skript to do so, but sadly nobody, who knows how this works. I`ve never
   > used R before, but got some stuff figured out myself. The skript goes:
   >
   > setwd("c:/Mark")
   > table <- read.table("r-TCO-Scene-Kontrolle.csv")
   > table
   > x <- c(table$x)
   > L <- c(table$lx)
   > m <- c(table$mx)
   > r.range<- c(0, 5)
   > eulerlotka <- function(r) sum(L * m * exp(-r * x)) - 1
   > res <- uniroot(f = eulerlotka, interval = r.range, tol = 1e-8)
   > res$root
   >
   > I understood that the first 3 lines are simply to load my data and show it
   > in the workspace console. The next 4 lines define variables of my .csv
   table
   >  for  R.  Thus far, everything works fine. Now comes the Euler-Lotka
   equation,
   > but somehow, this does not seem to work out as supposed. I tried to find a
   > solution on the internet, but I think this formula is somewhat special so
   I
   > could not find a suitible solution for my special problem. The console
   says:
   >
   >
   >> setwd("c:/Mark")
   >>
   >> table <- read.table("r-TCO-Scene-Kontrolle.csv")
   >>
   >> table
   > V1
   > 1 x;lx;mx
   > 2 1;1;0
   > 3 2;1;0
   > 4 3;1;0
   > 5 4;1;0
   > 6 5;1;0
   > 7 6;1;0
   > 8 7;1;0
   > 9 8;1;0
   > 10 9;1;0
   > 11 10;1;0
   > 12 11;0.2;3.5
   >>
   >> x <- c(table$x)
   >> L <- c(table$lx)
   >> m <- c(table$mx)
   >> r.range<- c(0, 5)
   >>
   >> eulerlotka <- function(r) sum(L * m * exp(-r * x)) - 1
   >> res <- uniroot(f = eulerlotka, interval = r.range, tol = 1e-8)
   > Error in uniroot(f = eulerlotka, interval = r.range, tol = 1e-08) :
   > f() values at end points not of opposite sign
   >>
   >> res$root
   >
   > Does anybody have an idea how to get this running?
   >
   > Thanks in advance
   >
   > Kind regards
   > Mark
   > __
   > [7]R-help@r-project.org mailing list
   > [8]https://stat.ethz.ch/mailman/listinfo/r-help
   > PLEASE do read the posting guide
   [9]http://www.R-project.org/posting-guide.html
   > and provide commented, minimal, self-contained, reproducible code.

References

   1. file://localhost/tmp/m_christj...@gmx.de
   2. file://localhost/tmp/s.blombe...@uq.edu.au
   3. file://localhost/tmp/m_christj...@gmx.de
   4. file://localhost/tmp/r-help@r-project.org
   5. file://localhost/tmp/r-help@r-project.org
   6. file://localhost/tmp/m_christj...@gmx.de
   7. file://localhost/tmp/R-help@r-project.org
   8. https:/

[R] yet another regular expression

2014-06-30 Thread Jim Lemon
Hi all,
I have managed, with the help of glob2rx() to get two parts of a text 
manipulation working. I have successfully gotten rid of the first and 
second bits, but I have hit the wall trying to get rid of the last bit. Here's 
an example:

initString<-
 "\"Delete this\":value1,\"Delete this too\":value2},Delete last bit"
sub("\"Delete this too\":","",
 sub(glob2rx("*this\":*"),"",initString),fixed=TRUE)

This gives me:

[1] "value1,value2},Delete last bit"

and glob2rx("},*") just won't get rid of the last bit. I throw myself upon 
the mercy of the regular expression gurus.

Jim

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/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] standard error of survfit.coxph()

2014-06-30 Thread Therneau, Terry M., Ph.D.
1. The computations "behind the scenes" produce the variance of the cumulative hazard. 
This is true for both an ordinary Kaplan-Meier and a Cox model.  Transformations to other 
scales are done using simple Taylor series.


  H = cumulative hazard = log(S);  S=survival
  var(H) = var(log(S))  = the starting point
  S = exp(log(S)), so  var(S) is approx [deriv of exp(x)]^2 * var(log(S)) = S^2 
var(H)
  var(log(log(S)) is approx (1/S^2) var(H)

2. At the time it was written, summary.survfit was used only for printing out the survival 
curve at selected times, and the audience for the printout wanted std(S).   True, that was 
20 years ago, but I don't recall anyone ever asking for summary to do anything else.  Your 
request is not a bad idea.
  Note however that the primary impact of using log(S) or S or log(log(S)) scale is is on 
the confidence intervals, and they do appear per request in the summary output.


Terry T.


On 06/28/2014 05:00 AM, r-help-requ...@r-project.org wrote:

Message: 9
Date: Fri, 27 Jun 2014 12:39:29 -0700
From: array chip
To:"r-help@r-project.org"  
Subject: [R] standard error of survfit.coxph()
Message-ID:
<1403897969.91269.yahoomail...@web122906.mail.ne1.yahoo.com>
Content-Type: text/plain

Hi, can anyone help me to understand the standard errors printed in the output 
of survfit.coxph()?

time<-sample(1:15,100,replace=T)

status<-as.numeric(runif(100,0,1)<0.2)
x<-rnorm(100,10,2)

fit<-coxph(Surv(time,status)~x)
??? ### method 1

survfit(fit, newdata=data.frame(time=time,status=status,x=x)[1:5,], 
conf.type='log')$std.err

 [,1]??? [,2]??? [,3]??? [,4]?? [,5]
?[1,] 0.0 0.0 0.0 0.0 0.
?[2,] 0.008627644 0.008567253 0.008773699 0.009354788 0.01481819
?[3,] 0.008627644 0.008567253 0.008773699 0.009354788 0.01481819
?[4,] 0.013800603 0.013767977 0.013889971 0.014379928 0.02353371
?[5,] 0.013800603 0.013767977 0.013889971 0.014379928 0.02353371
?[6,] 0.013800603 0.013767977 0.013889971 0.014379928 0.02353371
?[7,] 0.030226811 0.030423883 0.029806263 0.028918817 0.05191161
?[8,] 0.030226811 0.030423883 0.029806263 0.028918817 0.05191161
?[9,] 0.036852571 0.037159980 0.036186931 0.034645002 0.06485394
[10,] 0.044181716 0.044621159 0.043221145 0.040872939 0.07931028
[11,] 0.044181716 0.044621159 0.043221145 0.040872939 0.07931028
[12,] 0.055452631 0.056018832 0.054236881 0.051586391 0.10800413
[13,] 0.070665160 0.071363749 0.069208056 0.066655730 0.14976433
[14,] 0.124140400 0.125564637 0.121281571 0.118002021 0.30971860
[15,] 0.173132357 0.175309455 0.168821266 0.164860523 0.46393111

survfit(fit, newdata=data.frame(time=time,status=status,x=x)[1:5,], 
conf.type='log')$time
?[1]? 1? 2? 3? 4? 5? 6? 7? 8? 9 10 11 12 13 14 15

??? ### method 2

summary(survfit(fit, newdata=data.frame(time=time,status=status,x=x)[1:5,], 
conf.type='log'),time=10)$std.err

? 1? 2? 3? 4? 5
[1,] 0.04061384 0.04106186 0.03963184 0.03715246 0.06867532

By reading the help of ?survfit.object and ?summary.survfit, the standard error provided 
in the output of method 1 (survfit()) was for cumulative hazard-log(survival), while the 
standard error provided in the output of method 2 (summary.survfit()) was for survival 
itself, regardless of how you choose the value for "conf.type" ('log', 
'log-log' or 'plain'). This explains why the standard error output is different between 
method 1 (10th row) and method 2.

My question is how do I get standard error estimates for log(-log(survival))?

Thanks!

John


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

2014-06-30 Thread Mark Christjani

   Thank you, Simon, for your input.

   Data import works fine now, but the final equation still won`t work.

   Console reads now:

   > setwd("c:/Mark")
   >
   > table <- read.table("r-TCO-Scene-Kontrolle.csv", header=TRUE, sep=";")
   >
   > table
   x  lx  mx
   1   1 1.0 0.0
   2   2 1.0 0.0
   3   3 1.0 0.0
   4   4 1.0 0.0
   5   5 1.0 0.0
   6   6 1.0 0.0
   7   7 1.0 0.0
   8   8 1.0 0.0
   9   9 1.0 0.0
   10 10 1.0 0.0
   11 11 0.2 3.5
   >
   > x <- c(table$x)
   > L <- c(table$lx)
   > m <- c(table$mx)
   > r.range<- c(0, 5)
   >
   > eulerlotka <- function(r) sum(L * m * exp(-r * x)) - 1
   > res <- uniroot(f = eulerlotka, interval = r.range, tol = 1e-8)
   Error in uniroot(f = eulerlotka, interval = r.range, tol = 1e-08) :
 f() values at end points not of opposite sign
   >
   > res$root
   Error: object 'res' not found

   Any idea on this "Error in uniroot(f = eulerlotka, interval = r.range, tol =
   1e-08) :
 f() values at end points not of opposite sign"-matter?

   Kind regards,
   Mark



   Gesendet: Montag, 30. Juni 2014 um 12:41 Uhr
   Von: "Simon Blomberg" 
   An: "Mark Christjani" 
   Cc: "r-help@r-project.org" 
   Betreff: Re: [R] Population growthrate with Euler-Lotka
   Your script is failing at the first hurdle because you data are not being
   imported properly. You should include
   header=TRUE. sep=";"
   In the call to read.table.
   Cheers.
   Simon.
   Sent from my iPhone
   Sent from my iPhone
   > On 30 Jun 2014, at 7:10 pm, "Mark Christjani"  wrote:
   >
   >
   > Hi everybody,
   >
   >  I`m  Mark  and I do my PhD in biology. I try using R to calculate a
   population
   > growth rate of animals grown on different types of food. Our workgroup has
   a
   > R-skript to do so, but sadly nobody, who knows how this works. I`ve never
   > used R before, but got some stuff figured out myself. The skript goes:
   >
   > setwd("c:/Mark")
   > table <- read.table("r-TCO-Scene-Kontrolle.csv")
   > table
   > x <- c(table$x)
   > L <- c(table$lx)
   > m <- c(table$mx)
   > r.range<- c(0, 5)
   > eulerlotka <- function(r) sum(L * m * exp(-r * x)) - 1
   > res <- uniroot(f = eulerlotka, interval = r.range, tol = 1e-8)
   > res$root
   >
   > I understood that the first 3 lines are simply to load my data and show it
   > in the workspace console. The next 4 lines define variables of my .csv
   table
   >  for  R.  Thus far, everything works fine. Now comes the Euler-Lotka
   equation,
   > but somehow, this does not seem to work out as supposed. I tried to find a
   > solution on the internet, but I think this formula is somewhat special so
   I
   > could not find a suitible solution for my special problem. The console
   says:
   >
   >
   >> setwd("c:/Mark")
   >>
   >> table <- read.table("r-TCO-Scene-Kontrolle.csv")
   >>
   >> table
   > V1
   > 1 x;lx;mx
   > 2 1;1;0
   > 3 2;1;0
   > 4 3;1;0
   > 5 4;1;0
   > 6 5;1;0
   > 7 6;1;0
   > 8 7;1;0
   > 9 8;1;0
   > 10 9;1;0
   > 11 10;1;0
   > 12 11;0.2;3.5
   >>
   >> x <- c(table$x)
   >> L <- c(table$lx)
   >> m <- c(table$mx)
   >> r.range<- c(0, 5)
   >>
   >> eulerlotka <- function(r) sum(L * m * exp(-r * x)) - 1
   >> res <- uniroot(f = eulerlotka, interval = r.range, tol = 1e-8)
   > Error in uniroot(f = eulerlotka, interval = r.range, tol = 1e-08) :
   > f() values at end points not of opposite sign
   >>
   >> res$root
   >
   > Does anybody have an idea how to get this running?
   >
   > Thanks in advance
   >
   > Kind regards
   > Mark
   > __
   > R-help@r-project.org mailing list
   > [1]https://stat.ethz.ch/mailman/listinfo/r-help
   > PLEASE do read the posting guide
   [2]http://www.R-project.org/posting-guide.html
   > and provide commented, minimal, self-contained, reproducible code.

References

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


Re: [R] Population growthrate with Euler-Lotka

2014-06-30 Thread Simon Blomberg
There may be something wrong with your data: in all but one case you have lx=1 
and mx=0. Uniroot may be having difficulty because of this.

Simon.

Sent from my iPhone

> On 30 Jun 2014, at 9:09 pm, "Simon Blomberg"  wrote:
> 
> Hmm. Try setting extendInt="yes" in the call to uniroot. You should also look 
> at the help page for uniroot. help(uniroot) May give you a clue. It's 
> difficult for me to debug code on my iphone. Well, more difficult than usual.
> 
> Best,
> 
> Simon.
> 
> Sent from my iPhone
> 
> On 30 Jun 2014, at 8:53 pm, "Mark Christjani" 
> mailto:m_christj...@gmx.de>> wrote:
> 
> Thank you, Simon, for your input.
> 
> Data import works fine now, but the final equation still won`t work.
> 
> Console reads now:
> 
>> setwd("c:/Mark")
>> 
>> table <- read.table("r-TCO-Scene-Kontrolle.csv", header=TRUE, sep=";")
>> 
>> table
>x  lx  mx
> 1   1 1.0 0.0
> 2   2 1.0 0.0
> 3   3 1.0 0.0
> 4   4 1.0 0.0
> 5   5 1.0 0.0
> 6   6 1.0 0.0
> 7   7 1.0 0.0
> 8   8 1.0 0.0
> 9   9 1.0 0.0
> 10 10 1.0 0.0
> 11 11 0.2 3.5
>> 
>> x <- c(table$x)
>> L <- c(table$lx)
>> m <- c(table$mx)
>> r.range<- c(0, 5)
>> 
>> eulerlotka <- function(r) sum(L * m * exp(-r * x)) - 1
>> res <- uniroot(f = eulerlotka, interval = r.range, tol = 1e-8)
> Error in uniroot(f = eulerlotka, interval = r.range, tol = 1e-08) :
>  f() values at end points not of opposite sign
>> 
>> res$root
> Error: object 'res' not found
> 
> Any idea on this "Error in uniroot(f = eulerlotka, interval = r.range, tol = 
> 1e-08) :
>  f() values at end points not of opposite sign"-matter?
> 
> Kind regards,
> Mark
> 
> 
> 
> Gesendet: Montag, 30. Juni 2014 um 12:41 Uhr
> Von: "Simon Blomberg" mailto:s.blombe...@uq.edu.au>>
> An: "Mark Christjani" mailto:m_christj...@gmx.de>>
> Cc: "r-help@r-project.org" 
> mailto:r-help@r-project.org>>
> Betreff: Re: [R] Population growthrate with Euler-Lotka
> Your script is failing at the first hurdle because you data are not being 
> imported properly. You should include
> 
> header=TRUE. sep=";"
> 
> In the call to read.table.
> 
> Cheers.
> 
> Simon.
> 
> Sent from my iPhone
> 
> Sent from my iPhone
>> On 30 Jun 2014, at 7:10 pm, "Mark Christjani" 
>> mailto:m_christj...@gmx.de>> wrote:
>> 
>> 
>> Hi everybody,
>> 
>> I`m Mark and I do my PhD in biology. I try using R to calculate a population
>> growth rate of animals grown on different types of food. Our workgroup has a
>> R-skript to do so, but sadly nobody, who knows how this works. I`ve never
>> used R before, but got some stuff figured out myself. The skript goes:
>> 
>> setwd("c:/Mark")
>> table <- read.table("r-TCO-Scene-Kontrolle.csv")
>> table
>> x <- c(table$x)
>> L <- c(table$lx)
>> m <- c(table$mx)
>> r.range<- c(0, 5)
>> eulerlotka <- function(r) sum(L * m * exp(-r * x)) - 1
>> res <- uniroot(f = eulerlotka, interval = r.range, tol = 1e-8)
>> res$root
>> 
>> I understood that the first 3 lines are simply to load my data and show it
>> in the workspace console. The next 4 lines define variables of my .csv table
>> for R. Thus far, everything works fine. Now comes the Euler-Lotka equation,
>> but somehow, this does not seem to work out as supposed. I tried to find a
>> solution on the internet, but I think this formula is somewhat special so I
>> could not find a suitible solution for my special problem. The console says:
>> 
>> 
>>> setwd("c:/Mark")
>>> 
>>> table <- read.table("r-TCO-Scene-Kontrolle.csv")
>>> 
>>> table
>> V1
>> 1 x;lx;mx
>> 2 1;1;0
>> 3 2;1;0
>> 4 3;1;0
>> 5 4;1;0
>> 6 5;1;0
>> 7 6;1;0
>> 8 7;1;0
>> 9 8;1;0
>> 10 9;1;0
>> 11 10;1;0
>> 12 11;0.2;3.5
>>> 
>>> x <- c(table$x)
>>> L <- c(table$lx)
>>> m <- c(table$mx)
>>> r.range<- c(0, 5)
>>> 
>>> eulerlotka <- function(r) sum(L * m * exp(-r * x)) - 1
>>> res <- uniroot(f = eulerlotka, interval = r.range, tol = 1e-8)
>> Error in uniroot(f = eulerlotka, interval = r.range, tol = 1e-08) :
>> f() values at end points not of opposite sign
>>> 
>>> res$root
>> 
>> Does anybody have an idea how to get this running?
>> 
>> Thanks in advance
>> 
>> Kind regards
>> Mark
>> __
>> R-help@r-project.org mailing list
>> https://stat.ethz.ch/mailman/listinfo/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-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible co

Re: [R] Population growthrate with Euler-Lotka

2014-06-30 Thread David Stevens

Mark - good on you for jumping into R with both feet.

In addition to Simon's advice, the error message you are getting means 
that the two endpoints (r.range in your case) do not give function 
values that are of the opposite sign and so either the function has no 
roots on the interval or has and even number of roots on the interval 
(2,4,6,...). Neither situation is good for your case because uniroot 
finds the single root (where the y-value = 0) on the interval. Once the 
reading issues are settled, try narrowing or expanding the r.range. A 
good way to find a proper r.range is to plot the function vs. r and 
locate the range of r where the function crosses zero. Then use the 
region of r around that point as your r.range. You also learn a lot 
about that function by studying that plot.


Regards

David

On 6/30/2014 1:39 AM, Mark Christjani wrote:

Hi everybody,

I`m Mark and I do my PhD in biology. I try using R to calculate a population
growth rate of animals grown on different types of food. Our workgroup has a
R-skript to do so, but sadly nobody, who knows how this works. I`ve never
used R before, but got some stuff figured out myself. The skript goes:

setwd("c:/Mark")
table <- read.table("r-TCO-Scene-Kontrolle.csv")
table
x <- c(table$x)
L <- c(table$lx)
m <- c(table$mx)
r.range<- c(0, 5)
eulerlotka <- function(r) sum(L * m * exp(-r * x)) - 1
res <- uniroot(f = eulerlotka, interval = r.range, tol = 1e-8)
res$root

I understood that the first 3 lines are simply to load my data and show it
in the workspace console. The next 4 lines define variables of my .csv table
for R. Thus far, everything works fine. Now comes the Euler-Lotka equation,
but somehow, this does not seem to work out as supposed. I tried to find a
solution on the internet, but I think this formula is somewhat special so I
could not find a suitible solution for my special problem. The console says:


> setwd("c:/Mark")
>
> table <- read.table("r-TCO-Scene-Kontrolle.csv")
>
> table
   V1
1 x;lx;mx
2   1;1;0
3   2;1;0
4   3;1;0
5   4;1;0
6   5;1;0
7   6;1;0
8   7;1;0
9   8;1;0
10  9;1;0
11 10;1;0
12 11;0.2;3.5
>
> x <- c(table$x)
> L <- c(table$lx)
> m <- c(table$mx)
> r.range<- c(0, 5)
>
> eulerlotka <- function(r) sum(L * m * exp(-r * x)) - 1
> res <- uniroot(f = eulerlotka, interval = r.range, tol = 1e-8)
Error in uniroot(f = eulerlotka, interval = r.range, tol = 1e-08) :
  f() values at end points not of opposite sign
>
> res$root

Does anybody have an idea how to get this running?

Thanks in advance

Kind regards
Mark
__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/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 K Stevens, P.E., Ph.D.
Professor and Head, Environmental Engineering
Civil and Environmental Engineering
Utah Water Research Laboratory
8200 Old Main Hill
Logan, UT  84322-8200
435 797 3229 - voice
435 797 1363 - fax
david.stev...@usu.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.


Re: [R] Population growthrate with Euler-Lotka

2014-06-30 Thread Simon Blomberg
Hmm. Try setting extendInt="yes" in the call to uniroot. You should also look 
at the help page for uniroot. help(uniroot) May give you a clue. It's difficult 
for me to debug code on my iphone. Well, more difficult than usual.

Best,

Simon.

Sent from my iPhone

On 30 Jun 2014, at 8:53 pm, "Mark Christjani" 
mailto:m_christj...@gmx.de>> wrote:

Thank you, Simon, for your input.

Data import works fine now, but the final equation still won`t work.

Console reads now:

> setwd("c:/Mark")
>
> table <- read.table("r-TCO-Scene-Kontrolle.csv", header=TRUE, sep=";")
>
> table
x  lx  mx
1   1 1.0 0.0
2   2 1.0 0.0
3   3 1.0 0.0
4   4 1.0 0.0
5   5 1.0 0.0
6   6 1.0 0.0
7   7 1.0 0.0
8   8 1.0 0.0
9   9 1.0 0.0
10 10 1.0 0.0
11 11 0.2 3.5
>
> x <- c(table$x)
> L <- c(table$lx)
> m <- c(table$mx)
> r.range<- c(0, 5)
>
> eulerlotka <- function(r) sum(L * m * exp(-r * x)) - 1
> res <- uniroot(f = eulerlotka, interval = r.range, tol = 1e-8)
Error in uniroot(f = eulerlotka, interval = r.range, tol = 1e-08) :
  f() values at end points not of opposite sign
>
> res$root
Error: object 'res' not found

Any idea on this "Error in uniroot(f = eulerlotka, interval = r.range, tol = 
1e-08) :
  f() values at end points not of opposite sign"-matter?

Kind regards,
Mark



Gesendet: Montag, 30. Juni 2014 um 12:41 Uhr
Von: "Simon Blomberg" mailto:s.blombe...@uq.edu.au>>
An: "Mark Christjani" mailto:m_christj...@gmx.de>>
Cc: "r-help@r-project.org" 
mailto:r-help@r-project.org>>
Betreff: Re: [R] Population growthrate with Euler-Lotka
Your script is failing at the first hurdle because you data are not being 
imported properly. You should include

header=TRUE. sep=";"

In the call to read.table.

Cheers.

Simon.

Sent from my iPhone

Sent from my iPhone
> On 30 Jun 2014, at 7:10 pm, "Mark Christjani" 
> mailto:m_christj...@gmx.de>> wrote:
>
>
> Hi everybody,
>
> I`m Mark and I do my PhD in biology. I try using R to calculate a population
> growth rate of animals grown on different types of food. Our workgroup has a
> R-skript to do so, but sadly nobody, who knows how this works. I`ve never
> used R before, but got some stuff figured out myself. The skript goes:
>
> setwd("c:/Mark")
> table <- read.table("r-TCO-Scene-Kontrolle.csv")
> table
> x <- c(table$x)
> L <- c(table$lx)
> m <- c(table$mx)
> r.range<- c(0, 5)
> eulerlotka <- function(r) sum(L * m * exp(-r * x)) - 1
> res <- uniroot(f = eulerlotka, interval = r.range, tol = 1e-8)
> res$root
>
> I understood that the first 3 lines are simply to load my data and show it
> in the workspace console. The next 4 lines define variables of my .csv table
> for R. Thus far, everything works fine. Now comes the Euler-Lotka equation,
> but somehow, this does not seem to work out as supposed. I tried to find a
> solution on the internet, but I think this formula is somewhat special so I
> could not find a suitible solution for my special problem. The console says:
>
>
>> setwd("c:/Mark")
>>
>> table <- read.table("r-TCO-Scene-Kontrolle.csv")
>>
>> table
> V1
> 1 x;lx;mx
> 2 1;1;0
> 3 2;1;0
> 4 3;1;0
> 5 4;1;0
> 6 5;1;0
> 7 6;1;0
> 8 7;1;0
> 9 8;1;0
> 10 9;1;0
> 11 10;1;0
> 12 11;0.2;3.5
>>
>> x <- c(table$x)
>> L <- c(table$lx)
>> m <- c(table$mx)
>> r.range<- c(0, 5)
>>
>> eulerlotka <- function(r) sum(L * m * exp(-r * x)) - 1
>> res <- uniroot(f = eulerlotka, interval = r.range, tol = 1e-8)
> Error in uniroot(f = eulerlotka, interval = r.range, tol = 1e-08) :
> f() values at end points not of opposite sign
>>
>> res$root
>
> Does anybody have an idea how to get this running?
>
> Thanks in advance
>
> Kind regards
> Mark
> __
> R-help@r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/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] x,y scatterplots, with averaging by a column

2014-06-30 Thread Jim Lemon
On Mon, 30 Jun 2014 10:42:28 AM Tim Richter-Heitmann wrote:
> Hallo!
> 
> I have this matrix:
> 
> SampleID, Day, Species1, Species2,Species3,...,Speciesn
> 1,Monday,abundance values
> 2,Monday,abundance values
> 11,Tuesday,abundance values
> 12,Tuesday,abundance values
> 21,Wednesday,abundance values
> 22,Wednesday,abundance values
> 
> I would like to plot the Days on the x-axis, and the species 
abundance
> data on the y-axis. Each pair of values (i just have two 
measurements
> for each day) should be represented by their mean with absolute 
error
> bars (so we have basically a vertical min,max-range) and whiskers. 
The
> means for each Species observation should be connected with lines.
> Also of interest would be annotating the whispers with their sample 
ID
> (because the whiskers basically represent the values for y1,2 
(11,12;
> 21,22)).

Hi Tim,
I think this might get you started:

trhdf<-data.frame(SampleID=seq(0,50,by=10)+(1:2),
 Day=factor(rep( c("Monday","Tuesday","Wednesday",
  "Thursday","Friday","Saturday"),
 each=2),levels=c("Monday","Tuesday","Wednesday",
  "Thursday","Friday","Saturday")),
 Species1=sample(0:20,12),Species2=sample(0:20,12),
 Species3=sample(0:20,12),Species4=sample(0:20,12),
 Species5=sample(0:20,12))

rollfunc<-function(x,FUN="mean",roll=2) {
 lenx<-length(x)
 xmeans<-rep(NA,lenx/2)
 start<-1
 for(xm in 1:(lenx/2)) {
  xmeans[xm]<-do.call(FUN,list(x[start:(start+roll-1)]))
  start<-start+roll
 }
 return(xmeans)
}

xpos<-rep(1:6,5)+seq(-0.4,0.4,by=0.2)
ypos<-as.vector(sapply(trhdf[,3:7],rollfunc))
ymin<-as.vector(sapply(trhdf[,3:7],rollfunc,"min"))
ymax<-as.vector(sapply(trhdf[,3:7],rollfunc,"max"))

library(plotrix)

plot(xpos,ypos,pch=c("1","2","3","4","5"),ylim=c(0,20),
 xaxt="n",xlab="Day",ylab="Abundance")
dispersion(xpos,ypos,ymax,ymin,interval=FALSE)
staxlab(1,at=1:6,
 labels=c("Monday","Tuesday","Wednesday",
  "Thursday","Friday","Saturday"))

Jim

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/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] solving pde with given boundary condition (heat equation)

2014-06-30 Thread Zé Miguel
Dear R-helpers,

I have 3 thermometers measuring soil temperature at 3 levels every 10
minutes. I want to determine the soil diffusivity, by solving the heat
equation. The heat equation is a partial differential equation. In my case,
the initial values are know and the boundary conditions are given by 2 time
series: Tz1 and Tz3. These are measured temperatures at 2 levels.

I tried deSolve and bvpSolve, but apparently they do not provide a
numerical solution for this kind of boundary conditions (dirichlet boundary
condition?).

Help would be appreciated, since my calculus was selectively forgotten some
10 years ago


All the best,
J

-- 
José Miguel Delgado
Lisboa
Portugal

[[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] Population growthrate with Euler-Lotka

2014-06-30 Thread Simon Blomberg
Your script is failing at the first hurdle because you data are not being 
imported properly. You should include

header=TRUE. sep=";"

In the call to read.table.

Cheers.

Simon.

Sent from my iPhone

Sent from my iPhone
> On 30 Jun 2014, at 7:10 pm, "Mark Christjani"  wrote:
> 
> 
>   Hi everybody,
> 
>   I`m Mark and I do my PhD in biology. I try using R to calculate a population
>   growth rate of animals grown on different types of food. Our workgroup has a
>   R-skript to do so, but sadly nobody, who knows how this works. I`ve never
>   used R before, but got some stuff figured out myself. The skript goes:
> 
>   setwd("c:/Mark")
>   table <- read.table("r-TCO-Scene-Kontrolle.csv")
>   table
>   x <- c(table$x)
>   L <- c(table$lx)
>   m <- c(table$mx)
>   r.range<- c(0, 5)
>   eulerlotka <- function(r) sum(L * m * exp(-r * x)) - 1
>   res <- uniroot(f = eulerlotka, interval = r.range, tol = 1e-8)
>   res$root
> 
>   I understood that the first 3 lines are simply to load my data and show it
>   in the workspace console. The next 4 lines define variables of my .csv table
>   for R. Thus far, everything works fine. Now comes the Euler-Lotka equation,
>   but somehow, this does not seem to work out as supposed. I tried to find a
>   solution on the internet, but I think this formula is somewhat special so I
>   could not find a suitible solution for my special problem. The console says:
> 
> 
>> setwd("c:/Mark")
>> 
>> table <- read.table("r-TCO-Scene-Kontrolle.csv")
>> 
>> table
>  V1
>   1 x;lx;mx
>   2   1;1;0
>   3   2;1;0
>   4   3;1;0
>   5   4;1;0
>   6   5;1;0
>   7   6;1;0
>   8   7;1;0
>   9   8;1;0
>   10  9;1;0
>   11 10;1;0
>   12 11;0.2;3.5
>> 
>> x <- c(table$x)
>> L <- c(table$lx)
>> m <- c(table$mx)
>> r.range<- c(0, 5)
>> 
>> eulerlotka <- function(r) sum(L * m * exp(-r * x)) - 1
>> res <- uniroot(f = eulerlotka, interval = r.range, tol = 1e-8)
>   Error in uniroot(f = eulerlotka, interval = r.range, tol = 1e-08) :
> f() values at end points not of opposite sign
>> 
>> res$root
> 
>   Does anybody have an idea how to get this running?
> 
>   Thanks in advance
> 
>   Kind regards
>   Mark
> __
> R-help@r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/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] merge question

2014-06-30 Thread Dr Eberhard W Lisse
Rolf,

I hear you. 

But, after reflection, ie I looked at my situation again, it is great :-)-O

el


Sent from Dr Lisse's iPad mini

> On Jun 30, 2014, at 0:48, Rolf Turner  wrote:
> 
> 
>> On 30/06/14 10:32, Dr Eberhard W Lisse wrote:
>> 
>> Thanks,
>> 
>> I then set NA to 0, and can do the sutraction,
>> 
>> great.
> 
> Not so great.  I haven't gone through the issues underlying this post, but 
> replacing NA by 0 will almost surely yield nonsense.  "Missing" is ***not*** 
> the same thing as "zero".  Pretending that it is will have disastrous 
> consequences.  Think through what you are trying to do more clearly.
> 
> cheers,
> 
> Rolf Turner

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


[R] convergence warning in betamix()

2014-06-30 Thread ChrisR
Hi, I am running some rather complex mixtures of beta regressions using the
betamix() command from the betareg package (V. 3.0-4). If I am doing
exploratory regressions with only one random starting value (nstart=1) I
obtain results which converge after about 100 iterations. However, if I run
regressions with nstart=100 random starting values I obtain solutions
amended with a warning that no convergence resulted after 200 iterations. I
conclude that 1) the initial regression converges to a local optimum, 2) the
likelihood function is flat. However, at least in theory the EM algorithm
should converge to an optimum. Thus, I am wondering about the meaning of the
warning: does it mean "no convergence at all, i.e. after 5000 iterations of
the BFGS algorithm" or convergence but after more than 200 iterations?
Moreover, is there a way out the flat trap? I have started to experiment
with the SANN algorithm within the betamix() function but it is slow (as
expected)...
Thanks for any hints
Chris



--
View this message in context: 
http://r.789695.n4.nabble.com/convergence-warning-in-betamix-tp4693249.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] From long to wide format

2014-06-30 Thread arun


Hi Jorge,

You may try:
library(dplyr)
library(tidyr)

#Looks like this is faster than the other methods.
system.time({wide1 <- x2%>%
        select(-rate) %>% 
        mutate(variable=factor(variable, levels=unique(variable)),id=factor(id, 
levels=unique(id))) %>%  
    spread(variable,outcome)
colnames(wide1)[-1] <- paste("outcome",colnames(wide1)[-1],sep=".")
})

 #user  system elapsed 
 #  0.006    0.00    0.006



system.time(wide <- reshape(x2[, -4], v.names = "outcome", idvar = "id",
   timevar = "variable", direction = "wide"))
 #user  system elapsed 
 # 0.169   0.000   0.169



system.time({
sel <- unique(x2$variable)
id <- unique(x2$id)
X <- matrix(NA, ncol = length(sel) + 1, nrow = length(id))
X[, 1] <- id
colnames(X) <- c('id', sel)
r <- mclapply(seq_along(sel), function(i){
    out <- x2[x2$variable == sel[i], ][, 3]
    }, mc.cores = 4)
X[, -1] <- do.call(rbind, r)
X
})

# user  system elapsed 
#  0.125   0.011   0.074


 wide2 <- wide1
wide2$id <- as.character(wide2$id)
 wide$id <- as.character(wide$id)
all.equal(wide, wide2, check.attributes=F)
#[1] TRUE

A.K.



On Sunday, June 29, 2014 11:48 PM, Jorge I Velez  
wrote:
Dear R-help,

I am working with some data stored as "filename.txt.gz" in my working
directory.
After reading the data in using read.table(), I can see that each of them
has four columns (variable, id, outcome, and rate) and the following
structure:

# sample data
x2 <- data.frame(variable = rep(paste0('x', 1:100), each = 100), id =
rep(paste0('p', 1:100), 100), outcome = sample(0:2, 1, TRUE), rate =
runif(1, 0.5, 1))
str(x2)

Each variable, i.e., x1, x2,..., x100 is repeated as many times as the
number of unique IDs (100 in this example).  What I would like to do is to
transform the data above
in a long format.  I can do this by using

# reshape
wide <- reshape(x2[, -4], v.names = "outcome", idvar = "id",
                timevar = "variable", direction = "wide")
str(wide)

# or a "hack" with mclapply:

require(parallel)
sel <- as.character(unique(x2$variable))
id <- as.character(unique(x2$id))
X <- matrix(NA, ncol = length(sel) + 1, nrow = length(id))
X[, 1] <- id
colnames(X) <- c('id', sel)
r <- mclapply(seq_along(sel), function(i){
                        out <- x2[x2$variable == sel[i], ][, 3]
                        }, mc.cores = 4)
X[, -1] <- do.call(rbind, r)
X

However, I was wondering if it is possible to come up with another solution
, hopefully faster than these
.  Unfortunately, either one of these takes a very long time to process,
specially when the number of variables is very large
(> 250,000) and the number of ids is ~2000.

I would very much appreciate your suggestions.   At the end of this message
is my sessionInfo().

Thank you very much in advance.

Best regards,
Jorge Velez.-


R>  sessionInfo()

R version 3.0.2 Patched (2013-12-11 r64449)
Platform: x86_64-apple-darwin10.8.0 (64-bit)

locale:
[1] en_AU.UTF-8/en_AU.UTF-8/en_AU.UTF-8/C/en_AU.UTF-8/en_AU.UTF-8

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

other attached packages:
[1] knitr_1.6.3            ggplot2_1.0.0          slidifyLibraries_0.3.1
[4] slidify_0.3.52

loaded via a namespace (and not attached):
[1] colorspace_1.2-4 digest_0.6.4     evaluate_0.5.5   formatR_0.10
[5] grid_3.0.2       gtable_0.1.2     markdown_0.7.1   MASS_7.3-33
[9] munsell_0.4.2    plyr_1.8.1       proto_0.3-10     Rcpp_0.11.2
[13] reshape2_1.4     scales_0.2.4     stringr_0.6.2    tools_3.0.2
[17] whisker_0.4      yaml_2.1.13

    [[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] x,y scatterplots, with averaging by a column

2014-06-30 Thread Tim Richter-Heitmann

Hallo!

I have this matrix:

SampleID, Day, Species1, Species2,Species3,...,Speciesn
1,Monday,abundance values
2,Monday,abundance values
11,Tuesday,abundance values
12,Tuesday,abundance values
21,Wednesday,abundance values
22,Wednesday,abundance values

I would like to plot the Days on the x-axis, and the species abundance 
data on the y-axis. Each pair of values (i just have two measurements 
for each day) should be represented by their mean with absolute error 
bars (so we have basically a vertical min,max-range) and whiskers. The 
means for each Species observation should be connected with lines.
Also of interest would be annotating the whispers with their sample ID 
(because the whiskers basically represent the values for y1,2 (11,12; 
21,22)).

Any help is welcome! I am new to R, so please bear with me. Thank you!

--
Tim Richter-Heitmann (M.Sc.)
PhD Candidate



International Max-Planck Research School for Marine Microbiology
University of Bremen
Microbial Ecophysiology Group (AG Friedrich)
FB02 - Biologie/Chemie
Leobener Straße (NW2 A2130)
D-28359 Bremen
Tel.: 0049(0)421 218-63062
Fax: 0049(0)421 218-63069

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

2014-06-30 Thread Greg Minshall
hi.  "Writing R Extensions" provides a simple routine getListElement(),
said to be based on a similar routine in the package stats, for C code
to call to find a named element of a list .  however, it doesn't work
for the argument list passed to a .External(), as that is a PairList
rather than a List.

below is a simple reworking (with slightly different semantics) that
appears to work with PairLists.  the argument "cmd" is used in producing
an error() in the case where this the requested element is not found.
(the original getListElement() would return R_NilValue, but for *my* use
i found throwing the error easier at this lower level; possibly i should
have parameterized that behavior.)

here is an example of use:

static SEXP
rimageread(SEXP args) {
...
  file = CHAR(STRING_ELT(getPairListElement(args, "file", "rimageread"), 0));
  usemagick = LOGICAL(getPairListElement(args, "usemagickwand", 
"rimageread"))[0];
...
}


anyway, in the hope this may be of some use to someone.

cheers, Greg Minshall

/* get the list element named str, or report an error() */
static SEXP
getPairListElement(SEXP pairs, const char *str, const char *cmd) {
for (pairs = CDR(pairs); pairs != R_NilValue; pairs = CDR(pairs)) {
if (!isNull(TAG(pairs))) {
if (strcmp(CHAR(PRINTNAME(TAG(pairs))), str) == 0) {
return CAR(pairs);
}
}
}
error("%s: required parameter '%s' not specified", cmd, str);
/*NOTREACHED*/
}

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

2014-06-30 Thread Mark Christjani

   Hi everybody,

   I`m Mark and I do my PhD in biology. I try using R to calculate a population
   growth rate of animals grown on different types of food. Our workgroup has a
   R-skript to do so, but sadly nobody, who knows how this works. I`ve never
   used R before, but got some stuff figured out myself. The skript goes:

   setwd("c:/Mark")
   table <- read.table("r-TCO-Scene-Kontrolle.csv")
   table
   x <- c(table$x)
   L <- c(table$lx)
   m <- c(table$mx)
   r.range<- c(0, 5)
   eulerlotka <- function(r) sum(L * m * exp(-r * x)) - 1
   res <- uniroot(f = eulerlotka, interval = r.range, tol = 1e-8)
   res$root

   I understood that the first 3 lines are simply to load my data and show it
   in the workspace console. The next 4 lines define variables of my .csv table
   for R. Thus far, everything works fine. Now comes the Euler-Lotka equation,
   but somehow, this does not seem to work out as supposed. I tried to find a
   solution on the internet, but I think this formula is somewhat special so I
   could not find a suitible solution for my special problem. The console says:


   > setwd("c:/Mark")
   >
   > table <- read.table("r-TCO-Scene-Kontrolle.csv")
   >
   > table
  V1
   1 x;lx;mx
   2   1;1;0
   3   2;1;0
   4   3;1;0
   5   4;1;0
   6   5;1;0
   7   6;1;0
   8   7;1;0
   9   8;1;0
   10  9;1;0
   11 10;1;0
   12 11;0.2;3.5
   >
   > x <- c(table$x)
   > L <- c(table$lx)
   > m <- c(table$mx)
   > r.range<- c(0, 5)
   >
   > eulerlotka <- function(r) sum(L * m * exp(-r * x)) - 1
   > res <- uniroot(f = eulerlotka, interval = r.range, tol = 1e-8)
   Error in uniroot(f = eulerlotka, interval = r.range, tol = 1e-08) :
 f() values at end points not of opposite sign
   >
   > res$root

   Does anybody have an idea how to get this running?

   Thanks in advance

   Kind regards
   Mark
__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/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] perform a double poisson in R

2014-06-30 Thread Roberta Marino
Good morning,

for my data I've perform a Quasi-Poisson distribution and now I want to
perform a Double Poisson distribution



Could someone tell me if it is possible and how do it in R



I attach below my data



Tanks for help, best regards



Roberta Marino





> intdata<- read.table("dati-traffico-guide.dat")

> intdata

 V1 V2 V3 V4   V5

1 1  4  4  21.193913 3.053714

2 2  4  2   8.400438 2.128284

3 3  4  0  20.443000 3.017641

4 4  3  3  14.434567 2.669626

5 5  3  5  28.549402 3.351636

6 6  5  2   8.400438 2.128284

7 7  4  1   3.329605 1.202854

8 8  3  4  21.193913 3.053714

9 9  4  3  14.434567 2.669626

10   10  5  1   3.329605 1.202854

11   11  4  3  14.434567 2.669626

12   12  5  1   3.329605 1.202854

13   13  4  1   3.329605 1.202854

14   14  3  3  14.434567 2.669626

15   15  3  2   8.400438 2.128284

16   16  4  4  21.193913 3.053714

17   17  5  5  28.549402 3.351636

18   18  5  1   3.329605 1.202854

19   19  4  2   8.400438 2.128284

20   20  3  6  36.417738 3.595056

21   21  5  3  14.434567 2.669626

22   22  4  4  21.193913 3.053714

23   23  4  3  14.434567 2.669626

24   24  4  6  36.417738 3.595056

25   25  4  5  28.549402 3.351636

26   26  5  1   3.329605 1.202854

27   27  4  0  15.678000 2.752258

28   28  4  3  14.434567 2.669626

29   29  4  2   8.400438 2.128284

30   30  4  1   3.329605 1.202854

31   31  4  7  44.739851 3.800865

32   32  4  6  36.417738 3.595056

33   33  5  5  28.549402 3.351636

34   34  5  3  14.434567 2.669626

35   35  4  3  14.434567 2.669626

36   36  4  2   8.400438 2.128284

37   37  5  4  21.193913 3.053714

38   38  5  4  21.193913 3.053714

39   39  4  5  28.549402 3.351636

40   40  4  3  14.434567 2.669626

41   41  4  2   8.400438 2.128284

42   42  4  6  36.417738 3.595056

43   43  5  2   8.400438 2.128284

44   44  3  2   8.400438 2.128284

45   45  3  2   8.400438 2.128284

46   46  4  1   3.329605 1.202854

47   47  3  3  14.434567 2.669626

48   48  6  0  40.723000 3.706793

49   49  5  7  44.739851 3.800865

50   50  5  3  14.434567 2.669626

51   51  4  3  14.434567 2.669626

52   52  5  5  28.549402 3.351636

53   53  4  1   3.329605 1.202854

54   54  3  3  14.434567 2.669626

55   55  4  4  21.193913 3.053714

56   56  3  6  36.417738 3.595056

57   57  4  3  14.434567 2.669626

58   58  4  7  44.739851 3.800865

59   59  4  0  46.851000 3.846972

60   60  3  1   3.329605 1.202854

61   61  4  7  44.739851 3.800865

62   62  3  9  62.577007 4.136398

63   63  4  3  14.434567 2.669626

64   64  4  0  13.21 2.580974

65   65  3  1   3.329605 1.202854

66   66  4  1   3.329605 1.202854

67   67  4  3  14.434567 2.669626

68   68  4  4  21.193913 3.053714

69   69  4  3  14.434567 2.669626

70   70  3  3  14.434567 2.669626

71   71  4  3  14.434567 2.669626

72   72  3  4  21.193913 3.053714

73   73  4  3  14.434567 2.669626

74   74  5  4  21.193913 3.053714

75   75  3  5  28.549402 3.351636

76   76  4  5  28.549402 3.351636

77   77  3  5  28.549402 3.351636

78   78  3  6  36.417738 3.595056

79   79  3  3  14.434567 2.669626

80   80  5  7  44.739851 3.800865

81   81  3  1   3.329605 1.202854

82   82  3  0   5.184000 1.645577

83   83  3  0   7.742000 2.046660

84   84  6  2   8.400438 2.128284

85   85  5  0  80.941000 4.393720

86   86  3 14 112.876553 4.726295

87   87  4 17 146.278901 4.985515

88   88  4  7  44.739851 3.800865

89   89  5  3  14.434567 2.669626

90   90  5  3  14.434567 2.669626

91   91  4  4  21.193913 3.053714

92   92  3  5  28.549402 3.351636

93   93  4  2   8.400438 2.128284

94   94  3  7  44.739851 3.800865

95   95  4  8  53.471253 3.979144

96   96  4  2   8.400438 2.128284

97   97  3  5  28.549402 3.351636

98   98  6  1   3.329605 1.202854

99   99  5  3  14.434567 2.669626

100 100  4  7  44.739851 3.800865

101 101  4  8  53.471253 3.979144

102 102  3  5  28.549402 3.351636

103 103  4  3  14.434567 2.669626

104 104  5  3  14.434567 2.669626

105 105  3  5  28.549402 3.351636

106 106  4  9  62.577007 4.136398

107 107  4  5  28.549402 3.351636

108 108  4  4  21.193913 3.053714

109 109  4  7  44.739851 3.800865

110 110  4  9  62.577007 4.136398

111 111  3  1   3.329605 1.202854

112 112  3  1   3.329605 1.202854

113 113  4  2   8.400438 2.128284

114 114  4  2   8.400438 2.128284

115 115  4  4  21.193913 3.053714

116 116  3  4  21.193913 3.053714

117 117  3  3  14.434567 2.669626

118 118  5  2   8.400438 2.128284

119 119  4  4  21.193913 3.053714

120 120  3  1   3.329605 1.202854

121 121  4  3  14.434567 2.669626

122 122  4  5  28.549402 3.351636

123 123  4  5  28.549402 3.351636

124 124  4  4  21.193913 3.053714

125 125  3  4  21.193913 3.053714

126 126  3  3  14.434567 2.669626

127 127  4  2   8.400438 2.128284

128 128  5  0   6.436000 1.861907

129 129  5  1   3.329605 1.202854

130 130  5  1   3.329605 1.202854

131 131  5  1   3.329605 1.202854

132 132  4  3  14.434567 2.669626

133 133  3  1 

[R] How to document an S3 class?

2014-06-30 Thread Witold E Wolski
Hi,

How do I document an S3 class with roxygen2?


I create the class at the end of the method with:
class(res) <- "myclass"

but how do I create an documentation entry for this class, where I can
describe the fields of the class (in case of myclass these are just
list entries)?

regards





-- 
Witold Eryk Wolski

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/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] Change database in SQL Server using RODBC

2014-06-30 Thread Peter Crowther
On 30 June 2014 02:44, Ira Sharenow  wrote:
> I wish to query tables that are NOT in the default SQL Server 2012 database.
> Now for the problem. I also want to read in the table dbo.sports. That
> table is in the database sportsDB. I did not see any way to do so from
> within R.

Can you not use sportsDB.dbo.sports to reference the table?

In general, table reference syntax is [ [ [ serverName '.' ]
databaseName '.' ] [schema ] '.' ] tableName, where the names need
only be surrounded by [...] if they are not valid SQL Server
identifiers.  Many people may suggest you reference
[sportsDB].[dbo].[sports]; this is unnecessary verbiage.

Cheers,

- Peter

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

2014-06-30 Thread PIKAL Petr
Hi

Not much to cook from. Maybe

?approx

Regards
Petr


> -Original Message-
> From: r-help-boun...@r-project.org [mailto:r-help-bounces@r-
> project.org] On Behalf Of So
> Sent: Monday, June 30, 2014 7:05 AM
> To: r-help@r-project.org
> Subject: [R] Time series
>
> Hi There!
> I have a time series data for 13 years with freqency of 23 per year. I
> have plot the curve on R.
> Is it possible to refer to the point inbetween the nodes...
> eg. say the time series ts1 has ts1[1] 0.25 and ts1[2]=0.4. is it
> possible to get the time when ts1 reach to 0.3??
>
>
>
> --
> View this message in context: http://r.789695.n4.nabble.com/Time-
> series-tp4693234.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.


Tento e-mail a jakékoliv k němu připojené dokumenty jsou důvěrné a jsou určeny 
pouze jeho adresátům.
Jestliže jste obdržel(a) tento e-mail omylem, informujte laskavě neprodleně 
jeho odesílatele. Obsah tohoto emailu i s přílohami a jeho kopie vymažte ze 
svého systému.
Nejste-li zamýšleným adresátem tohoto emailu, nejste oprávněni tento email 
jakkoliv užívat, rozšiřovat, kopírovat či zveřejňovat.
Odesílatel e-mailu neodpovídá za eventuální škodu způsobenou modifikacemi či 
zpožděním přenosu e-mailu.

V případě, že je tento e-mail součástí obchodního jednání:
- vyhrazuje si odesílatel právo ukončit kdykoliv jednání o uzavření smlouvy, a 
to z jakéhokoliv důvodu i bez uvedení důvodu.
- a obsahuje-li nabídku, je adresát oprávněn nabídku bezodkladně přijmout; 
Odesílatel tohoto e-mailu (nabídky) vylučuje přijetí nabídky ze strany příjemce 
s dodatkem či odchylkou.
- trvá odesílatel na tom, že příslušná smlouva je uzavřena teprve výslovným 
dosažením shody na všech jejích náležitostech.
- odesílatel tohoto emailu informuje, že není oprávněn uzavírat za společnost 
žádné smlouvy s výjimkou případů, kdy k tomu byl písemně zmocněn nebo písemně 
pověřen a takové pověření nebo plná moc byly adresátovi tohoto emailu případně 
osobě, kterou adresát zastupuje, předloženy nebo jejich existence je adresátovi 
či osobě jím zastoupené známá.

This e-mail and any documents attached to it may be confidential and are 
intended only for its intended recipients.
If you received this e-mail by mistake, please immediately inform its sender. 
Delete the contents of this e-mail with all attachments and its copies from 
your system.
If you are not the intended recipient of this e-mail, you are not authorized to 
use, disseminate, copy or disclose this e-mail in any manner.
The sender of this e-mail shall not be liable for any possible damage caused by 
modifications of the e-mail or by delay with transfer of the email.

In case that this e-mail forms part of business dealings:
- the sender reserves the right to end negotiations about entering into a 
contract in any time, for any reason, and without stating any reasoning.
- if the e-mail contains an offer, the recipient is entitled to immediately 
accept such offer; The sender of this e-mail (offer) excludes any acceptance of 
the offer on the part of the recipient containing any amendment or variation.
- the sender insists on that the respective contract is concluded only upon an 
express mutual agreement on all its aspects.
- the sender of this e-mail informs that he/she is not authorized to enter into 
any contracts on behalf of the company except for cases in which he/she is 
expressly authorized to do so in writing, and such authorization or power of 
attorney is submitted to the recipient or the person represented by the 
recipient, or the existence of such authorization is known to the recipient of 
the person represented by the recipient.
__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/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] Time series

2014-06-30 Thread So
Hi There!
I have a time series data for 13 years with freqency of 23 per year. I have
plot the curve on R.
Is it possible to refer to the point inbetween the nodes... 
eg. say the time series ts1 has ts1[1] 0.25 and ts1[2]=0.4. is it possible
to get the time when ts1 reach to 0.3??



--
View this message in context: 
http://r.789695.n4.nabble.com/Time-series-tp4693234.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.