Re: [R] RODBC Multiple Results

2020-03-30 Thread Law, Jason
Harold, I have dealt with this problem over the years and after much experimenting, I can say that I *think* what you want is impossible. For RODBC, you need a stored proc that uses SET NOCOUNT ON and that only returns a single result set. You may want to try experimenting with the odbc

Re: [R] One Dimensional Monte Carlo Simulation

2017-08-01 Thread Law, Jason
Tony, I’m not sure what exactly you’re trying to do, but you're not really taking advantage of vectorization in your R code. I've tried to clean it up a little. The clamped lognormal is almost always 0 or L? That seems a little odd. You seem to be using the inverse cdf method of drawing

Re: [R] Converting time zones in R using metadata file information of video files, help needed.

2015-11-23 Thread Law, Jason
The "lubridate" package will help simplify these time zone conversions. It provides two simple functions with_tz and force_tz that conceptually make things simpler. library(lubridate) > x <- as.POSIXct("2015-06-22 01:53:28", 'Europe/Berlin') > with_tz(x, 'America/Toronto') [1] "2015-06-21

Re: [R] help using extrafont package | R graphics

2014-04-30 Thread Law, Jason
On my system, the name of the Garamond font file is GARA.TTF. Thus, font_import(pattern = 'GARA') will work, but font_import(pattern=gara) won't. Unfortunately, font_import seems to fail rather ungracefully when there is no match to a pattern. Jason -Original Message- From:

Re: [R] Change data format query

2014-02-19 Thread Law, Jason
library(reshape2) data.melt - melt(data, id.vars = c('BH_ID', 'BH_Name', 'Pack_Name')) dcast(dm, BH_Name ~ Pack_Name) -Original Message- From: r-help-boun...@r-project.org [mailto:r-help-boun...@r-project.org] On Behalf Of drruddy gmail Sent: Wednesday, February 19, 2014 7:18 AM To:

Re: [R] creating an equivalent of r-help on r.stackexchange.com ? (was: Re: Should there be an R-beginners list?)

2014-02-04 Thread Law, Jason
Clint and Liviu, Stackoverflow also has rss feeds available, if you prefer being pushed the information that way. For the R tagged questions it's here: http://stackoverflow.com/feeds/tag/r. Since some e-mail clients double as feed readers, you may be able to read the feed from your e-mail

Re: [R] Plotting multiple trends on one graph

2013-11-25 Thread Law, Jason
Natalie, I'm assuming this is some kind of passive animal sampling? Instream PIT tags for fish? In that case, you can get what I think you want using ggplot2 and something like this: dat$TagID - as.factor(dat$TagID) dat$Station - as.factor(dat$Station) dat$Station2 - as.numeric(dat$Station)

Re: [R] spsurvey analysis

2013-11-01 Thread Law, Jason
I use the spsurvey package a decent amount. The cont.cdftest function bins the cdf in order to perform the test which I think is the root of the problem. Unfortunately, the default is 3 which is the minimum number of bins. I would contact Tom Kincaid or Tony Olsen at NHEERL WED directly to

Re: [R] Selecting maximums between different variables

2013-10-17 Thread Law, Jason
See ?pmax for getting the max for each year. do.call('pmax', oil[-1]) Or equivalently: pmax(oil$TX, oil$CA, oil$AL, oil$ND) apply and which.max will give you the index: i - apply(oil[-1], 1, which.max) which you can use to extract the state: names(oil[-1])[i] Jason -Original

Re: [R] Plot time series data irregularly hourly-spaced

2013-10-16 Thread Law, Jason
You just need the date, otherwise how would it know what time comes first? In strptime(), a date is being assumed. Try this: testtime-c(20:00:00,22:10:00,22:20:00,23:15:00,23:43:00,00:00:00,00:51:00,01:00:00) testday - rep(Sys.Date() - c(1,0), times = c(5,3)) plot(as.POSIXct(paste(testday,

Re: [R] Transposing the output of 'table'

2013-10-07 Thread Law, Jason
If you want a dataframe rather than a matrix, I often use the as.data.frame method for table objects. See ?table for the documentation. You can even nicely name the dimensions and frequency. OBJECT - sample(4, 20, TRUE) as.data.frame(table(var1 = OBJECT), responseName = 'frequency') Jason

Re: [R] function on columns of two arrays

2013-08-20 Thread Law, Jason
library(abind) library(plyr) c - abind(a,b, along = 4) results - alply(c, c(2,3), function(x) lm(x[,2] ~ x[,1])) ldply(results, function(x) summary(x)$coef) Jason Law Statistician City of Portland Bureau of Environmental Services Water Pollution Control Laboratory 6543 N Burlington Avenue

Re: [R] replace multiple values in vector at once

2013-07-12 Thread Law, Jason
In the plyr package there are also the functions revalue and mapvalues: library(plyr) x - c(a, b, c) revalue(x, c(a = A, c = C)) mapvalues(x, c(a, c), c(A, C)) mapvalues works on numeric, character and factor. Jason -Original Message- From: r-help-boun...@r-project.org

Re: [R] String based chemical name identification

2013-07-03 Thread Law, Jason
Might be better off using a web service like ChemSpider to do the matching for you http://www.chemspider.com/AboutServices.aspx?. The idea that you can identify the synonyms by name is probably optimistic unless they are exact matches. Here's some python code that seems to make it pretty

Re: [R] Loops

2013-06-25 Thread Law, Jason
Not sure what you're trying to do, but it looks like most of what you're attempting to do in the code can be done just using vectors rather than loops, at least the inner loop. For example: k - 1.15 l - exp((1 / k) * (7.16 - 0.44 + 0.12 - 0.016)) z - (log(1 / p) * l)^k See ifelse for how to

Re: [R] Reshape or Plyr?

2013-04-22 Thread Law, Jason
Hi Bruce, I work with a lot of similar data and have to do these types of things quite often. I find it helps to keep to vectorized code as much as possible. That is, do as many of the calculations as possible outside of the aggregation code. Here's one way: library(reshape2) # stick to a

Re: [R] Averaging Out many rows from a column AND funtion to string

2013-03-27 Thread Law, Jason
This completes in about a second on my system and uses the actual matrix dimensions you quote: nr - 153899 nc - 3415 keep - rnorm(nr * nc, 80, 20) dim(keep) - c(nr, nc) shrink.to - 1000 system.time( { idx - rep(1:shrink.to, length.out = nr) plot.me -

Re: [R] Plot cumulative sums of rainfall per year

2013-03-26 Thread Law, Jason
Try this: library(plyr) library(ggplot2) library(lubridate) data-read.csv(http://dl.dropbox.com/u/4236038/test_cumu.csv;) data$Date - as.Date(data$Date) cumu - ddply(data,.(year(Date)),transform, cumRain = cumsum(Rainfall)) ggplot(cumu, aes(x = yday(Date), y = cumRain, color =

Re: [R] R-help Digest, Vol 121, Issue 5

2013-03-05 Thread Law, Jason
On R 2.15.2 and ArcGIS 9.3.1, it works for me in ArcCatalog but you have to follow the particulars here: http://webhelp.esri.com/arcgisdesktop/9.3/index.cfm?TopicName=Accessing_delimited_text_file_data For example: write.table(test, '***.tab', sep = '\t', row.names = F) The extension .tab and

Re: [R] Install package automatically if not there?

2010-06-24 Thread Law, Jason
Something like: if (!require(pkg)){ install.packages(pkg) } Jason -Original Message- From: r-help-boun...@r-project.org [mailto:r-help-boun...@r-project.org] On Behalf Of Ralf B Sent: Thursday, June 24, 2010 12:26 PM To: r-help@r-project.org Subject: [R] Install package

Re: [R] Summing data based on certain conditions

2010-04-01 Thread Law, Jason
This should do the trick: data$date - as.Date(data$date, '%m/%d/%Y') data$month - format(data$date, '%Y-%m') by(data$rammday, data$month, sum) Hope that helps, Jason -Original Message- From: r-help-boun...@r-project.org [mailto:r-help-boun...@r-project.org] On Behalf Of Stephan

[R] create string of comma-separated content of vector

2009-05-19 Thread Law, Jason
See ?toString x - 0:10 toString(x) See ?sQuote for cases where the vector is a character and needs to be quoted. Jason Law Statistician City of Portland Bureau of Environmental Services Water Pollution Control Laboratory 6543 N Burlington Avenue Portland, OR 97203-5452

[R] R crash with ATLAS precompiled Rblas.dll on Windows XP Core2 Duo

2008-07-08 Thread Law, Jason
I noticed a problem using R 2.7.1 on Windows XP SP2 with the precompiled Atlas Rblas.dll. Running the code below causes R to crash. I started R using Rgui --vanilla and am using the precompiled Atlas Rblas.dll from cran.fhcrc.org dated 17-Jul-2007 05:04 for Core2 Duo. The code that causes the

[R] Different axis limits for each facet in ggplot2

2008-03-25 Thread Law, Jason
Does Hadley's response to the following post still hold for the most recent version of ggplot2? http://tolstoy.newcastle.edu.au/R/e2/help/07/07/21347.html#21379qlink2 I'm trying to accomplish in ggplot2 what the relation component of scales does in lattice, e.g., stripplot(yield ~ variety |

Re: [R] Help rewriting looping structure?

2007-12-06 Thread Law, Jason
This will give you the percents in the same order as your original data (as this is what your original code did) apply(tdat, 2, function(x) { o - order(x) oldo - order(o) prc - cumsum(x[o]) / sum(x) prc[oldo] }) Jason Law Statistician City of Portland, Bureau of