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
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
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
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:
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
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.
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:
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
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 ), '+') ]
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
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*
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([,
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 -
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,
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:
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
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
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,
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:
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
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
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
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
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
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:
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
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.
27 matches
Mail list logo