[R] Closing files after using write
When I run the following code in a loop I get an error after about 125 times saying too many open files... if(inherits(atmpt, "try-error")){ output <- paste(yahooSymbol,"\n",sep="") write(output, file = "data", append = TRUE, sep = "") } else { I've tried various things to close the file after write opens it, and looked through the RBase docs... but I can't find anything that succesfully closes the file. This is obviously trivial... any ideas Nick [[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] Closing files after using write
That would work... except I've got a DBConnection I don't want to close and open constantly On Mon, Dec 21, 2009 at 12:28 PM, Henrique Dallazuanna wrote: > Try: > > closeAllConnections() > > On Mon, Dec 21, 2009 at 3:22 PM, Nick Torenvliet > wrote: > > When I run the following code in a loop I get an error after about 125 > times > > saying too many open files... > > > > > > if(inherits(atmpt, "try-error")){ > >output <- paste(yahooSymbol,"\n",sep="") > >write(output, file = "data", append = TRUE, sep = "") > > } else { > > > > > > I've tried various things to close the file after write opens it, and > looked > > through the RBase docs... but I can't find anything that succesfully > closes > > the file. > > > > This is obviously trivial... any ideas > > > > Nick > > > >[[alternative HTML version deleted]] > > > > __ > > R-help@r-project.org mailing list > > https://stat.ethz.ch/mailman/listinfo/r-help > > PLEASE do read the posting guide > http://www.R-project.org/posting-guide.html > > and provide commented, minimal, self-contained, reproducible code. > > > > > > -- > Henrique Dallazuanna > Curitiba-Paraná-Brasil > 25° 25' 40" S 49° 16' 22" O > [[alternative HTML version deleted]] __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] Closing files after using write
Hey all, thanks for your input... assigning the connection and then using unlink works just fine. Thanks On Mon, Dec 21, 2009 at 12:33 PM, Gray Calhoun wrote: > Hi Nick, > I hope you're being a little disingenuous about how hard you looked > > Typing ?close will pull up the right help page. I think you're > having trouble because you don't store the file object in a variable, > so there's no convenient way to refer to it when you need to close it > (or when you want to write to it...). Do three different steps: 1) > open file. 2) write to file. 3) close file; and you should be fine. > > You also don't need to open the file 125 times: open it before the loop. > > --Gray > > On Mon, Dec 21, 2009 at 11:22 AM, Nick Torenvliet > wrote: > > When I run the following code in a loop I get an error after about 125 > times > > saying too many open files... > > > > > > if(inherits(atmpt, "try-error")){ > >output <- paste(yahooSymbol,"\n",sep="") > >write(output, file = "data", append = TRUE, sep = "") > > } else { > > > > > > I've tried various things to close the file after write opens it, and > looked > > through the RBase docs... but I can't find anything that succesfully > closes > > the file. > > > > This is obviously trivial... any ideas > > > > Nick > > > >[[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. > > > > > > -- > Gray Calhoun > > Assistant Professor of Economics > Iowa State University > [[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] accessing members of a data.frame
I have the following code fileList <-list.files(path = ".", pattern = "[^a-z].txt$", all.files = FALSE, full.names = FALSE, recursive = FALSE, ignore.case = FALSE) for (x in 1:length(fileList)){ fileLines <- data.frame(read.table(fileList[x])) print(string) } the lines of the file all have the following format... AB,20091224,156,156,154,154,55,1198 Can I access the comma separated values directly via indexes on fileLines? e.g. I want to be able to do something like this... >date <- fileLines[1][2] >print(date) "20091224" I've been trying for a while and I haven't been able to hit the separate elements. Nick [[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] Accessing members
Consider the following > fileLines V1 V2V3V4 V5 V6V7 V8 1 AB 20091224 156.0 156.0 154.00 154.0055 1198 2 AB.C 20091224 156.0 156.0 156.00 156.00 0 0 3 ABF10 20091224 156.0 156.0 156.00 156.0055444 4 ABH10 20091224 156.0 156.0 156.00 156.00 0749 5 ABH11 20091224 157.2 157.2 157.20 157.20 0 0 6 ABH12 20091224 157.2 157.2 157.20 157.20 0 0 7 ABK10 20091224 157.2 157.2 157.20 157.20 0 5 8 ABK11 20091224 157.2 157.2 157.20 157.20 0 0 9 ABN10 20091224 157.2 157.2 157.20 157.20 0 0 10 ABN11 20091224 157.2 157.2 157.20 157.20 0 0 11 ABV10 20091224 157.2 157.2 157.20 157.20 0 0 12 ABV11 20091224 157.2 157.2 157.20 157.20 0 0 13 ABZ10 20091224 157.2 157.2 157.20 157.20 0 0 14 ABZ11 20091224 157.2 157.2 157.20 157.20 0 0 15RS 20091224 395.0 395.0 381.42 381.42 12918 100618 16 RS.C 20091224 395.0 399.1 395.00 398.70 1680 0 17 RSF10 20091224 395.0 399.1 395.00 398.70 2277 3081 18 RSF11 20091224 420.3 420.3 420.30 420.3050203 19 RSF12 20091224 415.5 415.5 415.50 415.50 0 0 20 RSH10 20091224 401.1 403.9 399.50 403.60 9925 79548 21 RSH11 20091224 419.2 419.2 419.20 419.20 0193 22 RSK10 20091224 406.9 409.9 406.40 409.90 264 5769 23 RSK11 20091224 415.5 415.5 415.50 415.50 0 0 24 RSN10 20091224 414.7 415.2 410.00 415.20 189 6391 25 RSN11 20091224 415.5 415.5 415.50 415.50 0 2 26 RSX10 20091224 414.9 417.9 413.00 417.30 213 5431 27 RSX11 20091224 415.5 415.5 415.50 415.50 0 0 28WF 20091224 363.0 363.0 363.00 363.00 0 0 29WW 20091224 152.0 152.0 152.00 152.00 0 0 > attributes (fileLines) $names [1] "V1" "V2" "V3" "V4" "V5" "V6" "V7" "V8" $class [1] "data.frame" $row.names [1] 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 [26] 26 27 28 29 > fileLines[1,2] [1] 20091224 As expected! > fileLines[1,3] [1] 156 As expected! > fileLines[1,1] [1] AB 29 Levels: AB AB.C ABF10 ABH10 ABH11 ABH12 ABK10 ABK11 ABN10 ABN11 ... WW Doh! How do I access the "AB" element directly? Nick [[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] Accessing members
Thanks everyone... the as.character(fileLines[1][1]) solution worked well... Factors??? the treatment is so far away from what I know. Cool though... On Mon, Dec 28, 2009 at 8:55 PM, David Winsemius wrote: > > On Dec 28, 2009, at 5:14 PM, Nick Torenvliet wrote: > > Consider the following >> >> fileLines >>> >> V1 V2V3V4 V5 V6V7 V8 >> 1 AB 20091224 156.0 156.0 154.00 154.0055 1198 >> 2 AB.C 20091224 156.0 156.0 156.00 156.00 0 0 >> 3 ABF10 20091224 156.0 156.0 156.00 156.0055444 >> > . > > . > >> >> attributes (fileLines) >>> >> $names >> [1] "V1" "V2" "V3" "V4" "V5" "V6" "V7" "V8" >> >> $class >> [1] "data.frame" >> >> $row.names >> [1] 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 >> 24 >> 25 >> [26] 26 27 28 29 >> >> fileLines[1,2] >>> >> [1] 20091224 >> As expected! >> >> fileLines[1,3] >>> >> [1] 156 >> As expected! >> >> fileLines[1,1] >>> >> [1] AB >> 29 Levels: AB AB.C ABF10 ABH10 ABH11 ABH12 ABK10 ABK11 ABN10 ABN11 ... WW >> Doh! >> >> How do I access the "AB" element directly? >> > > You already did access that element directly. You were given a bit more > information than you expected but the value of fileLines[1,1] is "AB" and > you were also advised that such value was one of 29 possible values for the > particular factor set of which it is a member. > > > -- > David > > >> Nick >> >>[[alternative HTML version deleted]] >> >> __ >> R-help@r-project.org mailing list >> https://stat.ethz.ch/mailman/listinfo/r-help >> PLEASE do read the posting guide >> http://www.R-project.org/posting-guide.html >> and provide commented, minimal, self-contained, reproducible code. >> > > [[alternative HTML version deleted]] __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
[R] error logging
Yet another question... I'm wondering if there is a built in facility to log errors. I've got this statement that gives me verbose DBI errors as they come up (to standard output), but I'd like to trap and log them to a file as I running about 300 sql statements through this particular piece of code and I'd like to keep the loop going and deal with all the errors once the bulk of it has been processed. atmpt <- try(dbGetQuery(con,sql)) options(show.error.messages = TRUE) if(inherits(atmpt, "try-error")){ } The R docs aren't structured in the way I'm used to(I will get the hang of it)... so I'm more than willing to ?theDesiredCommand at the R - prompt... if you'd lead me in the right direction. Thanks again! Nick [[alternative HTML version deleted]] __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] error logging
Beauty thank-you... I'm crashing but I'll check that out in a couple when I get back. Must go snowboarding tomorrow! On Mon, Dec 28, 2009 at 11:20 PM, Gabor Grothendieck < ggrothendi...@gmail.com> wrote: > Try this: > > logfile <- file("logfile") > open(logfile, "w") > sink(logfile, type = "message") > 1/"a" # generate an error > > > On Mon, Dec 28, 2009 at 11:11 PM, Nick Torenvliet > wrote: > > Yet another question... > > > > I'm wondering if there is a built in facility to log errors. I've got > this > > statement that gives me verbose DBI errors as they come up (to standard > > output), but I'd like to trap and log them to a file as I running about > > 300 sql statements through this particular piece of code and I'd like > to > > keep the loop going and deal with all the errors once the bulk of it has > > been processed. > > > >atmpt <- try(dbGetQuery(con,sql)) > >options(show.error.messages = TRUE) > >if(inherits(atmpt, "try-error")){ > > > >} > > > > The R docs aren't structured in the way I'm used to(I will get the hang > of > > it)... so I'm more than willing to ?theDesiredCommand at the R - > prompt... > > if you'd lead me in the right direction. > > > > Thanks again! > > > > Nick > > > >[[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] seg-fault... but on what
I got the following after running succesfully through this loop 28 million times... the loop opens text files in a directory and inserts line by line into a database... *** caught segfault *** address 0xc010, cause 'memory not mapped' Traceback: 1: .getGeneric(f, where, package) 2: getGeneric("coerce", where = where) 3: as(obj, "integer") 4: mysqlConnectionInfo(dbObj, ...) 5: dbGetInfo(conn, "rsId") 6: dbGetInfo(conn, "rsId") 7: dbListResults(con) 8: dbListResults(con) 9: mysqlQuickSQL(conn, statement, ...) 10: dbGetQuery(con, sql) 11: dbGetQuery(con, sql) 12: doTryCatch(return(expr), name, parentenv, handler) 13: tryCatchOne(expr, names, parentenv, handlers[[1L]]) 14: tryCatchList(expr, classes, parentenv, handlers) 15: tryCatch(expr, error = function(e) {call <- conditionCall(e)if (!is.null(call)) {if (identical(call[[1L]], quote(doTryCatch))) call <- sys.call(-4L)dcall <- deparse(call)[1L]prefix <- paste("Error in", dcall, ": ") LONG <- 75Lmsg <- conditionMessage(e)sm <- strsplit(msg, "\n")[[1L]]if (14L + nchar(dcall, type = "w") + nchar(sm[1L], type = "w") > LONG) prefix <- paste(prefix, "\n ", sep = "")}else prefix <- "Error : "msg <- paste(prefix, conditionMessage(e), "\n", sep = "").Internal(seterrmessage(msg[1L])) if (!silent && identical(getOption("show.error.messages"), TRUE)) {cat(msg, file = stderr()) .Internal(printDeferredWarnings())}invisible(structure(msg, class = "try-error"))}) 16: try(dbGetQuery(con, sql)) 17: eval.with.vis(expr, envir, enclos) 18: eval.with.vis(ei, envir) 19: source("~/SoothSayer/EODData/DBScripts/loadEODQuotes.r") Possible actions: 1: abort (with core dump, if enabled) 2: normal R exit 3: exit R without saving workspace 4: exit R saving workspace Selection: The code is pretty simple... library(RMySQL) drv <- dbDriver("MySQL") con <- dbConnect(drv, host="localhost", dbname="markets", user="root", pass="embryoni3") fileList <- list.files(pattern = "[[:upper:]]{2,}", all.files = FALSE, full.names = FALSE, recursive = FALSE, ignore.case = FALSE) for (x in 1:length(fileList)){ string <- strsplit(fileList[x], "_", fixed = TRUE) string <- string[[1]][1] fileLines <- read.csv(fileList[x],header = FALSE,row.names = NULL ) for ( j in 1:length(fileLines[,1])){ sql <- paste("insert into endOfDayData (date,market,symbol,open,high,low,close,volume) values ('", fileLines[j,2],"','",string,"','",as.character(fileLines[j,1]),"','",fileLines[j,3],"','",fileLines[j,4],"','",fileLines[j ,5],"','",fileLines[j,6],"','",fileLines[j,7],"')",sep="") #print(sql) atmpt <- try(dbGetQuery(con,sql)) options(show.error.messages = TRUE) if(inherits(atmpt, "try-error")){ } } } dbDisconnect(con) My understanding was that in general R liked to put a placekeeper like NA or NULL in for non-existent elements of defined structures... so I was surprised to see a seg fault... I'm having trouble interpretting the error... any clues would be appreciated. Nick [[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] seg-fault... but on what
Thanks Duncan, I'll work on reproducibility and possibly getting a core dump... If I get those I'll post to R-dev or RMySQL-dev. Nick On Wed, Dec 30, 2009 at 9:36 AM, Duncan Murdoch wrote: > On 30/12/2009 9:20 AM, Nick Torenvliet wrote: > >> I got the following after running succesfully through this loop 28 million >> times... the loop opens text files in a directory and inserts line by line >> into a database... >> >> > > This looks like a bug in RMySql or possibly R. What versions are you > using? Can you make it happen reproducibly with the same script? Can you > simplify the script so it happens quickly, rather than requiring 28 million > iterations? Without a simple recipe to reproduce it, I doubt if anyone > would be able to track down the problem. > > Duncan Murdoch > >> *** caught segfault *** >> address 0xc010, cause 'memory not mapped' >> >> Traceback: >> 1: .getGeneric(f, where, package) >> 2: getGeneric("coerce", where = where) >> 3: as(obj, "integer") >> 4: mysqlConnectionInfo(dbObj, ...) >> 5: dbGetInfo(conn, "rsId") >> 6: dbGetInfo(conn, "rsId") >> 7: dbListResults(con) >> 8: dbListResults(con) >> 9: mysqlQuickSQL(conn, statement, ...) >> 10: dbGetQuery(con, sql) >> 11: dbGetQuery(con, sql) >> 12: doTryCatch(return(expr), name, parentenv, handler) >> 13: tryCatchOne(expr, names, parentenv, handlers[[1L]]) >> 14: tryCatchList(expr, classes, parentenv, handlers) >> 15: tryCatch(expr, error = function(e) {call <- conditionCall(e)if >> (!is.null(call)) {if (identical(call[[1L]], >> quote(doTryCatch))) call <- sys.call(-4L)dcall <- >> deparse(call)[1L]prefix <- paste("Error in", dcall, ": ") >> LONG <- 75Lmsg <- conditionMessage(e)sm <- strsplit(msg, >> "\n")[[1L]]if (14L + nchar(dcall, type = "w") + nchar(sm[1L], type >> = >> "w") > LONG) prefix <- paste(prefix, "\n ", sep = >> "")}else prefix <- "Error : "msg <- paste(prefix, >> conditionMessage(e), "\n", sep = "").Internal(seterrmessage(msg[1L])) >> if (!silent && identical(getOption("show.error.messages"), TRUE)) >> {cat(msg, file = stderr()) >> .Internal(printDeferredWarnings())}invisible(structure(msg, class >> = >> "try-error"))}) >> 16: try(dbGetQuery(con, sql)) >> 17: eval.with.vis(expr, envir, enclos) >> 18: eval.with.vis(ei, envir) >> 19: source("~/SoothSayer/EODData/DBScripts/loadEODQuotes.r") >> >> Possible actions: >> 1: abort (with core dump, if enabled) >> 2: normal R exit >> 3: exit R without saving workspace >> 4: exit R saving workspace >> Selection: >> >> >> The code is pretty simple... >> >> >> library(RMySQL) >> drv <- dbDriver("MySQL") >> con <- dbConnect(drv, host="localhost", dbname="markets", user="root", >> pass="embryoni3") >> fileList <- list.files(pattern = "[[:upper:]]{2,}", all.files = FALSE, >> full.names = FALSE, recursive = FALSE, ignore.case = FALSE) >> for (x in 1:length(fileList)){ >>string <- strsplit(fileList[x], "_", fixed = TRUE) >>string <- string[[1]][1] >>fileLines <- read.csv(fileList[x],header = FALSE,row.names = NULL ) >> >>for ( j in 1:length(fileLines[,1])){ >>sql <- paste("insert into endOfDayData >> (date,market,symbol,open,high,low,close,volume) values ('", >> >> fileLines[j,2],"','",string,"','",as.character(fileLines[j,1]),"','",fileLines[j,3],"','",fileLines[j,4],"','",fileLines[j >> ,5],"','",fileLines[j,6],"','",fileLines[j,7],"')",sep="") >>#print(sql) >>atmpt <- try(dbGetQuery(con,sql)) >>options(show.error.messages = TRUE) >>if(inherits(atmpt, "try-error")){ >> >>} >> >>} >> >> } >> >> dbDisconnect(con) >> >> My understanding was that in general R liked to put a placekeeper like NA >> or >> NULL in for non-existent elements of defined structures... so I was >> surprised to see a seg fault... I'm having trouble interpretting the >> error... any clues would be appreciated. >> >> Nick >> >>[[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] capturing stdout
I'm wondering if anyone knows of a way to capture system messages, for instance when I do the following: > system("../DBScripts/getEODData.sh") .//LSE_20091230.txt: 154.80 kB 207.24 kB/s ./Fundamentals//LSE.txt: 420.58 kB 301.47 kB/s ./Fundamentals//MLSE.txt:3.42 kB 16.20 kB/s Remote host has closed the connection. ncftpget /: remote host closed control connection. > I'd like to get the stdout from the system call into some memory location where I can play with it... Is there a simple way to do this? [[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] Subtracting time series
Hi all, I've got a time series object (xts) called table. Table contains closing price and volume for each market day of 2009 on a given equity. I'd like to get another xts object, say table2, that contains for each market day holds the close of that day minus the close of the day before and the volume of that day minus the volume of the day before. So table2 <- table[x,] - table[(x-1),] But I can't quit get the syntax, any help would be appreciated. Nick [[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] Simple 3D Plot Question
Hi all, I've got a simple 3D plot as follows... > xx <- seq(-20,20,.5) > yy <- seq(-20,20,.5) > zFunc <- function(x,y){3*x^2*y} > z <- outer(xx,yy,zFunc) > persp(xx,yy,z,theta=30,phi=30,ticktype="detailed") Just beautiful! My question is how do I constrain the plot to only display x^2 <= y <= 1? Thanks in advance, Nick [[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] Labels for matplot x axis
Hi all, I've been messing with this for a while now.. myStudy is a matrix of word frequency to date of document/document. As you can see I'm trying to plot the series in the matrix. I'd like three things -- 1- In the plot that gets created the first series is a solid line, the rest are dashed... how do I make them either one or the other. 2- The legend that comes up has filled boxes with colour as legend keys, I'd like to show coloured lines for legend keys instead. 3- The x axis of the plot come up labelled 0-80 with major intervals of twenty, I'd like to see (@45 degrees) the axis labelled with the rownames of myStudy, and I'd like to be able to control the interval at which these major ticks are displayed. I messed around for an hour or two, and was able to get the rownames on the x axis using the last command. I tried using at w/ seq w/ %% but I can't get the major tick intervals. > myStudy Terms Docs china greec greece greek 201003025691 058 201003036294 0 101 2010030420 125 085 201003059877 050 201003063112 0 9 20100308 12550 032 . . . . 201006157529 013 201006168421 0 8 201006173610 010 2010061860 8 0 7 20100620 113 4 0 3 20100621 741 7 5 1 > matplot(myStudy,type="l", main = "Word Study",xlab="WSJ Print Date",ylab="Word Frequency",col=c("blue","red","green")) > legend(10,600,colnames(myStudy),fill=c("blue","red","green")) >axis(1,at=1:95,labels=rownames(myStudy),las=1) Thanks for your time!! Nick [[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] Labels for matplot x axis
Jim, I just checked your help out and everything works fine except the axis labels, I should probably have been more specific. I had already been able to draw the rownames() as labels, what I was looking for was the capacity to define major ticks, and hence draw only every nth rowname on the graph as a label with a tickmark... is this possible? On Tue, Jun 22, 2010 at 7:48 AM, Jim Lemon wrote: > On 06/22/2010 08:05 PM, Nick Torenvliet wrote: > >> Hi all, I've been messing with this for a while now.. >> >> myStudy is a matrix of word frequency to date of document/document. >> >> As you can see I'm trying to plot the series in the matrix. >> >> I'd like three things -- >> 1- In the plot that gets created the first series is a solid line, the >> rest >> are dashed... how do I make them either one or the other. >> > > lty=1 > > > 2- The legend that comes up has filled boxes with colour as legend keys, >> I'd like to show coloured lines for legend keys instead. >> > > specify col=("blue","red","green"),lty=1 instead of fill() > > > 3- The x axis of the plot come up labelled 0-80 with major intervals of >> twenty, I'd like to see (@45 degrees) the axis labelled with the rownames >> of myStudy, and I'd like to be able to control the interval at which these >> major ticks are displayed. >> > > try staxlab(1,at=1:95,labels=rownames(myStudy),srt=45,cex=0.5) but you will > want to stretch the plot out horizontally and adjust the "cex" argument to > get the best readability. > > Jim > [[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] Plotting by factor with xts
Hi all, I've got an xts time series of stock symbols and closing prices. > head(x) symbol close 2010-01-04 "AFB" "13.46" 2010-01-04 "AKP" "12.80" 2010-01-04 "APX" " 8.78" 2010-01-04 "AYN" "13.15" 2010-01-04 "BAF" "13.50" 2010-01-04 "BBF" "12.86" > tail(x) symbol close 2011-01-21 "VMO" "12.35" 2011-01-21 "VOQ" "13.77" 2011-01-21 "VPV" "11.97" 2011-01-21 "VTJ" "14.74" 2011-01-21 "VTN" "13.16" 2011-01-21 "XAA" "12.82" > is.xts(x) [1] TRUE I've made the symbols a factor > head(xFactor) symbol AFBAKPAPXAYNBAFBBF 154 Levels: AFB AKP APX AYN BAF BBF BBK BFK BFO BFZ BIE BJZ BKK BKN BLH ... XAA Each factor represent a time series on closing prices. I would like to plot those 154 time series on a single plot... Any ideas? Regards, Nick [[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] Plotting multiple xts/zoo time series on a single plot.
So I've got a 154 column wide xts time series object and I want to plot the 154 series on a single plot and have the added benefit of the time series dates on the x axis. Any suggestions for plotting functions, maplot works but does not give dates on the axis and I can't seem to get plot to give me more than one series. Nick [[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] Simple problem with lm/predict
Hi all, I've got an xts time series with monthly OHLC Dow Jones industrial index data from 1980 to present, the data is in stored in x. I've done an OLS fit on the data in 1982::1994 and stored it in extrapolate1 (x[,4] contains the closing value for the index). > t3 <- seq(1980,1994,length = length(x["1980::1994",4])) > t4<-t3^2 > extrapolate1 <- lines(lm(x["1980::1994",4]~t3+t4)$fit) > extrapolate1 Call: lm(formula = x["1980::1994", 4] ~ t3 + t4) Coefficients: (Intercept) t3 t4 3.161e+07 -3.205e+048.125e+00 The plot comes up with the appropriate line fit for 1980::1994, so I can safely say the model/fit is correct. I want to plot the predicted response of extrapolate into 1995 and beyond and after much googling have got about this close -- > new.t <- seq(1995,len=2*12,by = 1/12) > new.dat <- data.frame(Time = new.t, Seas = rep(1:12,2)) > predict(extrapolate1,new.dat)[1:24] 12345678 704.9639 714.5726 724.2807 734.0882 743.9951 754.0014 764.1071 774.3122 9 10 11 12 13 14 15 16 784.6168 795.0207 805.5240 816.1267 826.8288 837.6303 848.5312 859.5315 17 18 19 20 21 22 23 24 870.6313 881.8304 893.1289 904.5268 916.0241 927.6209 939.3170 951.1125 Warning message: 'newdata' had 24 rows but variable(s) found have 180 rows This is straight from the net, the trouble is with how new.dat is set up but I can't figure it out... Regards, Nick [[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 Choosing Start Values for nls
Hi all, I'm trying to do a simple curve fit and coming up with some interesting results I would like to get comment on. So as shown below, tsR is my explanatory and response is... well... my response. This same data in gnumeric gets fitted with the curve "response=10078.4 + 1358.67 * ln (explanatory - 2009.07) So I'm using nls with the start values supplied by gnumeric. in "First Time Through" I'm very close to the values gnumeric found, I get NaNs and Infinities. In "Second Time Through" I use the "exact" values given by gnumeric... and it all come together fine. The difference between start value in First and Second time through is practically insignificant and gnumeric was able to fit this without effort. At this rate R is basically useless to me -- what can I change here to set R up better for this non-linear fit? What a shame... such a beautiful curve :-) **Data*** > response [1] 7062.93 7608.92 8168.12 8500.33 8447.00 9171.61 9496.28 9712.28 [9] 9712.73 10344.84 10428.05 10067.33 10325.26 10856.63 11008.61 10136.63 [17] 9774.02 10465.94 10319.95 > tsR [1] 2009.167 2009.250 2009.333 2009.417 2009.500 2009.583 2009.667 2009.750 [9] 2009.833 2009.917 2010.000 2010.083 2010.167 2010.250 2010.333 2010.417 [17] 2010.500 2010.583 2010.667 ***First Time Through*** > reFit <- nls(response ~ A + B * log(tsR - C), start=c(A=1,B=1350,C=2000)) Error in numericDeriv(form[[3L]], names(ind), env) : Missing value or an infinity produced when evaluating the model In addition: Warning message: In log(tsR - C) : NaNs produced ***Second Time Through*** > reFit <- nls(response ~ A + B * log(tsR-C),start=c(A=10078.4,B=1358.67,C=2009.07)) > summary(reFit) Formula: response ~ A + B * log(tsR - C) Parameters: Estimate Std. Error t value Pr(>|t|) A 1.008e+04 1.427e+0270.628 < 2e-16 *** B 1.359e+03 2.997e+02 4.534 0.000339 *** C 2.009e+03 7.314e-02 27468.499 < 2e-16 *** --- Signif. codes: 0 *** 0.001 ** 0.01 * 0.05 . 0.1 1 Residual standard error: 388.8 on 16 degrees of freedom Number of iterations to convergence: 6 Achieved convergence tolerance: 6.394e-06 [[alternative HTML version deleted]] __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
[R] Error w tokenizer .jcall unless run as root
Hi all, I've got an R script that loads the following libraries library(rJava) library(RWeka) library(tm) At some when I try to run the tm tokenizer as MyTokenizer <- function(x) NGramTokenizer(x, Weka_control(min = 1, max = 4)) ECONOMIST_TDM <- TermDocumentMatrix(ECONOMIST_CORPUS,control=list(tokenize=MyTokenizer)) I get the following error unless I'm running R as root... Error in .jcall("RWekaInterfaces", "[S", "tokenize", .jcast(tokenizer, : RcallMethod: cannot determine object class > ECONOMIST_TDM <- TermDocumentMatrix(ECONOMIST_CORPUS,control=list(tokenize=MyTokenizer)) Error in .jcall("RWekaInterfaces", "[S", "tokenize", .jcast(tokenizer, : RcallMethod: cannot determine object class I first noticed this problem in the summer, and just left it thinking I would stumble across a solution. I do realize this means I need to set permissions somewhere properly -- but I haven't stumbled across the affected file and even if I don't know what the proper permisions/owner/group should be. Does anyone know what I need to do? I'm running R on Lucid Lynx. Regards, Nick [[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] xyplot text sizing
Hi all, I'm using xyplot(closingDataXTS) To get a page with any number of seperate plots on it (as many plots as columns in closingDataXTS). Each plot is named according to colnames(closingDataXTS). I would like to control the size of the text each plot name appears in. I've seen a number of solutions for similar problems that point me in the direction of trellis.par.get and trellis.par.set but have been unable to put anything together that works. Any ideas for me? Nick [[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.