Re: [R] mapply instead for loop

2012-11-03 Thread Omphalodes Verna
Thanks for help.   But, I am surprised, that mapply is slower than for loop?   OV     From: Uwe Ligges Cc: "r-help@r-project.org" Sent: Saturday, November 3, 2012 4:32 PM Subject: Re: [R] mapply instead for loop On 30.10.2012 20:01, Omphalodes Verna wrot

Re: [R] Can you turn a string into a (working) symbol?

2012-11-03 Thread andrewH
Yes, the assign command goes a little way toward what what I was hoping for. But it requires a different syntax, and it does not in general let you use quoted expressions that you could use with other assignment operators. For instance, > DD <- 1:3 > assign("DD[2]", 5) > DD [1] 1 2 3 So I am s

Re: [R] Can you turn a string into a (working) symbol?

2012-11-03 Thread andrewH
Ah! Excellent! That will be most useful. And sorry about the typo. I found another function in a different discussion that also seems to work, at least in most cases I have tried. I do not at all understand the difference between the two. doppel <- function(x) {eval(parse(text=x)) However, ne

Re: [R] Changing Date Variables as Continuous Variables

2012-11-03 Thread Rolf Turner
There is a phenomenon that occurs here which, it seems to me, merits some emphasis. The glm() function appears to be perfectly willing to take a variable of class "Date" and treat it as a continuous variable. Apparently what it does (on the basis of one little experiment that I did) is convert

Re: [R] sqldf Date problem

2012-11-03 Thread jim holtman
Most likely your "Date" is either a character or a factor (you need to provide an 'str' of the dataframe). You are therefore most likely doing a character compare and that is the reason for your problem. You need to convert to a character string of the format -MM-DD to do the correct character

Re: [R] Changing Date Variables as Continuous Variables

2012-11-03 Thread jim holtman
Here is how to convert your column of factors into Dates: > x <- read.table(text = '2/10/2011 + 2/20/2011 + 3/4/2011') > # read in as factors > str(x) 'data.frame': 3 obs. of 1 variable: $ V1: Factor w/ 3 levels "2/10/2011","2/20/2011",..: 1 2 3 > # convert to Date > x$date <- as.Date(as.chara

[R] Changing Date Variables as Continuous Variables

2012-11-03 Thread hoguejm
I am very new to R, so I apologize if this question is trivial. I have a row in my data of dates in the format mm/dd/; about 3500 rows. I am using this variable in a logistic regression model, and need to treat it as continuous, not a factor as r has decided it is. I tried the as.numeric fu

[R] sqldf Date problem

2012-11-03 Thread Andreas Recktenwald
Dear R-help readers, i've created a database for quotes data (for 4 years; 2007 -- 2010) with the sqldf package. This database contains a column "Date" in the format mm/dd/. The table in the database is called "main.data" and the database itself "Honda". I tried to get the Data just f

Re: [R] importing jpeg 2000

2012-11-03 Thread Fred909
Mike, thanks for your answer. I thought GDAL is a library itself. You suggest underlying libraries. Do you know where can I find them? The other option: to convert the jpeg2000 files outside R: is it possible in R to execute an extern program? Btw I'm working with OSX Lion and still in the steep

Re: [R] lmPerm p-values and multiple testing

2012-11-03 Thread Pat
Even you used perm="Exact", the maximum observations allowed is only 10. If data exceeds this, perm="Prob" is used instead of "Exact". So, the p-values are always changed. The Porb method will approximate the permutation distribution by randomly exchanging pairs of Y elements. -- View this mes

Re: [R] Date format conversion from "2012-09-20" to "2012:09:20"

2012-11-03 Thread veepsirtt
Hi, thanks A.K try this not working #* # Load historical data #** library('quantmod') endDate =Sys.Date() startDate = as.Date(endDate-10, order="ymd") dataspy = getSymbo

[R] sqldf Date problem

2012-11-03 Thread Andreas Recktenwald
Dear R-help readers, i've created a database for quotes data (for 4 years; 2007 -- 2010) with the sqldf package. This database contains a column "Date" in the format mm/dd/. The table in the database is called "main.data" and the database itself "Honda". I tried to get the Data just

Re: [R] Replacing NAs in long format

2012-11-03 Thread arun
HI Bill, It is much simpler. # with aggregate() and merge()  res1<-with(dat2,aggregate(seq_len(nrow(dat2)),by=list(idr=idr),FUN=function(i) with(dat2[i,], any(schyear<=5 & year ==0  res2<-merge(dat2,res1,by="idr")  colnames(res2)[4]<-"flag"  within(res2,{flag<-as.integer(flag)})  #idr schyea

Re: [R] Replacing NAs in long format

2012-11-03 Thread William Dunlap
Or, even simpler, > flag <- with(dat2, ave(schyear<=5 & year==0, idr, FUN=any)) > data.frame(dat2, flag) idr schyear year flag 1 1 4 -1 TRUE 2 1 50 TRUE 3 1 61 TRUE 4 1 72 TRUE 5 2 90 FALSE 6 2 101 FALSE 7 2 112

Re: [R] Violin plot of categorical/binned data

2012-11-03 Thread Jim Lemon
On 11/04/2012 06:27 AM, Nathan Miller wrote: Hi, I'm trying to create a plot showing the density distribution of some shipping data. I like the look of violin plots, but my data is not continuous but rather binned and I want to make sure its binned nature (not smooth) is apparent in the final pl

Re: [R] Replacing NAs in long format

2012-11-03 Thread William Dunlap
ave() or split<-() can make that easier to write, although it may take some time to internalize the idiom. E.g., > flag <- rep(NA, nrow(dat2)) # add as.integer if you prefer 1,0 over TRUE,FALSE > split(flag, dat2$idr) <- lapply(split(dat2, dat2$idr), function(d)with(d, any(schyear<=5 & year

Re: [R] finding global variables in a function containing formulae

2012-11-03 Thread William Dunlap
> -Original Message- > From: William Dunlap > Sent: Saturday, November 03, 2012 11:23 AM > To: 'Hafen, Ryan P'; Bert Gunter > Cc: r-help@r-project.org > Subject: RE: [R] finding global variables in a function containing formulae > > findGlobals must be explicitly ignoring calls to the ~ fu

Re: [R] Replacing NAs in long format

2012-11-03 Thread arun
Hi, May be this helps: dat2<-read.table(text=" idr  schyear  year 1    4  -1 1    5    0 1    6    1 1    7    2 2    9    0 2    10    1 2    11  2 ",sep="",header=TRUE)  dat2$flag<-unlist(lapply(split(dat2,dat2$i

Re: [R] Replacing NAs in long format

2012-11-03 Thread Christopher Desjardins
I have a similar sort of follow up and I bet I could reuse some of this code but I'm not sure how. Let's say I want to create a flag that will be equal to 1 if schyear < = 5 and year = 0 for a given idr. For example > dat idr schyear year 1 4 -1 1 50 1

Re: [R] Replacing NAs in long format

2012-11-03 Thread Christopher Desjardins
Hi Jim, Thank you so much. That does exactly what I want. Chris On Sat, Nov 3, 2012 at 1:30 PM, jim holtman wrote: > > x <- read.table(text = "idr schyear year > + 1 80 > + 1 91 > + 1 10 NA > + 2 4 NA > + 2 5 -1 > + 2 60 > + 2 7

Re: [R] Can you turn a string into a (working) symbol?

2012-11-03 Thread jim holtman
for the second part use 'assign' > assign(paste0('a', 'a'), 3) > aa [1] 3 > On Sat, Nov 3, 2012 at 5:31 PM, andrewH wrote: > Dear folks-- > > Suppose I have an expression that evaluates to a string, and that that > string, were it not a character vector, would be a symbol. I would like a > fu

Re: [R] Can you turn a string into a (working) symbol?

2012-11-03 Thread jim holtman
Is this what you want (the answer you "wanted" is not correct): > aa <- 3.1416 > bb <- function(x) {x^2} > r <- 2 > xx <- c("aa", "bb") > > doppel <- function(x) get(x) > > out <- doppel(xx[1])*doppel(xx[2])(r) > > out [1] 12.5664 > On Sat, Nov 3, 2012 at 5:31 PM, andrewH wrote: > Dear fol

Re: [R] Logical vector-based extraction

2012-11-03 Thread jim holtman
works fine for me creating: > state_pflt200 <- df$p_fatal <200 > df[state_pflt200, c("state.name","p_fatal")] [1] state.name p_fatal <0 rows> (or 0-length row.names) > considering that there were no values less than 200 in your data, the result is correct. So what is the problem? On Sat, Nov 3

[R] Logical vector-based extraction

2012-11-03 Thread Muhuri, Pradip (SAMHSA/CBHSQ)
Hello, The most part of the program works except that the following logical variable does not get created although the second logical variable-based extraction works. I don't understand what I am doing wrong here. state_pflt200 <- df$p_fatal <200 df[state_pflt200, c("state.name","p_fatal")]

Re: [R] backreferences in gregexpr

2012-11-03 Thread Gabor Grothendieck
On Sat, Nov 3, 2012 at 4:08 PM, Alexander Shenkin wrote: > On 11/2/2012 5:14 PM, Gabor Grothendieck wrote: > > On Fri, Nov 2, 2012 at 6:02 PM, Alexander Shenkin > wrote: > >> Hi Folks, > >> > >> I'm trying to extract just the backreferences from a regex. > >> > >>> temp = "abcd1234abcd1234" > >>

[R] Can you turn a string into a (working) symbol?

2012-11-03 Thread andrewH
Dear folks-- Suppose I have an expression that evaluates to a string, and that that string, were it not a character vector, would be a symbol. I would like a function, call it doppel(), that will take that expression as an argument and produce something that functions exactly like the symbol woul

Re: [R] mergeing a large number of large .csvs

2012-11-03 Thread jim holtman
It easier than that. I forgot I can do it entirely within R: setwd("/temp/csv") files <- Sys.glob("daily*csv") output <- file('Rcombined.csv', 'w') for (i in files){ cat(i, '\n') # write out file processing input <- readLines(i) input <- input[-1L] # delete header writeLines(inp

Re: [R] mergeing a large number of large .csvs

2012-11-03 Thread jim holtman
These are not commands, but programs you can use. Here is a file copy program in "perl" (I spelt it wrong in the email); This will copy all the files that have "daily" in their names. It also skips the first line of each file assuming that it is the header. perl can be found on most systems.

Re: [R] backreferences in gregexpr

2012-11-03 Thread Alexander Shenkin
On 11/2/2012 5:14 PM, Gabor Grothendieck wrote: > On Fri, Nov 2, 2012 at 6:02 PM, Alexander Shenkin wrote: >> Hi Folks, >> >> I'm trying to extract just the backreferences from a regex. >> >>> temp = "abcd1234abcd1234" >>> regmatches(temp, gregexpr("(?:abcd)(1234)", temp)) >> [[1]] >> [1] "abcd123

Re: [R] mergeing a large number of large .csvs

2012-11-03 Thread Benjamin Caldwell
Jim, Where can I find documentation of the commands you mention? Thanks On Sat, Nov 3, 2012 at 12:15 PM, jim holtman wrote: > A faster way would be to use something like 'per', 'awk' or 'sed'. > You can strip off the header line of each CSV (if it has one) and then > concatenate the files t

Re: [R] some help

2012-11-03 Thread Rui Barradas
Hello, Without data it's not easy to answer to your questions, but 1. Use ?unlist. If the data is in a file, read it with ?read.table and the unlist the result. All columns will be stacked. dat <- read.table(filename, ...) unlist(dat) 2. At best confusing. But to divide a vector into groups

Re: [R] some help

2012-11-03 Thread David Winsemius
On Nov 3, 2012, at 9:07 AM, dattel_palme wrote: > Hi People! > > I have following concern consisting of some steps to do in R: > > I have an ascii file (table) consisting of many columns and rows. > 1. I would like to order all values of the columns one under each other. It > will begin with

[R] Violin plot of categorical/binned data

2012-11-03 Thread Nathan Miller
Hi, I'm trying to create a plot showing the density distribution of some shipping data. I like the look of violin plots, but my data is not continuous but rather binned and I want to make sure its binned nature (not smooth) is apparent in the final plot. So for example, I have the number of indivi

Re: [R] mergeing a large number of large .csvs

2012-11-03 Thread jim holtman
A faster way would be to use something like 'per', 'awk' or 'sed'. You can strip off the header line of each CSV (if it has one) and then concatenate the files together. This is very efficient use of memory since you are just reading one file at a time and then writing it out. Will probably be a

Re: [R] to print system.time always

2012-11-03 Thread jim holtman
I use notepad++ on Windows, so it is easy to add a "hotkey" that will surround a block of code that you want to execute with: system.time({..code to run..}) Usually you don't want it around each statement. I use the following function to have it print out CPU and memory usage at various

Re: [R] to print system.time always

2012-11-03 Thread Uwe Ligges
On 03.11.2012 19:42, jim holtman wrote: Here is a faster solution to your 'apply'; use 'sapply' instead: str(x) num [1:100, 1:30] 0.0346 0.4551 0.66 0.8528 0.5494 ... system.time(y <- apply(x, 1, cumsum)) user system elapsed 13.240.61 14.02 system.time(ys <- sapply(1:

Re: [R] to print system.time always

2012-11-03 Thread Uwe Ligges
On 03.11.2012 16:52, mrzung wrote: Hi all; I want to print system.time whenever I execute any command. It takes too much time to type "system.time()" function to all command. is there any solution on it? See ?Rprof on how to profile your code. And, apply(matrix,1,cumsum) command is too

Re: [R] to print system.time always

2012-11-03 Thread jim holtman
Here is a faster solution to your 'apply'; use 'sapply' instead: > str(x) num [1:100, 1:30] 0.0346 0.4551 0.66 0.8528 0.5494 ... > system.time(y <- apply(x, 1, cumsum)) user system elapsed 13.240.61 14.02 > system.time(ys <- sapply(1:col, function(a) cumsum(x[,a]))) user syst

Re: [R] Replacing NAs in long format

2012-11-03 Thread jim holtman
> x <- read.table(text = "idr schyear year + 1 80 + 1 91 + 1 10 NA + 2 4 NA + 2 5 -1 + 2 60 + 2 71 + 2 82 + 2 93 + 2 104 + 2 11 NA + 2 126 + 3 4 NA + 3 5 -2 +

Re: [R] override date in xts time series

2012-11-03 Thread arun
HI, Could you check whether you are getting the same result with tz="GMT"? as.POSIXct(x,format=fmt,tz="GMT") #[1] "2004-01-01 01:15:00 GMT" "2004-01-01 01:30:00 GMT" #[3] "2004-01-01 01:45:00 GMT" "2004-01-01 02:00:00 GMT" #[5] "2004-01-01 02:30:00 GMT" "2004-01-01 03:00:00 GMT" #[7] "2004-01-01 0

[R] to print system.time always

2012-11-03 Thread mrzung
Hi all; I want to print system.time whenever I execute any command. It takes too much time to type "system.time()" function to all command. is there any solution on it? And, apply(matrix,1,cumsum) command is too slow to some large matrix. is there any function like rowCumSums ? thank u! -

[R] optim & .C / Crashing on run

2012-11-03 Thread Paul Browne
Hello, I am attempting to use optim under the default Nelder-Mead algorithm for model fitting, minimizing a Chi^2 statistic whose value is determined by a .C call to an external shared library compiled from C & C++ code. My problem has been that the R session will immediately crash upon starting

Re: [R] reorder() in the latticeExtra library

2012-11-03 Thread arun
Hi, Try this: genotype1<-factor(genotype,levels=c("CJ1450 NW 4/25/12","CJ1450 BAL 4/25/12", "CJ1450 NW\n4/27/12", "CJ1450 BAL 4/27/12", "CJ1721 NW 4/27/12", "CJ1721 BAL\n4/27/12", "CJ1721 NW 4/29/12", "CJ1721 BAL 4/29/12") ) segplot(genotype1 ~ lower + upper, data = x, draw.bands = FALSE, center

[R] some help

2012-11-03 Thread dattel_palme
Hi People! I have following concern consisting of some steps to do in R: I have an ascii file (table) consisting of many columns and rows. 1. I would like to order all values of the columns one under each other. It will begin with column 1, then column 2 under column 1, column 3 under column 2

Re: [R] finding global variables in a function containing formulae

2012-11-03 Thread William Dunlap
findGlobals must be explicitly ignoring calls to the ~ function. You could poke through the source code of codetools and find where this is happening. Or, if you have the source code for the package you are investigating, use sed to change all "~" to "%TILDE%" and then use findGlobals on the resul

Re: [R] Replacing NAs in long format

2012-11-03 Thread Rui Barradas
Hello, Try the following. I've called your data.frames 'dat' and 'dat2' # First your datasets, see ?dput dput(dat) structure(list(idr = c(1L, 1L, 1L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L), schyear = c(8L, 9L, 10L, 4L, 5L, 6L, 7L, 8L, 9L, 10L, 11L, 12L, 4L, 5L, 6L, 7

Re: [R] reorder() in the latticeExtra library

2012-11-03 Thread David Winsemius
On Nov 3, 2012, at 6:36 AM, Jorge Dinis wrote: > Thanks David, I used you suggestion and it worked fine, please see below for > what I did. > > segplot(reorder(factor(genotype), genotype) ~ lower + upper Perhaps a missing close-paren . ^ Although reading this as a formatted posting

[R] Replacing NAs in long format

2012-11-03 Thread Christopher Desjardins
Hi, I have the following data: > data[1:20,c(1,2,20)] idr schyear year 1 80 1 91 1 10 NA 2 4 NA 2 5 -1 2 60 2 71 2 82 2 93 2 104 2 11 NA 2 126 3 4 NA 3 5 -2 3 6 -1 3

Re: [R] override date in xts time series

2012-11-03 Thread arun
Hi, Sorry, I forgot to answer the second question.  txt<-paste("\\10",unique(month(index(x.1))),"\\2",sep="")  #without the as.character() also should work #because  str(paste("\\10",unique(month(index(x.1))),"\\2",sep="")) # it returns a character # chr "\\101\\2" #Here too: str(paste(10,unique

Re: [R] override date in xts time series

2012-11-03 Thread Eric Morway
Sys.setenv(TZ="GMT") did the trick! Thank you very much. I'll continue to work the larger problem with this option. Out of curiosity, however, can the following code be modified so that the replacement argument is informed by the month of x.1?: index(y.1)<-as.POSIXct(gsub("(.*\\-).*(\\-.*)","

[R] AUTO: Alan Chalk has left RSA (returning 30/11/2012)

2012-11-03 Thread Alan Chalk
I am out of the office until 30/11/2012. Please send work related emails to laura.jor...@uk.rsagroup.com or personal emails to alanch...@gmail.com. Note: This is an automated response to your message "R-help Digest, Vol 117, Issue 3" sent on 03/11/2012 11:00:07. This is the only notification y

Re: [R] override date in xts time series

2012-11-03 Thread Eric Morway
Hello Arun, I too am using R 2.15 and am unable to get the same result as you. You will notice in the R code that follows that when I use 'update' the time in the xts object goes haywire. For example, "2004-04-04 01:15:00 EST" gets converted to "2004-01-03 22:15:00 PST" (see below). Because

Re: [R] rgl package and animation

2012-11-03 Thread Robert Baer
On 11/3/2012 6:47 AM, Duncan Murdoch wrote: On 12-11-02 7:47 PM, Robert Baer wrote: I am trying to figure out how to use rgl package for animation. It appears that this is done using the play3d() function. Below I have some sample code that plots a 3D path and puts a sphere at the point farthe

Re: [R] mergeing a large number of large .csvs

2012-11-03 Thread Jeff Newmiller
On the absence of any data examples from you per the posting guidelines, I will refer you to the help files for the melt function in the reshape2 package. Note that there can be various mixtures of wide versus long... such as a wide file with one date column and columns representing all stock p

Re: [R] Bioconductor, merging annotation with list of probeids

2012-11-03 Thread Uwe Ligges
On 03.11.2012 14:56, Brawni wrote: i will sorry! anyway it's a data.frame object. isn't that good? And what are you referring to? I do not see any citation in this message? A, some Nabble generated mail... Please do read the posting guide to this mailing list. Uwe Ligges -- View

Re: [R] mapply instead for loop

2012-11-03 Thread Uwe Ligges
On 30.10.2012 20:01, Omphalodes Verna wrote: Hi all! My question in about using mapply instead for loop. Below is a example with for loop: Is it posible to give same results with mapply function? Thanks for help! OV x <- 1:10 y <- 1:10 xyz <- data.frame(expand.grid(x,y)[1], expand.grid(x,y

[R] Contrasts in manova

2012-11-03 Thread paola
Hi everybody I am trying to find contrast in MANOVA. I used next code contrasts(ffage)<-ctr contrasts(ffage) MANOVA.agec<-manova(Y1~ffage,data=vol18.df) summary(MANOVA.agec, split =list (ffage=list("0-17 v over 18"=0, "18-25 v over 26"=1, "26-31 v over 32"=2, "32-42 v over 43"=3, "43-65 v 66+"=4

Re: [R] reorder() in the latticeExtra library

2012-11-03 Thread Jorge Dinis
Thanks David, I used you suggestion and it worked fine, please see below for what I did. segplot(reorder(factor(genotype), genotype) ~ lower + upper On Nov 3, 2012, at 2:47 AM, David Winsemius wrote: > define genotype as a factor [[alternative HTML version deleted]]

Re: [R] Bioconductor, merging annotation with list of probeids

2012-11-03 Thread Brawni
i will sorry! anyway it's a data.frame object. isn't that good? -- View this message in context: http://r.789695.n4.nabble.com/Bioconductor-merging-annotation-with-list-of-probeids-tp4648251p4648305.html Sent from the R help mailing list archive at Nabble.com. _

Re: [R] How to make pch symbols thicker?

2012-11-03 Thread Ben Tupper
On Nov 2, 2012, at 10:06 PM, 21rosit wrote: > Hi I need to know how to make pch symbols like pch=3 (+) or pch=4(x) or even > the border of squares or triangles thicker without changing the size. I have > a lot of symbols of different colors but you can't see the colors clearly > and I don't want

Re: [R] rgl package and animation

2012-11-03 Thread Duncan Murdoch
On 12-11-02 7:47 PM, Robert Baer wrote: I am trying to figure out how to use rgl package for animation. It appears that this is done using the play3d() function. Below I have some sample code that plots a 3D path and puts a sphere at the point farthest from the origin (which in this case also a

Re: [R] finding global variables in a function containing formulae

2012-11-03 Thread Gabor Grothendieck
On Thu, Nov 1, 2012 at 2:04 PM, Hafen, Ryan P wrote: > I need to find all global variables being used in a function and > findGlobals() in the codetools package works quite nicely. However, I am not > able to find variables that are used in formulae. Simply avoiding formulae > in functions is

Re: [R] mergeing a large number of large .csvs

2012-11-03 Thread Benjamin Caldwell
Jeff, If you're willing to educate, I'd be happy to learn what wide vs long format means. I'll give rbind a shot in the meantime. Ben On Nov 2, 2012 4:31 PM, "Jeff Newmiller" wrote: > I would first confirm that you need the data in wide format... many > algorithms are more efficient in long forma

Re: [R] reorder() in the latticeExtra library

2012-11-03 Thread David Winsemius
On Nov 2, 2012, at 8:04 PM, JDINIS wrote: > Hello all, thanks for your time and help. Below are my commands, and it > generates a really nice plot, however I am not happy with the reorder() > function. I would like the order to be the same as they appear in the > genotype variable "genotype <- c

[R] reorder() in the latticeExtra library

2012-11-03 Thread JDINIS
Hello all, thanks for your time and help. Below are my commands, and it generates a really nice plot, however I am not happy with the reorder() function. I would like the order to be the same as they appear in the genotype variable "genotype <- c("CJ1450 NW 4/25/12","CJ1450 BAL 4/25/12","CJ1450 NW