[R] File path expansion

2007-05-25 Thread McGehee, Robert
R-Help, I discovered a mis-feature is ghostscript, which is used by the bitmap function. It seems that specifying file names in the form ~/abc.png rather than /home/directory/abc.png causes my GS to crash when I open the bitmap device on my Linux box. The easiest solution would seem to be to

[R] Removing terms from formula

2006-11-29 Thread McGehee, Robert
R-help, Given a simple linear model, say lm(x ~ y + z), I would like to remove model terms that are factors with only one level. Thus, if 'z' were a factor with only one level, lm(x ~ y + z) becomes lm(x ~ y + 1). Likewise, if both 'y' and 'z' are one-level factors, then the resulting calculation

[R] Plotting text with lattice

2006-09-29 Thread McGehee, Robert
Hello, I've decided to take the leap and try my hand at the lattice package, though I am getting stuck at what one might consider a trivial problem, plotting text at a point in a graph. Apologies in advance if (that) I'm missing something extremely basic. Consider in base graphics: plot(1:10)

[R] Weighted Mean Confidence Interval

2006-08-09 Thread McGehee, Robert
Hello, I'm looking to calculate a 95% confidence interval about my estimate for a sample's weighted mean, where the calculated confidence interval would equal the t-test confidence interval of the sample in the case when all of the weights are equal. My initial thought was to simply implement a

[R] Capturing stderr from system()

2006-08-07 Thread McGehee, Robert
Hello, I have a system command that occasionally fails and writes output to standard error, which R will print to the screen when ignore.stderr = FALSE. For example: system(BadCommand) sh: line 1: BadCommand: command not found I would like to know if the above command fails, and can presumably

Re: [R] parallel computing

2006-05-25 Thread McGehee, Robert
Moreno, As much of my processor time is often spent doing basic linear algebra operations (matrix inversion, quadratic programming, etc), I recently recompiled R using a BLAS implementation (ATLAS) tuned for parallel processing. The speed improvement for linear algebra operations was significant

Re: [R] Fast update of a lot of records in a database?

2006-05-19 Thread McGehee, Robert
I was going to suggest sqlUpdate in RODBC, but it looks like that function also uses the UPDATE command repeated nrow times. A second strategy that I generally prefer because it does not require RODBC (as much) and better supports transaction control is to first create a temporary table with the

Re: [R] Fast update of a lot of records in a database?

2006-05-19 Thread McGehee, Robert
Hadley, There are several reasons that running one large load and one large update would be significantly faster than thousands of individual updates. First, the time it takes to execute a query does not grow linearly with the size of a query. That is, the statement: SELECT TOP 100 * FROM table

Re: [R] Newbie to R: would like to solve a problem

2006-05-12 Thread McGehee, Robert
Not sure I completely followed (especially what a Knockback is), but I'll give this a try. If you want to precisely define the convolution of multiple attacks, you would want to use a language that utilizes symbolic integration, which R currently does not support (e.g. see Mathematica). That

Re: [R] Newbie to R: would like to solve a problem

2006-05-12 Thread McGehee, Robert
Actually, if you're going to go out transform the data, why not use a Fourier transform and take advantage of the fact that F[f*g] = F[f]F[g]? That's the easiest way in my mind to do multiple convolutions of fitted data. Taylor series are neither good at modeling Schwartz functions (a rapidly

Re: [R] Create graphs from text console

2006-03-23 Thread McGehee, Robert
Also check out the GDD package created by Simon Urbanek if bitmap does not fit your needs. On some systems, bitmap is slow or produces an inferior quality plot, in part because anti-aliasing is not supported (at least on my system). GDD, however, produces excellent anti-aliased graphs using the GD

Re: [R] prepared query with RODBC ?

2006-03-02 Thread McGehee, Robert
code for ideas. HTH, Robert -Original Message- From: Laurent Gautier [mailto:[EMAIL PROTECTED] Sent: Thursday, March 02, 2006 3:20 AM To: McGehee, Robert Cc: r-help@stat.math.ethz.ch Subject: Re: [R] prepared query with RODBC ? Well, I may not have been clear enough. My experience

[R] Spearman correlation confidence interval

2006-02-28 Thread McGehee, Robert
R-help(ers), Does anyone know of an R function available for calculating a confidence interval for a Spearman correlation? If no such resource is available, is using the confidence interval from a Pearson correlation a reasonable proxy if the vectors come from normal distributions (i.e. likely

Re: [R] prepared query with RODBC ?

2006-02-28 Thread McGehee, Robert
I may be misunderstanding you, but why can't you execute a prepared query the same in RODBC as you would directly on your SQL server? In Microsoft SQL server, for instance, I would just set up an ADO application and set the Prepared and CommandText properties before running the query. Here is an

Re: [R] Scientific notation in plots

2006-01-13 Thread McGehee, Robert
You could also use a function like this to transform a number x into your beautiful notation, where x is the number and digits is the number of digits you would like to see after the decimal. Then you could use the axis and labels syntax suggested by Iain, as such: sciNotation - function(x,

Re: [R] a series of 1's and -1's

2006-01-11 Thread McGehee, Robert
I would compare the Shannon entropy of your test vector with the entropy of your expected probability distribution to see if they are close. That is, if you're binary probability distribution is half 1 and half -1, then if your string is long you would expect about half the numbers in your vector

Re: [R] R newbie example code question

2006-01-10 Thread McGehee, Robert
Hello, Why not just copy and paste the examples from the help pages? No need to type anything. However, if you'd like to run the entire help section for a function, check out the example function, i.e.: example(plot) Robert -Original Message- From: Mark Leeds [mailto:[EMAIL PROTECTED]

Re: [R] matching country name tables from different sources

2006-01-10 Thread McGehee, Robert
I would throw a tolower() around s1 and s2 so that 'canada' matches with 'CANADA', and perhaps consider using a Levenshtein distance rather than the longest common subsequence. An algorithm for Levenshtein distance can be found here (courtesy of Stephen Upton)

Re: [R] R is GNU S, not C.... [was how to get or store .....]

2005-12-06 Thread McGehee, Robert
Jan T. Kim wrote: There is a draft R Coding Convention available at http://www.maths.lth.se/help/R/RCC/ which may be useful for finding a style that is good because it is widely used and therefore familiar to a large number of readers.-- However, as the author Henrik Bengtsson

Re: [R] calculating IRR (accounting) in R

2005-11-30 Thread McGehee, Robert
Hello, If we define IRR implicitly such that NPV(C, IRR) = 0, then we can just write an IRR function that finds the zeros of the NPV function. Here are two such functions: NPV - function(C, r) { sum(C / (1 + r) ^ (seq(along = C) - 1)) } IRR - function(C) { uniroot(NPV, c(0, 1), C =

Re: [R] Help with try or tryCatch

2005-10-31 Thread McGehee, Robert
It sounds like you want `try` with the argument `silent = TRUE`. This will allow you to keep running your program without errors. If you want to check if the line had an error, you can error control by seeing if the class of the resulting object is try-error. For example, let's say I wanted to

[R] cbind/rbind and NULL

2005-10-18 Thread McGehee, Robert
I'm trying to understand why I can rbind but not cbind dataframes to NULLs. For 'cbind' ('rbind'), vectors of zero length (including 'NULL') are ignored unless the result would have zero rows (columns), for S compatibility. (Zero-extent matrices do not occur in S3 and are

Re: [R] Counterintuitive Simulation Results

2005-08-04 Thread McGehee, Robert
Spencer, On the first iteration of your simulation, all of the Qp.t + z.t 0, so you're adding a vector of rep(4.5, 2) to a random distribution with mean -0.1. So one would expect on iteration 2, your mean would have dropped by about 0.1 (which it does). This process continues until about the

[R] Redirecting Messages and Errors to a file

2005-07-27 Thread McGehee, Robert
Hello all, I'm trying to setup a simple construct that will email me all errors, warnings, and output of a sample R script. My initial thought was to use sink() and tryCatch around the script such that at the end of the script any output would be mailed to me, i.e.: sinkFile - tempfile()

Re: [R] Redirecting Messages and Errors to a file

2005-07-27 Thread McGehee, Robert
/messages to the same file to preserve the order of the messages/output, if this is possible. Robert -Original Message- From: Thomas Lumley [mailto:[EMAIL PROTECTED] Sent: Wednesday, July 27, 2005 10:37 AM To: McGehee, Robert Cc: r-help@stat.math.ethz.ch Subject: Re: [R] Redirecting Messages

Re: [R] How to define S4 methods for '['

2005-06-20 Thread McGehee, Robert
setMethod([,foo,function(x,i, j, .,drop=TRUE)callGeneric([EMAIL PROTECTED],i,j,drop=drop) ) ^^^ You have a typo. Use ... instead of . (note ?[). Best, Robert Robert McGehee Quantitative Analyst Geode Capital Management, LLC 53 State Street, 5th Floor | Boston,

Re: [R] drop elements of vector by class

2005-06-17 Thread McGehee, Robert
a - data.frame(a = 1:2, b = c(a, b), c = I(c(a, b))) a - a[ , !sapply(a, class) %in% factor] -Original Message- From: E. Michael Foster [mailto:[EMAIL PROTECTED] Sent: Friday, June 17, 2005 10:58 AM To: r-help@stat.math.ethz.ch Subject: [R] drop elements of vector by class i'm trying

[R] Subassignments involving NAs in data frames

2005-06-09 Thread McGehee, Robert
I'm seeing some inconsistent behavior when re-assigning values in a data frame. The first assignment turns all of the 0s in my data frame to 2s, the second fails to do so. df1 - data.frame(a = c(NA, 0, 3, 4)) df2 - data.frame(a = c(NA, 0, 0, 4)) df1[df1 == 0] - 2 ## Works df2[df2 == 0] - 2

RE: [R] mvr function

2005-06-01 Thread McGehee, Robert
Jim, I had some of the same difficulties. The NIR data frame consists of a column of y variables and a matrix of X variables (and until looking at this dataset, I had not realized that data frames could hold matrices). So, after consulting the R-help sages, I turned by data into an identical

RE: [R] reason for na.last=TRUE in rank

2005-05-19 Thread McGehee, Robert
Because rank and order are (supposed to be) inverses of each other. For example: a - c(3, 1, NA) a[order(a[rank(a)])] [1] 3 1 NA a[rank(a[order(a)])] [1] 3 1 NA BUT a[order(a[rank(a, na.last = FALSE)])] [1] 1 NA 3 a[rank(a[order(a)], na.last = FALSE)] [1] 1 NA 3 -Original

RE: [R] applying a function over an array

2005-05-18 Thread McGehee, Robert
This will do it. a - array(1:12, c(4, 3)) d - function(a,b,c) {a+b+c} apply(a, 1, function(x) do.call(d, sapply(x, list))) [1] 15 18 21 24 -Original Message- From: BJ [mailto:[EMAIL PROTECTED] Sent: Wednesday, May 18, 2005 9:10 AM To: r-help@stat.math.ethz.ch Subject: [R] applying a

RE: [R] summary statistics for lists of matrices or dataframes

2005-05-10 Thread McGehee, Robert
You could try temporarily switching the list to an array, then just run an apply on rows and columns: apply(array(do.call(cbind, z), c(dim(z[[1]]), length(z))), c(1, 2), mean) Best, Robert -Original Message- From: David Kane [mailto:[EMAIL PROTECTED] Sent: Tuesday, May 10, 2005 10:04

[R] Data() and CSV files

2005-04-27 Thread McGehee, Robert
Hello, For reasons I don't understand, data() imports CSV (Comma-Separated Values) as if they were delimited by semicolons instead of commas. (Are semicolon-separated Comma-Separated-Value files common somewhere?) Given that this is the case, if I choose to put comma-delimited CSV files in my

[R] Strange data frame

2005-04-21 Thread McGehee, Robert
Hello, I'm playing around with the PLS package and found a data set (NIR) whose structure I don't understand. Forgive me if this is a stupid question, as I feel like it must be since I am less experienced with aspects of modeling. My problem, the pls NIR data frame does not seem to be a typical

RE: [R] A question about function behavior

2005-04-20 Thread McGehee, Robert
Sure. Here are three ways. Using pmax() is probably the most elegant. a - function(t) { pmax(t + 1, 0) } OR a - function(t) { sapply(t + 1, max, 0) } OR a - function(t) { t - t + 1 t[which(t 0)] - 0 t } -Original Message- From: Jorge Ahumada

RE: [R] How to change letters after space into capital letters

2005-04-12 Thread McGehee, Robert
This short function capitalizes the first letter of each word in a character string, which is what I think you want. capitalize - function(x) { x - strsplit(x, ) for (i in seq(along = x)) { substr(x[[i]], 1, 1) - toupper(substr(x[[i]], 1, 1)) } sapply(x, function(z)

RE: [R] Recall() and sapply()

2005-03-30 Thread McGehee, Robert
I doubt it's possible to use Recall inside a sapply like this. sapply (and lapply) make a copy of the function (FUN - match.fun(FUN)) before passing it inside an internal function (rval - .Internal(lapply(X, FUN)). So, while I'm not precisely sure how Recall is coded up, I bet that once it is

[R] Legend Line Size

2005-03-14 Thread McGehee, Robert
Hello all, When I view or print the below plot on my Linux machine under R 2.0.1 I see a nice thick solid and dashed line with a legend. However, while the lines are distinguishable, the legend is not. That is, the short (solid) line next to line1 and the short (dashed) line next to line2 seem to

RE: [R] function in order to plot the same graph to postscript and pdf

2005-03-09 Thread McGehee, Robert
Use substitute() instead of expression(); choose to use either MYPLOT or myplot because they are different variables; and use parentheses around your function arguments instead of braces. -Original Message- From: Ronny Klein [mailto:[EMAIL PROTECTED] Sent: Wednesday, March 09, 2005 12:22

RE: [R] how modify object in parent.env

2005-03-08 Thread McGehee, Robert
This isn't an environment problem. Assigning something to a get call doesn't make any sense. Use assign. a - 5 get(a) - 10 Error: couldn't find function get- And from the ?assign help page, you can pick what environment you want to make the assignment. Just pick the parent environment.

RE: [R] number formatting

2005-02-28 Thread McGehee, Robert
x - .001 x [1] 0.001 sub(+0, , x) [1] .001 Of course, that means you'll be storing this number as a character, but if you're looking to format how the number is printed, that's probably what you want. -Original Message- From: Laura Holt [mailto:[EMAIL PROTECTED] Sent: Monday,

RE: [R] string concatenation operator

2005-02-24 Thread McGehee, Robert
Not without extending character to another class. If you try to define this + method using S4, you get a proper error indicating that addition over characters is not allowed. setMethod(+, signature(character, character), function(e1,e2) paste(e1,e2, sep = )) Error in

RE: [R] help: how to get coefficients from the result

2005-02-24 Thread McGehee, Robert
?coef should do the trick. -Original Message- From: mingan [mailto:[EMAIL PROTECTED] Sent: Thursday, February 24, 2005 5:12 PM To: r-help@stat.math.ethz.ch Subject: [R] help: how to get coefficients from the result I am using timereg and Survreg packages below is the output, but

[R] Windows Printing and Line Widths

2005-02-08 Thread McGehee, Robert
Hi all, I develop and print from both Windows and Linux, and am seeing some printing inconsistencies first described about a year and a half ago by Andy Liaw (see below). Specifically, the line widths on my windows plots are about 5 times smaller than that on Linux, and my windows printouts do not

RE: [R] Evaluating code in a sandbox

2005-01-31 Thread McGehee, Robert
Why not just save your current global environment and reload it after running the offending code? See ?save.image to save, then rm(list = ls()) to clear the global environment. If a program tries to get or assign something to a global environment, then either you rewrite the program to do

RE: [R] Extracting a numeric prefix from a string

2005-01-31 Thread McGehee, Robert
Perhaps an easier way would be to throw away the offending text at the end of the strings, rather than matching all possible numeric formulations at the beginning of the string, that is: sub(\\.*[[:alpha:]]+$, , x) Easier to read, if nothing else, and it allows for 2e-7 as a valid number. This

[R] Indexing Lists and Partial Matching

2005-01-27 Thread McGehee, Robert
I was unaware until recently that partial matching was used to index data frames and lists. This is now causing a great deal of problems in my code as I sometimes index a list without knowing what elements it contains, expecting a NULL if the column does not exist. However, if partial matching is

RE: [R] Indexing Lists and Partial Matching

2005-01-27 Thread McGehee, Robert
. Thanks, Robert PS. None of this applies to partial matching of function arguments, as this is certainly widely used. -Original Message- From: Huntsinger, Reid [mailto:[EMAIL PROTECTED] Sent: Thursday, January 27, 2005 10:15 AM To: 'McGehee, Robert'; r-help@stat.math.ethz.ch Subject: RE: [R

RE: [R] how to use do.call(rbind, get(list(mlist)))

2005-01-21 Thread McGehee, Robert
get() doesn't take a list. You need to wrap it in an lapply so that it grabs the dataframes individually and then wraps it into a list for do.call(). The easy way, however, that doesn't involve do.call or get is to simply construct the proper text rbind query and then run it with eval.

RE: [R] Attach for S4 objects?

2005-01-18 Thread McGehee, Robert
Certainly this _is_ possible. However, there are no built-in functions to do just this (that I know of). Here's a function that attaches like you say (but still makes a local copy) attachslot - function(x) { xname - substitute(x) sl - names(getSlots(class(x))) slotnames - paste(sl,

RE: [R] signif() generic

2005-01-18 Thread McGehee, Robert
The method below looks for arguments of sec and numeric. Sounds like you want to pass in sec and missing (the class of missing data) and get a default behavior. So in addition to the method you already wrote, try this one as well: setMethod(signif, signature(x = sec, digits = missing),

[R] as.character methods

2005-01-13 Thread McGehee, Robert
Hello, ?as.character says that the as.character function is a generic with usage: as.character(x, ...). So, I want to create an S4 object with an as.character method following the above usage, but I get the below error telling me that ... isn't in the generic for as.character. setClass(tmp,

RE: [R] as.character methods

2005-01-13 Thread McGehee, Robert
the point entirely. Any clarification is greatly appreciated. Thanks, Robert -Original Message- From: Prof Brian Ripley [mailto:[EMAIL PROTECTED] Sent: Thursday, January 13, 2005 5:58 PM To: McGehee, Robert Cc: r-help@stat.math.ethz.ch Subject: Re: [R] as.character methods You seem

RE: [R] global objects not overwritten within function

2005-01-12 Thread McGehee, Robert
I would suggest reading the posting guide, (http://www.r-project.org/posting-guide.html) and give a reproducible example, with the error message that you received. As is, I have no idea what you are doing here, and certainly cannot run this code. You use ... as an argument to your functions (why I

RE: [R] Destructor for S4 objects?

2005-01-08 Thread McGehee, Robert
Adam, I'm about to encounter a very similar problem, so would be curious if you find a good solution, although your thoughts with reg.finalizer look promising. The thoughts I had sketched out for tackling this problem: 1) Have all ancillary resources freed when the package is detached. The new()

[R] Creating unary operators

2005-01-07 Thread McGehee, Robert
Is it correct (by its lack of mention in the R-Language Definition Manual) that it is impossible to create a user-defined unary operator? Ex: (This doesn't work, but it's an example of what I'm looking for) %PLUSONE% - function(x) x + 1 %PLUSONE% 2 [1] 3 And if the above is impossible, am I

RE: [R] Tuning string matching

2005-01-05 Thread McGehee, Robert
It sounds like what you want is a rudimentary spell-checker whose word is the input name, and whose dictionary is an array of your database names. Spell checking rules are designed to find missing repeats, transposed letters, extra letters... precisely the reasons you're not matching your names to

[R] Rcmd check Error help

2005-01-05 Thread McGehee, Robert
R-help, I'm the primary developer for an increasingly large R package with over three thousand lines of code. Unfortunately, do the complexity of the code, I sometimes am required to change several interoperating parts of the package before testing for bugs and performance. And sometimes unnoticed

[R] Modulus Problem

2004-12-08 Thread McGehee, Robert
R users, I am having a problem with the modulus operator for large numbers as follows, a - 2 n - 561 ## n is the first Carmichael number, so by Fermat's Little Theorem the below should equal zero. (a^(n-1) - 1) %% n [1] 2.193172e+152 ## Seems that R and Fermat disagree ## Also,