Re: [R] quickest way convert 1-col df to vector?

2010-03-08 Thread Steve Jaffe
D'oh -- thanks! I'm always forgetting the double-bracket extractor... -Original Message- From: Erik Iverson [mailto:er...@ccbr.umn.edu] Sent: Monday, March 08, 2010 10:50 AM To: Steve Jaffe Cc: r-help@r-project.org Subject: Re: [R] quickest way convert 1-col df to vector? sjaffe wrote

Re: [R] tapply for function taking of 1 argument?

2010-02-03 Thread Steve Jaffe
Yes, this is clearly the key to working with subsets. Thanks -Original Message- From: Petr PIKAL [mailto:petr.pi...@precheza.cz] Sent: Wednesday, February 03, 2010 4:16 AM To: Steve Jaffe Cc: r-help@r-project.org Subject: Re: [R] tapply for function taking of 1 argument? Hi r-help-boun

Re: [R] tapply for function taking of 1 argument?

2010-02-02 Thread Steve Jaffe
Excellent! I knew there would be a clever answer using 'do.call' :-) -Original Message- From: Charles C. Berry [mailto:cbe...@tajo.ucsd.edu] Sent: Tuesday, February 02, 2010 4:25 PM To: Steve Jaffe Cc: r-help@r-project.org Subject: Re: [R] tapply for function taking of 1 argument

[R] dyn.load search path?

2009-09-17 Thread Steve Jaffe
Sorry if this is somewhere in the fine manuals but I've been unable to locate it. Does dyn.load use a search path or does it just look in the current directory for non-fully-qualified filenames? If there is a search path, what is it? Thanks for your help -- View this message in context:

Re: [R] Several simple but hard tasks to do with R

2009-08-20 Thread Steve Jaffe
For history of both commands and output, consider running R inside emacs using the ESS package and simply saving the buffer to a file. If you save the session as an S transcript file (extension .St) it is also easy to reload and re-execute any part of it. Emacs or xemacs is available on most

Re: [R] Is there a construct for conditional comment?

2009-08-20 Thread Steve Jaffe
Why not if ( 0 ) { commented with zero } else { commented with one } Greg Snow-2 wrote: I believe that #if lines for C++ programs is handled by the preprocessor, not the compiler. So if you want the same functionality for R programs, it would make sense to just preprocess the R file.

[R] why is 0 not an integer?

2009-08-05 Thread Steve Jaffe
Why when I assign 0 to an element of an integer vector does the type change to numeric? Here is a particularly perplexing example: v - 0:10 v [1] 0 1 2 3 4 5 6 7 8 9 10 class(v) [1] integer v[1] - 0 class(v) [1] numeric #!! -- View this message in context:

[R] array slice notation?

2009-08-04 Thread Steve Jaffe
Suppose I have an n-diml array A and I want to extract the first row -- ie all elements A[1, ...] Interactively if I know 'n' I can write A[1,] with (n-1) commas. How do I do the same more generally, eg in a script? (I can think of doing this by converting A to a vector then extracting

Re: [R] array slice notation?

2009-08-04 Thread Steve Jaffe
Yes, I was thinking more in terms of mental operations than physical. I think the following works, but it doesn't seem entirely transparent :-) Given array A, and a vector of row indices v (ie 1 = v = dim(A)[1]), the slice of rows v is A[ outer(v, dim(A)[1]*( 1:prod(dim(A)[-1])-1 ), '+') ]

Re: [R] array slice notation?

2009-08-04 Thread Steve Jaffe
Although you *do* have to re-assign the dimensions, otherwise the result is just a flat vector, ie slice - A[ outer(v, dim(A)[1]*( 1:prod(dim(A)[-1])-1 ), '+') ] dim(slice) - dim(A)[-1] Steve Jaffe wrote: A[ outer(v, dim(A)[1]*( 1:prod(dim(A)[-1])-1 ), '+') ] -- View this message

Re: [R] array slice notation?

2009-08-04 Thread Steve Jaffe
correction -- that would work for a single row, if you want the result to be an array with one fewer dimensions. But in general you get an array of the same dimension you started with (where the first dimension may be length 1). So: dim(slice) - c(length(v), dim(arr)[-1]) Although you *do*

Re: [R] array slice notation?

2009-08-04 Thread Steve Jaffe
Very nice. Two questions: 1 Do you have any idea of the timing difference, if any, between this and the vector-subscripting method? 2 How do you generalize this to select multiple rows eg with indexes given by a vector 'v'? Søren Højsgaard wrote: You can do A - HairEyeColor do.call([,

[R] write matrix M including names(dimnames(M))

2009-07-30 Thread Steve Jaffe
I can do this by writing (and reading) the file according to some format of my own devising, but I'm wondering if there is a built-in way to write and then restore a matrix with not only the dimnames (which write.table/read.table can preserve) but also the names(dimnames)? Example: M -

[R] problem aligning barplot and scatter plot (ala 'layout' example)

2009-07-10 Thread Steve Jaffe
I'm trying just to do the x-barplot + scatterplot from the layout example. The barplot does not come out aligned horizontally with the scatter plot, although I am passing in the same xlim to both. When I run the example it comes out correctly. I haven't figured out what I'm doing differently,

[R] print() to file?

2009-07-08 Thread Steve Jaffe
I'd like to write some objects (eg arrays) to a log file. cat() flattens them out. I'd like them formatted as in 'print' but print only writes to stdout. Is there a simple way to achieve this result? Thanks -- View this message in context:

[R] vectorizing a function

2009-07-07 Thread Steve Jaffe
I'm sure I'm missing something obvious but I'm not seeing how to simply vectorize a function of two or more variables. Say I have f - function(x,y) if (x0) y else -y Now I have vectors x and y of equal length and I'd like to apply f element-wise. I.e. conceptually z - f(x,y) where x, y, z are

Re: [R] vectorizing a function (NEVERMIND)

2009-07-07 Thread Steve Jaffe
Nevermind, indeed it is obvious: Vectorize ! Steve Jaffe wrote: I'm sure I'm missing something obvious but I'm not seeing how to simply vectorize a function of two or more variables. -- View this message in context: http://www.nabble.com/vectorizing-a-function-tp24380064p24380136.html

[R] sorting question

2009-07-01 Thread Steve Jaffe
I've asked about custom sorting before and it appears that -- in terms of a user-defined order -- it can only be done either by defining a custom class or using various tricks with order Just wondering if anyone has a clever way to order vintages of the form 2002, 2003H1, 2003H2, 2004, 2005Q1,

[R] X-window graphics -- preventing window coming to front?

2009-06-23 Thread Steve Jaffe
When I do dev.new(), the resulting window comes to the front and grabs the focus. Is there a way to prevent this so I can continue working in other windows while the graphics are being produced? Thanks -- View this message in context:

[R] searching help for partial matches

2009-06-17 Thread Steve Jaffe
The situation is that I know there is a function and know approximately what the name is, and want to find the exact name. Is there a way of searching for near-matches (similar to unix apropos). For example, I know there is a function called something like allequal (or allequals or AllEquals

Re: [R] searching help for partial matches

2009-06-17 Thread Steve Jaffe
help.search -- excellent I'm a bit confused though -- doc seems to say that ??pattern is same as help.search(pattern) but it doesn't work that way for me...I'd been trying ?? for some time without success. For example, ??allequal #returns No documentation for '?allequal' in specified packages

[R] list of data.frames?

2009-06-17 Thread Steve Jaffe
I'm trying to build up a list of data.frames by appending one by one. If x,y,z are data.frames, I can do somelist - list(x, y, z) (or even somelist - list(x=x, y=y, z=z) to get names) But if I start with somelist - list(x,y) and now want to go from this to list(x,y,z) I'm stuck. I've tried

[R] how to tell if as.numeric succeeds?

2009-06-04 Thread Steve Jaffe
Suppose I have a vector of strings. I'd like to convert this to a vector of numbers if possible. How can I tell if it is possible? as.numeric() will issue a warning if it fails. Do I need to trap this warning? If so, how? In other words, my end goal is a function that takes a vector of strings

[R] logical indexing multidimensional arrays

2009-06-04 Thread Steve Jaffe
Suppose I have an n-dimensional array and a logical vector as long as the first dimension. I can extract an n-dimensional subarray with a[ i, , , , .. ,] where there are n-1 commas (ie empty indices) Is there an alternative notation that would better lend itself to more generic use, e.g. to

[R] custom sort?

2009-05-28 Thread Steve Jaffe
Sounds simple but haven't been able to find it in docs: is it possible to sort a vector using a user-defined comparison function? Seems it must be, but sort doesn't seem to provide that option, nor does order sfaics -- View this message in context:

Re: [R] custom sort?

2009-05-28 Thread Steve Jaffe
hmm, that is what I was afraid of. I considered that but thought to myself, surely there must be an easier way. I wonder why this feature isn't available. It's there in scripting languages, like perl, but also in hardcore languages like C++ where std::sort and sorted containers allow the user to

[R] Cox Proportional Odds Model

2009-05-04 Thread Steve Jaffe
Is there a function, like coxph for the proportional hazard model, for fitting a discrete-time proportional odds model? -- View this message in context: http://www.nabble.com/Cox-Proportional-Odds-Model-tp23373426p23373426.html Sent from the R help mailing list archive at Nabble.com.