Re: [R] Runtime error in R

2013-08-14 Thread Camilo Mora
Thanks Jeff: I simplified my code and a single line in which I open a file causes this problem. The file opens well in another program and smaller files open just fine in R. So it seems the problem is with a default value somewhere for how big the files can be. I am suspicious of this as R

Re: [R] How to extract last value in each group

2013-08-14 Thread peter dalgaard
On Aug 15, 2013, at 00:03 , David Winsemius wrote: > > On Aug 14, 2013, at 2:18 PM, Steve Lianoglou wrote: > >> While we're playing code golf, likely faster still could be to use >> data.table. Assume your data is in a data.frame named "x": >> >> R> library(data.table) >> R> x <- data.table(x,

Re: [R] why Vectorize conjures a list, not a vector?

2013-08-14 Thread Hervé Pagès
Hi Zhang, First note that a list is a vector (try is.vector(list())). The documentation for sapply() and Vectorize() should say *atomic* vector instead of vector in the desccription of the 'simplify' and 'SIMPLIFY' arguments. So in order for sapply() to be able to simplify the result, all runs o

Re: [R] why Vectorize conjures a list, not a vector?

2013-08-14 Thread Jeff Newmiller
Vectorize is a functional version of a for loop that maps scalars to vectors or uniform length vectors to matrices, or any non-uniform vector to a list. Type the name of the function to see how it is implemented. You are giving it vectors of a variety of lengths, so you are getting a list back.

Re: [R] Grap Element from Web Page

2013-08-14 Thread Sparks, John James
Thanks so much for looking into this for me. Unfortunately, I get an error when I execute your code. Is there a library that you loaded that I haven't? require(scrapeR) require(XML) require(RCurl) doc<-htmlTreeParse("http://www.sec.gov/cgi-bin/browse-edgar?CIK=MSFT&Find=Search&owner=exclude&acti

[R] why Vectorize conjures a list, not a vector?

2013-08-14 Thread Zhang Weiwu
The manual seems to suggest, with the SIMPLIFY = TRUE default option, Vectorize would conjure a vector if possible. Quote: SIMPLIFY: logical or character string; attempt to reduce the result to a vector, matrix or higher dimensional array; see the ‘simplify’ argument of ‘sappl

Re: [R] changing colnames

2013-08-14 Thread farnoosh sheikhi
Thanks for the code. It was so simple and worked perfectly. I really appreciate it.   Best,Farnoosh Sheikhi Cc: R help Sent: Wednesday, August 14, 2013 11:56 AM Subject: Re: changing colnames Hi, You could try: dat1<- read.table(text=" X1,X2,X3 age,race,stat

[R] A question about using delayedAssign

2013-08-14 Thread Gang Peng
I run the examples in delayedAssign: msg <- "old" delayedAssign("x", msg) msg <- "new!" x If I run these four commands together, x is "new". If I run the first two commands first and then run the last two commands, x is "old". I just cannot figure out why. Thanks. Gang [[alternative HT

Re: [R] regex challenge

2013-08-14 Thread Guanrao Chen
This might be hard. How to tell f is to be changed while h is NOT ...   Thanks, Guanrao http://www.myfav5.com where fun and easy friend-making happens From: Frank Harrell To: RHELP Sent: Wednesday, August 14, 2013 11:13 PM Subject: [R] regex challenge I

[R] regex challenge

2013-08-14 Thread Frank Harrell
I would like to be able to use gsub or gsubfn to process a formula and to translate the variables but to ignore expressions in the formula. Supposing that the R formula has already been transformed into a character string and that the transformation is to convert variable names to upper case an

Re: [R] condense repetitive code for read.csv and rename.vars

2013-08-14 Thread arun
HI, You could try: #If all the files are in the working directory: vec1<-list.files() #Created 3 dummy files in my WD vec1 #[1] "mergedStatstA.csv" "mergedStatstB.csv" "mergedStatstC.csv" library(gdata) lapply(seq_along(vec1),function(i) {x1<-read.csv(vec1[i],header=TRUE,sep="\t");x2<-rename.va

Re: [R] convert delimited strings with ranges to numeric

2013-08-14 Thread Bert Gunter
Better yet! -- Bert On Wed, Aug 14, 2013 at 6:03 PM, Richard M. Heiberger wrote: > I would use source > >> x<- "2,5-7,10,12-15" >> source(textConnection(paste("c(", gsub("\\-", ":", x), ")")))$value > [1] 2 5 6 7 10 12 13 14 15 > > > > On Wed, Aug 14, 2013 at 8:10 PM, Bert Gunter wrote: >>

Re: [R] convert delimited strings with ranges to numeric

2013-08-14 Thread arun
I had earlier came up with a similar kind of function, though didn't posted. unlist(lapply(strsplit(x,",")[[1]],function(x) sapply(strsplit(x,"-"),function(x) {x1<-as.numeric(x);if(length(x1)==2) seq(x1[1],x1[2]) else x1}))) A.K. - Original Message - From: Bert Gunter To: arun Cc: Ch

Re: [R] barplot: add an image in each bar

2013-08-14 Thread Jim Lemon
On 08/15/2013 01:16 AM, Igor Ribeiro wrote: Dear all, I need to insert an small icon in each bar of a barplot, in a specific location (depending on bar's value). For example: the first bar has X value of 5. I need to insert an icon at X value 3. The second bar has X value of 8. I need to insert a

Re: [R] condense repetitive code for read.csv and rename.vars

2013-08-14 Thread Siraaj Khandkar
On 08/14/2013 03:43 PM, bcrombie wrote: Is there a more concise way to write the following code? library(gdata) mydataOUTPUTrtfA <- read.csv("mergedStatstA.csv") save(mydataOUTPUTrtfA, file="mydataOUTPUTrtfA.RData") mydataOUTPUTrtfA <- rename.vars(mydataOUTPUTrtfA, from="X", to="Statistics.Calcu

Re: [R] convert delimited strings with ranges to numeric

2013-08-14 Thread Richard M. Heiberger
I would use source > x<- "2,5-7,10,12-15" > source(textConnection(paste("c(", gsub("\\-", ":", x), ")")))$value [1] 2 5 6 7 10 12 13 14 15 On Wed, Aug 14, 2013 at 8:10 PM, Bert Gunter wrote: > Neither gsubfn nor eval(parse)) is required, of course: > > > x<- "2,5-7,10,12-15" > > z <-str

Re: [R] Barplots

2013-08-14 Thread Jim Lemon
On 08/14/2013 10:40 PM, Alexander Gotowski wrote: Hi, I'm attempting to make a bar plot for some genomics data that includes a separate bar for each sample taken. I am having trouble applying these sample labels to the individual bars. It seems that the barplot() function will only ta

Re: [R] convert delimited strings with ranges to numeric

2013-08-14 Thread Bert Gunter
Neither gsubfn nor eval(parse)) is required, of course: > x<- "2,5-7,10,12-15" > z <-strsplit(scan(text=x,sep=",",wh="a"),split="-") ## use scan to vectorize > the string > l <- lapply(z,as.numeric) > unlist(lapply(l,function(x){ last <- x[length(x)]## alternately could use if() on the len

Re: [R] Matrix Multiplication using R.

2013-08-14 Thread Roger Koenker
In the event that these are moderately sparse matrices, you could try Matrix or SparseM. Roger Koenker rkoen...@illinois.edu On Aug 14, 2013, at 10:40 AM, Praveen Surendran wrote: > Dear all, > > I am exploring ways to perform multiplication of a 9 x 4 matrix with > it's transpose

Re: [R] convert delimited strings with ranges to numeric

2013-08-14 Thread arun
Hi, May be this helps: library(gsubfn) as.numeric(strsplit(gsub("[c() ]","",gsubfn("([0-9]+)-([0-9]+)", ~as.numeric(seq(x,y)),x)),",")[[1]]) #[1]  2  5  6  7 10 12 13 14 15 A.K. - Original Message - From: Chris Stubben To: r-help@r-project.org Cc: Sent: Wednesday, August 14, 2013 1:41

Re: [R] How to extract last value in each group

2013-08-14 Thread David Winsemius
On Aug 14, 2013, at 2:18 PM, Steve Lianoglou wrote: > While we're playing code golf, likely faster still could be to use > data.table. Assume your data is in a data.frame named "x": > > R> library(data.table) > R> x <- data.table(x, key=c('Date', 'Time')) > R> ans <- x[, .SD[.N], by='Date'] I t

Re: [R] How to extract last value in each group

2013-08-14 Thread Michael Hannon
Or how about rle/cumsum, as per the appended? -- Mike > myData <- read.table("junk.dat", header=TRUE, stringsAsFactors=FALSE) > myData Date Time O H L C U D 1 06/01/2010 1358 136.40 136.40 136.35 136.35 2 12 2 06/01/2010 1359 136.40 136.50 136.35 136.50 9 6 3 06/01/2010 1400 136.45 136.55 136.35

[R] condense repetitive code for read.csv and rename.vars

2013-08-14 Thread bcrombie
Is there a more concise way to write the following code? library(gdata) mydataOUTPUTrtfA <- read.csv("mergedStatstA.csv") save(mydataOUTPUTrtfA, file="mydataOUTPUTrtfA.RData") mydataOUTPUTrtfA <- rename.vars(mydataOUTPUTrtfA, from="X", to="Statistics.Calculated", info=FALSE) mydataOUTPUTrtfB <- r

Re: [R] getting rid of .Rhistory and .RData

2013-08-14 Thread David Winsemius
On Aug 14, 2013, at 8:16 AM, MacQueen, Don wrote: > A look at ?history shows an environment variable that might help you > restrict it to just one central .Rhistory file. I'm guessing this refers to the fourth paragraph and it appears that suppressing any history saving may be possible as well.

Re: [R] How to extract last value in each group

2013-08-14 Thread Steve Lianoglou
Or with plyr: R> library(plyr) R> ans <- ddply(x, .(Date), function(df) df[which.max(df$Time),]) -steve On Wed, Aug 14, 2013 at 2:18 PM, Steve Lianoglou wrote: > While we're playing code golf, likely faster still could be to use > data.table. Assume your data is in a data.frame named "x": > > R

Re: [R] How to extract last value in each group

2013-08-14 Thread Steve Lianoglou
While we're playing code golf, likely faster still could be to use data.table. Assume your data is in a data.frame named "x": R> library(data.table) R> x <- data.table(x, key=c('Date', 'Time')) R> ans <- x[, .SD[.N], by='Date'] -steve On Wed, Aug 14, 2013 at 2:01 PM, William Dunlap wrote: > A s

Re: [R] Producing multiple analyses (histograms/kernel densities) of network timings between groups

2013-08-14 Thread David Carlson
I'm not sure I follow you exactly so let's start with some data and one graph and move on from there: First the data (I'm assuming you don't have A to A so you really want 3 lines on a graph)? set.seed(42) pairs <- structure(list(From = structure(c(1L, 1L, 1L, 2L, 2L, 2L, 3L, 3L, 3L, 4L, 4L, 4L)

Re: [R] How to extract last value in each group

2013-08-14 Thread William Dunlap
A somewhat faster version (for datasets with lots of dates, assuming it is sorted by date and time) is isLastInRun <- function(x) c(x[-1] != x[-length(x)], TRUE) f3 <- function(dataFrame) { dataFrame[ isLastInRun(dataFrame$Date), ] } where your two suggestions, as functions, are f1 <

Re: [R] How to extract last value in each group

2013-08-14 Thread Noah Silverman
That works beautifully. Never used the unlist or "with" commands before. More to learn there. Thanks! -- Noah Silverman, M.S., C.Phil UCLA Department of Statistics 8117 Math Sciences Building Los Angeles, CA 90095 On Aug 14, 2013, at 1:08 PM, arun wrote: > Hi, > Try: > dat1<- read.table(t

Re: [R] force pdf()

2013-08-14 Thread Thomas Petzoldt
Hi, this is not a problem of R it is a problem of the pdf viewer. Solution: just use an alternative pdf viewer like gsview or (even simpler) SumatraPDF. Hope it helps Thomas P. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/list

Re: [R] How to extract last value in each group

2013-08-14 Thread arun
Hi, Try: dat1<- read.table(text="     Date Time  O  H  L  C  U  D 06/01/2010 1358 136.40 136.40 136.35 136.35  2  12 06/01/2010 1359 136.40 136.50 136.35 136.50  9  6 06/01/2010 1400 136.45 136.55 136.35 136.40  8  7 06/01/2010 1700 136.55 136.55 136.55 136.55  1  0 06/02/2010 

Re: [R] getting rid of .Rhistory and .RData

2013-08-14 Thread Patrick Connolly
On Wed, 14-Aug-2013 at 04:01PM +0200, Jannis wrote: |> Well, I have made some tests with the 'no save' option. This only |> seems to control the saving of .RData files (at least none appeared |> in the working directory in my tests). A file called .RHistory is |> still created. I can now put some

[R] How to extract last value in each group

2013-08-14 Thread Noah Silverman
Hello, I have some stock pricing data for one minute intervals. The delivery format is a bit odd. The date column is easily parsed and used as an index for an its object. However, the time column is just an integer (1:1807) I just need to extract the *last* entry for each day. Don't actuall

Re: [R] Modifying a design matrix in mgcv

2013-08-14 Thread David Winsemius
On Aug 14, 2013, at 12:46 PM, Andrew Crane-Droesch wrote: > Thanks! I hadn't touched environment variables before, not knowing what they > were. The G$X matrix indeed seems to get squared, giving appropriately > nonsensical results. I can now go and code a (hopefully) sensible change to > i

Re: [R] Matrix Multiplication using R.

2013-08-14 Thread Bert Gunter
Well, one might start by noting that it's usually unnecessary and unwise to multiply a matrix by its transpose. Matrix decompositions, algebraic identities, and/or iterative procedures usually do calculations involving t(x)%*%x in better ways. 'Course without knowledge of your problem, maybe I'm

Re: [R] Modifying a design matrix in mgcv

2013-08-14 Thread Andrew Crane-Droesch
Thanks! I hadn't touched environment variables before, not knowing what they were. The G$X matrix indeed seems to get squared, giving appropriately nonsensical results. I can now go and code a (hopefully) sensible change to it. On 08/14/2013 10:32 PM, David Winsemius wrote: environment(mo

Re: [R] Problem with zero-inflated negative binomial model in sediment river dynamics

2013-08-14 Thread Achim Zeileis
On Wed, 14 Aug 2013, Cade, Brian wrote: Z is correct, of course.  I was just being a little too simplistic in my explanation trying to emphasize the reversal of signs of the coefficients in the logistic regression part of the zero-inflated model. When users ask me what the binary part of the

Re: [R] Modifying a design matrix in mgcv

2013-08-14 Thread David Winsemius
On Aug 14, 2013, at 11:08 AM, Andrew Crane-Droesch wrote: > Hello, > > I am trying to make a slight modification to the way gam (mgcv) works. > I want to modify the G$X matrix, which is the design matrix, to > accommodate an estimator that I am trying to program. I am working with > panel d

Re: [R] changing colnames

2013-08-14 Thread Daniel Nordlund
> -Original Message- > From: r-help-boun...@r-project.org [mailto:r-help-boun...@r-project.org] > On Behalf Of arun > Sent: Wednesday, August 14, 2013 11:56 AM > To: farnoosh sheikhi > Cc: R help > Subject: Re: [R] changing colnames > > Hi, > You could try: > dat1<- read.table(text=" > X1,

Re: [R] Matrix Multiplication using R.

2013-08-14 Thread Doran, Harold
Do your matrices have any special properties we should know about? For example, are they sparse, symmetric, diagonal, etc? -Original Message- From: r-help-boun...@r-project.org [mailto:r-help-boun...@r-project.org] On Behalf Of Praveen Surendran Sent: Wednesday, August 14, 2013 11:41 AM

Re: [R] Problem with zero-inflated negative binomial model in sediment river dynamics

2013-08-14 Thread Lauria, Valentina
Dear Brian and Achim, Many thanks for your reply and help it is very much appreciated! All the best, Valentina Dr. Valentina Lauria Postdoctoral researcher Room 118, Martin Ryan Institute Department of Earth and Ocean Sciences National University of Ireland, Galway Ireland www.nephrops.eu

[R] Matrix Multiplication using R.

2013-08-14 Thread Praveen Surendran
Dear all, I am exploring ways to perform multiplication of a 9 x 4 matrix with it's transpose. As expected even a 4 x 100 %*% 100x4 didn't work on my desktop... giving the error "Error: cannot allocate vector of length 16" However I am trying to run this on one node (64G

Re: [R] Create rows for columns in dataframe

2013-08-14 Thread Dark
Hi Arun, The second method is indeed working much faster. It worked fast for my 600.000 row record. Still I have 2 bigger files where processing becomes an issue even though I have lots of memory (32 gig) for the second statement: res2<-reshape(dat2,idvar="newCol",varying=list(2:26),direction="lon

[R] Producing multiple analyses (histograms/kernel densities) of network timings between groups

2013-08-14 Thread Jack Challen
(This is a repost from a little while ago. I assume my mail got silently bounced because I used some rather strange email routing. If it did get through, and I simply haven't seen it or a response, then please accept my apologies) Hi, I'm new to R, and new to statistics. I'm *trying* to learn

[R] Negative page rank values

2013-08-14 Thread Farhan Ahmed
Hello, I'm using igraph for some simple network analysis of a directed graph. When I calculate the page-rank using page.rank(g), the returned vector contains negative values. The vector sums to 1, which tells me that the algorithm working fine. How do I interpret the negative values and is there

[R] barplot: add an image in each bar

2013-08-14 Thread Igor Ribeiro
Dear all, I need to insert an small icon in each bar of a barplot, in a specific location (depending on bar's value). For example: the first bar has X value of 5. I need to insert an icon at X value 3. The second bar has X value of 8. I need to insert an icon at value 7. I have both vectors with va

Re: [R] changing colnames

2013-08-14 Thread arun
Hi, You could try: dat1<- read.table(text=" X1,X2,X3 age,race,stat 12,2,35 17,6,55 ",sep=",",header=TRUE,stringsAsFactors=FALSE) colnames(dat1)<- dat1[1,]  dat1<- dat1[-1,] dat1[]<-lapply(dat1,as.numeric) row.names(dat1)<- 1:nrow(dat1)  dat1 #  age race stat #1  12    2   35 #2  17    6   55 A.K.

Re: [R] Understanding S4 method dispatch

2013-08-14 Thread Hervé Pagès
And it doesn't even select "the first method lexicographically in the ordering" (whatever that means): setClass("B", "NULL") setClass("A", "NULL") setMethod("show", "B", function(object) cat("B object\n")) setMethod("show", "A", function(object) cat("A object\n")) setClass("AB", contai

[R] R: recommended linux version for R user

2013-08-14 Thread Otto
The one you can have some assistance from friends an colleagues around. Ditoni + tastierina =erroru di battitura Jie ha scritto: >Dear All, > >I plan to switch to linux and run R, latex and CUDA on it. >For this reason, which is the recommended version of linux (stable, >efficient, compatible e

Re: [R] How to "vectorize" subsetting

2013-08-14 Thread Steve Lianoglou
Howdy, On Wed, Aug 14, 2013 at 9:40 AM, Bert Gunter wrote: > mod Jeff Newmiller's comments... > > 1. Have you read"An Introduction to R? (or other basic tutorial -- > there are many on the web). If no, stop posting and do so. This will > help you to understand R's basic data manipulation capabili

[R] recommended linux version for R user

2013-08-14 Thread Jie
Dear All, I plan to switch to linux and run R, latex and CUDA on it. For this reason, which is the recommended version of linux (stable, efficient, compatible etc.)? It will be installed on a desktop, with intel i5, nvidia gpu, 16 gb ram. Thank for your attention and hopefully not off topic. Bes

[R] Modifying a design matrix in mgcv

2013-08-14 Thread Andrew Crane-Droesch
Hello, I am trying to make a slight modification to the way gam (mgcv) works. I want to modify the G$X matrix, which is the design matrix, to accommodate an estimator that I am trying to program. I am working with panel data, and I want to take all continuous variables, including basis funct

Re: [R] convert delimited strings with ranges to numeric

2013-08-14 Thread Marc Schwartz
On Aug 14, 2013, at 12:41 PM, Chris Stubben wrote: > Is there an easy way to convert character strings with comma-separated > numbers and ranges to a numeric vector? > > x<- "2,5-7,10,12-15" > > [1] 2 5 6 7 10 12 13 14 15 > > Thanks, > Chris > There is a general admonishment to not

Re: [R] Create rows for columns in dataframe

2013-08-14 Thread arun
Hi, This seemed to be faster than the other two methods: vec1<- as.character(rep(dat1[,1],each=(ncol(dat1)-1))) vec2<- as.character(unlist(t(dat1[,-1]))) vec3<- rep(rep(c(TRUE,FALSE),c(1,(ncol(dat1)-2))),nrow(dat1)) dat2<-data.frame(DSYSRTKY=vec1,CODE=vec2,PRIMAIRY=vec3,stringsAsFactors=FALSE) dat3

Re: [R] Understanding S4 method dispatch

2013-08-14 Thread Hervé Pagès
Hi Zehnder, You're right that the fact that B already inherits from A is probably part of the story but it's not all the story: setClass("A", "NULL") setClass("B", "A") setMethod("show", "A", function(object) cat("A object\n")) setMethod("show", "B", function(object) cat("B object\n"))

[R] convert delimited strings with ranges to numeric

2013-08-14 Thread Chris Stubben
Is there an easy way to convert character strings with comma-separated numbers and ranges to a numeric vector? x<- "2,5-7,10,12-15" [1] 2 5 6 7 10 12 13 14 15 Thanks, Chris -- Chris Stubben Los Alamos National Lab Bioscience Division MS M888 Los Alamos, NM 87545 _

Re: [R] Week number for a given date

2013-08-14 Thread Christofer Bogaso
Hi Rainer, Thanks for your pointer. However I was not looking the week number for the underlying year. Rather, week number for the underlying month. For example, if the date is 8/14/2013 then I should get the week number as '3'. Because it is 3rd week of August month. Any help on that? Thanks a

Re: [R] Understanding S4 method dispatch

2013-08-14 Thread Hadley Wickham
On Wed, Aug 14, 2013 at 11:36 AM, Simon Zehnder wrote: > Because the signature is always (A,A) or (B,B). Then, as in AB we have A and > B and no relationship between A and B, R chooses the method > lexicographically. The result is as expected: f for A is chosen. It's not as expected, because it

Re: [R] Week number for a given date

2013-08-14 Thread Rainer Schuermann
What about ?lubridate particulatrly week()? On Wednesday 14 August 2013 22:00:42 Christofer Bogaso wrote: > Hello again, > > I need to calculate the week number of the corresponding month given a date. > > Is there any function available with R to calculate that? > > Thanks and regards, > >

Re: [R] How to "vectorize" subsetting

2013-08-14 Thread Bert Gunter
mod Jeff Newmiller's comments... 1. Have you read"An Introduction to R? (or other basic tutorial -- there are many on the web). If no, stop posting and do so. This will help you to understand R's basic data manipulation capabilities and structures (list, "apply" type functions,...). 2. mod 1), pe

Re: [R] Understanding S4 method dispatch

2013-08-14 Thread Simon Zehnder
Because the signature is always (A,A) or (B,B). Then, as in AB we have A and B and no relationship between A and B, R chooses the method lexicographically. The result is as expected: f for A is chosen. If you would do something like: setClass("A", contains = "list") setClass("B", contains = "

[R] Week number for a given date

2013-08-14 Thread Christofer Bogaso
Hello again, I need to calculate the week number of the corresponding month given a date. Is there any function available with R to calculate that? Thanks and regards, [[alternative HTML version deleted]] __ R-help@r-project.org mailing list

Re: [R] Memory limit on Linux?

2013-08-14 Thread Stackpole, Chris
> From: Jack Challen [mailto:jack.chal...@ocsl.co.uk] > Sent: Wednesday, August 14, 2013 10:45 AM > Subject: RE: Memory limit on Linux? > > (I'm replying from a horrific WebMail UI. I've attempted to maintain > what I think is sensible quoting. Hopefully it reads ok). [snip] > If all users are abl

Re: [R] How to "vectorize" subsetting

2013-08-14 Thread Jeff Newmiller
If your efforts on those unspecified other forums were like this one, perhaps repeating what doesn't work is your problem. You don't appear to have read and understood the footer of any email on this list. For one thing, you need to post in plain text (to avoid the corruption that HTML email can

Re: [R] Memory limit on Linux?

2013-08-14 Thread Stackpole, Chris
> From: Kevin E. Thorpe [mailto:kevin.tho...@utoronto.ca] > Sent: Tuesday, August 13, 2013 2:25 PM > Subject: Re: [R] Memory limit on Linux? > > It appears that at the shell level, the differences are not to blame. > It has been a long time, but years ago in HP-UX, we needed to change an > actual

Re: [R] Understanding S4 method dispatch

2013-08-14 Thread Hadley Wickham
> In my opinion the reason for the behavior lies in the specific multiple > inheritance structure between AB, B and A. So what if we don't make such a weird inheritance structure, and instead have A and B inherit from a common parent: setClass("A", contains = "list") setClass("B", contains = "li

Re: [R] getting rid of .Rhistory and .RData

2013-08-14 Thread MacQueen, Don
A look at ?history shows an environment variable that might help you restrict it to just one central .Rhistory file. -Don -- Don MacQueen Lawrence Livermore National Laboratory 7000 East Ave., L-627 Livermore, CA 94550 925-423-1062 On 8/14/13 7:15 AM, "Jannis" wrote: >OK, this seems to b

Re: [R] Problem with zero-inflated negative binomial model in sediment river dynamics

2013-08-14 Thread Cade, Brian
Z is correct, of course. I was just being a little too simplistic in my explanation trying to emphasize the reversal of signs of the coefficients in the logistic regression part of the zero-inflated model. Brian Brian S. Cade, PhD U. S. Geological Survey Fort Collins Science Center 2150 Centre

Re: [R] [optim/bbmle] function returns NA

2013-08-14 Thread Ravi Varadhan
Carlos, There are likely several problems with your likelihood. You should check it carefully first before you do any optimization. It seems to me that you have box constraints on the parameters. They way you are enforcing them is not correct. I would prefer to use an optimization algorithm t

Re: [R] How to "vectorize" subsetting

2013-08-14 Thread Rainer Schuermann
I'm sure there are better, more elegant ways avoiding the nested loop I'm suggesting - but if it was my problem, here is what I would do (assuming that my understanding of your question is correct): ### separate function for 'doing something' with the data subset do.something <- function( qA, qB

[R] How to "vectorize" subsetting

2013-08-14 Thread Derickson, Ryan, VHACIN
I'm not trying to repost or spam everyone- I submitted this once before I subscribed so I just wanted to resend in case it didn't get disseminated. Hello all, I've tried to solve this for weeks and posted to other forums with little success- I'd appreciate any help from anyone. I

[R] ggplot

2013-08-14 Thread Patrick Ho
I am learning analysis of longitudinal data from the  book Longitudinal data Data Analysis for the Behavioral Science using R by Jeffrey Long. On page 123, myX <- scale_x_continuous(breaks = 5:8, name = "Grade") myY <- scale_y_continuous(name = " Reading Score ") g1 <- ggplot(data=MPLS.LS,

Re: [R] Create rows for columns in dataframe

2013-08-14 Thread arun
Hi, I tried the second method on a bigger dataset.  This is what I get, indx<-rep(1:nrow(dat1),6e4) dat2<- dat1[indx,] system.time({ vec1<- paste(dat2[,1],dat2[,2],colnames(dat2)[2],sep=".") res2<-reshape(dat2,idvar="newCol",varying=list(2:26),direction="long") res3<-res2[order(res2[,4]),] res4<

Re: [R] Double return statement

2013-08-14 Thread ONKELINX, Thierry
Dear Katherine, Combine both outputs in a list and return that. return(list(first = output.1, second = output.2)) Best regards, ir. Thierry Onkelinx Instituut voor natuur- en bosonderzoek / Research Institute for Nature and Forest team Biometrie & Kwaliteitszorg / team Biometrics & Quality Ass

Re: [R] Double return statement

2013-08-14 Thread Sarah Goslee
Hi, The usual thing to do is return a list containing output_1 and output_2. Sarah On Wed, Aug 14, 2013 at 10:23 AM, Katherine Gobin wrote: > Dear R forum, > > I have a function which generates say two outputs, say output_1 and output_2. > Output_1 is a single row output whereas Output_2 is a

[R] Double return statement

2013-08-14 Thread Katherine Gobin
Dear R forum, I have a function which generates say two outputs, say output_1 and output_2. Output_1 is a single row output whereas Output_2 is a dataframe having multiple records. Is it possible to use two return statements in function. Output_2 uses some records from output_1, hence I need to

Re: [R] grImport/ghostscript problems

2013-08-14 Thread Prof Brian Ripley
On 14/08/2013 14:52, Andrew Halford wrote: Hi Again, I still cannot get the PostscriptTrace to work. The error message remains the same. I have run the following with no problems Sys.setenv(R_GSCMD="c:/Program Files(x86)/gs/gs9.07/bin/gswin32") but the call to Postscript Trace still fails

Re: [R] getting rid of .Rhistory and .RData

2013-08-14 Thread Jannis
OK, this seems to be only a problem when I use emacs/ess. I will try to find a solution to this but this does not seem to be related to emacs. In case anyone of you has an Idea: I use: (setq inferior-R-args "--no-save --no-restore --silent") to start R, but still a .RHistory file is saved. Ch

Re: [R] getting rid of .Rhistory and .RData

2013-08-14 Thread Jannis
Well, I have made some tests with the 'no save' option. This only seems to control the saving of .RData files (at least none appeared in the working directory in my tests). A file called .RHistory is still created. I can now put some code to delete this file in .Last function but somehow I thin

Re: [R] Comparing two columns in an Excel file

2013-08-14 Thread arun
Hi, Try: set.seed(42) dat1<- as.data.frame(matrix(sample(LETTERS,2*1e6,replace=TRUE),ncol=2)) dat2<- dat1[1:1e5,] dat3<- dat1 library(data.table) dt1<- data.table(dat1) system.time(dat1$sat<- 1*(dat1[,1]==dat1[,2])) #   user  system elapsed #  0.148   0.004   0.152 library(car) system.time({dat3$

Re: [R] grImport/ghostscript problems

2013-08-14 Thread Andrew Halford
Hi Again, I still cannot get the PostscriptTrace to work. The error message remains the same. I have run the following with no problems > Sys.setenv(R_GSCMD="c:/Program Files(x86)/gs/gs9.07/bin/gswin32") but the call to Postscript Trace still fails > PostScriptTrace("fish.ps") Error in PostSc

Re: [R] Barplots

2013-08-14 Thread Sarah Goslee
Hi, Your question doesn't quite make sense to me, and since you didn't provide a reproducible example it's impossible to really know what you're doing. Have you read ?barplot and tried the examples? There's a names.arg argument that takes a character vector that is used for labels. Otherwise the

[R] Barplots

2013-08-14 Thread Alexander Gotowski
Hi, I'm attempting to make a bar plot for some genomics data that includes a separate bar for each sample taken. I am having trouble applying these sample labels to the individual bars. It seems that the barplot() function will only take a numeric matrix, and therefore cannot have any c

Re: [R] Create rows for columns in dataframe

2013-08-14 Thread Dark
Hi A.K, Thanks for your great help. I'm now running your first suggestion on a 600.000 row sample after verifying it works on a smaller sample. It's now been running for 40 minutes. Which method do you think will be faster? Regards Derk -- View this message in context: http://r.789695.n4.nab

Re: [R] Lattice: bwplot - changing box colors in legend and plot when using panel.groups = function... and panel = panel.superpose

2013-08-14 Thread Anna Zakrisson Braeunlich
Thank you very much Kevin Wright! you managed to understand my somewhat cryptic question. Now I have a perfect graph. I changed the my.theme to: my.theme <- list( box.umbrella = list(col = "black"), box.rectangle = list(col="black"), box.dot = list(col = "black", pch = 3, cex=2), plot.sym

[R] How to "vectorize" subsetting

2013-08-14 Thread Derickson, Ryan, VHACIN
Hello all, I've tried to solve this for weeks and posted to other forums with little success- I'd appreciate any help from anyone. I have survey data grouped by facility and area (area is a collection of facilities). Questions are q1-q10. For each facility, I need to subset each item into the

Re: [R] getting rid of .Rhistory and .RData

2013-08-14 Thread Jannis
Thanks, I will look into ways to tell ess/emacs to use such options. I am, however, quite sure that I have never answered "yes" to the question when quitting R. Cheers Jannis On 13.08.2013 20:21, MacQueen, Don wrote: R --no-save __ R-help@r-pro

Re: [R] Grabbing numbers inside a character string

2013-08-14 Thread Simon Zehnder
Thomas, se ?sub and regular expression. That should make it. Further, see the package gsubfn Best Simon On Aug 14, 2013, at 2:14 PM, Thomas wrote: > I have a string that contains something like: > > ...verified email at neu.eduCited by > 99853 > and I'd like to extract the number next to

Re: [R] Grabbing numbers inside a character string

2013-08-14 Thread arun
Hi, Try: a1<- "...verified email at neu.eduCited by 99853 To: r-help@r-project.org Cc: Sent: Wednesday, August 14, 2013 8:14 AM Subject: [R] Grabbing numbers inside a character string I have a string that contains something like: ...verified email at neu.eduCited by 99853https://stat.ethz.ch/ma

[R] Grabbing numbers inside a character string

2013-08-14 Thread Thomas
I have a string that contains something like: ...verified email at neu.eduCited by 99853div> and I'd like to extract the number next to the text "Cited by " - so it will be whatever numbers are beside "Cited by " until a non-numeric character is reached. Can anyone suggest a good way of do

Re: [R] force pdf()

2013-08-14 Thread Prof Brian Ripley
On 14/08/2013 11:23, Christof Kluß wrote: Hi is there a way to generate a pdf, e.g. pdf("test.pdf"), even if the file "test.pdf" is open? (e.g. with acrobat) i.e. I would have to close "test.pdf" in the viewer without any user interaction, than override the file and maybe open it again. thx Ch

Re: [R] Lme4 and syntax of random factors

2013-08-14 Thread ONKELINX, Thierry
Dear Robert, (1|A/B) is shorthand for (1|A) + (1|A:B) ir. Thierry Onkelinx Instituut voor natuur- en bosonderzoek / Research Institute for Nature and Forest team Biometrie & Kwaliteitszorg / team Biometrics & Quality Assurance Kliniekstraat 25 1070 Anderlecht Belgium + 32 2 525 02 51 + 32 54 43

Re: [R] coxph diagnostics

2013-08-14 Thread Andrews, Chris
"Based on the plot of Schoenfeld residuals and Terry's explanation is it safe to say that proportional hazards assumption holds despite the significant global p-values?" No. I don't want to put words in Terry's mouth, but he seems to be saying that proportional hazards does NOT hold but it ma

Re: [R] storing multidimensional arrays - save and load -

2013-08-14 Thread Ista Zahn
You can use saveRDS() and readRDS() instead of save/load. Unlike load readRDS just returns the value, allowing you to assign it to whatever name you want. Best, Ista On Wed, Aug 14, 2013 at 5:52 AM, Witold E Wolski wrote: > I am have a procedure which generates multidimensional arrays. > > To

Re: [R] Understanding S4 method dispatch

2013-08-14 Thread Simon Zehnder
Ambiguity is indeed detected by R and the user is informed on it. But in the case of Hadley's example, I still believe, that the specific multiple inheritance structure creates this behavior. If you call: showMethods("f") Function: f (package .GlobalEnv) x="A", y="A" x="AB", y="AB" (inherite

[R] force pdf()

2013-08-14 Thread Christof Kluß
Hi is there a way to generate a pdf, e.g. pdf("test.pdf"), even if the file "test.pdf" is open? (e.g. with acrobat) i.e. I would have to close "test.pdf" in the viewer without any user interaction, than override the file and maybe open it again. thx Christof ___

Re: [R] Regression of categorical data

2013-08-14 Thread Achim Zeileis
On Tue, 13 Aug 2013, Walter Anderson wrote: I have a set of survey data where I have answers to identify preference of three categories using three questions 1) a or b? 2) b or c? 3) a or c? and want to obtain weights for each of the preferences something like X(a) + Y(b) + Z(c) = 100% You

Re: [R] Lme4 and syntax of random factors

2013-08-14 Thread Robert U
Thank you for your answer Ben B., it is helpful.  The post on Fixed vs Random effects is particularly interesting. I had in mind to create a fixed interaction, as you propose (time*A). I actually wanted to compare it with a random interaction, so to decide on which model to go with based on t

Re: [R] Problem with zero-inflated negative binomial model in sediment river dynamics

2013-08-14 Thread Achim Zeileis
On Tue, 13 Aug 2013, Cade, Brian wrote: Lauria: For historical reasons the logistic regression (binomial with logit link) model portion of a zero-inflated count model is usually structured to predict the probability of the 0 counts rather than the nonzero (>=1) counts so the coefficients will b

[R] storing multidimensional arrays - save and load -

2013-08-14 Thread Witold E Wolski
I am have a procedure which generates multidimensional arrays. To compute them is expensive so I want to store them in order to be able to analyse them later. I am using at the moment problem is that the array is always assigned to a variable ma (the computation is in a loop). Than I generate a

  1   2   >