Hi,
I still have little ability to predict how these functions will treat the
columns of data frames:
# Here's a data frame with a column a of integers,
# and a column b of characters:
df - data.frame(
+ a = 1:2,
+ b = c(a,b)
+ )
df
a b
1 1 a
2 2 b
# Except -- both columns
If you're willing to assume independence, multiplication is the way to go:
Pr( a beats b a beats c) = Pr( a beats b ) * Pr( a beats c )
If you're not willing to assume independence, things can get very weird:
http://en.wikipedia.org/wiki/Arrow's_impossibility_theorem
--
View this message in
One option might be to turn the sequence into a character string, and then
use something like grep(). Kind of a kludge, but possibly easy.
--
View this message in context:
http://n4.nabble.com/Count-matches-of-a-sequence-in-a-vector-tp2019018p2019161.html
Sent from the R help mailing list
Phil's algorithm is a good one, unless you're worried about optimizing for
speed. It makes N * M comparisons, where N is the length of the first
vector and M is the length of the second. Explicitly iterating through the
longer vector, you could reduce the number of comparisons to M. As is
This sort of calculation can't be vectorized; you'll have to iterate through
the sequence, e.g. with a for loop. I don't know if a routine has already
been written.
--
View this message in context:
http://n4.nabble.com/Count-matches-of-a-sequence-in-a-vector-tp2019018p2019108.html
Sent from
Thanks a lot, David and Dennis! Also, your suggestions for how I could have
better stated my question are duly noted, and appreciated.
--
View this message in context:
http://n4.nabble.com/xtabs-of-proportions-and-naming-a-dimension-not-a-row-tp2015261p2015380.html
Sent from the R help mailing
http://cran.r-project.org/doc/FAQ/R-FAQ.html#How-do-I-convert-factors-to-numeric_003f
--
View this message in context:
http://n4.nabble.com/dataframe-tp2015650p2016230.html
Sent from the R help mailing list archive at Nabble.com.
__
Hi,
xtabs() creates a table of counts. I want a table of proportions -- that
is, I want to divide every vector (along a particular dimension) by its sum.
The tiny example below does that. The call to xtabs() creates a matrix A
with dimensions (x1,x2,y). I transform A using aperm() and
Wow, those are cool functions! Â Thanks!
--- On Sat, 4/10/10, Henrique Dallazuanna [via R]
ml-node+1835454-939980203-179...@n4.nabble.com wrote:
From: Henrique Dallazuanna [via R]
ml-node+1835454-939980203-179...@n4.nabble.com
Subject: Re: str: how to use no list recursively?
To: Jeff Brown
Hi,
In the help file for str(), the following line appears: no.list
logical;
if true, no ‘list of ...’ nor the class are printed. However, that appears
to be true only on the top level; setting no.list to TRUE still leaves the
remaining levels with the `list of ...' statement intact:
Thanks, Bill! That was deep, and took me a long time to work through, but I
get it now.
And Gabor -- r-proto is great!
--
View this message in context:
http://n4.nabble.com/Scope-and-assignment-baffling-tp1747582p1753321.html
Sent from the R help mailing list archive at Nabble.com.
Hi,
If you want to export a single bar chart, this works:
png( ET );
barchart( data[,ET] )
dev.off()
quartz_off_screen
2
But if you want to export a few of them, this does not:
factorCols - c(MR,ET);
sapply( factorCols, function(x) {
+ png( x );
+ barchart(
You were right. Jorge Velez wrote me off-list and pointed out that I need to
call print() to write the barplot to the device, just as explained in the
FAQ.
Thanks!
--
View this message in context:
http://n4.nabble.com/Export-bug-Hist-vs-barchart-tp1750593p1750672.html
Sent from the R help
Ah, I finally figured it out: I had asked
In both of those cases, why is the [] needed?
It's because when on the left hand side of an assignment, the bracket
operator attempts to preserve the class and dimension of the object it's
subsetting. (Or at least, that's true when the object is a
Hi,
The code below creates a value, x$a, which depending on how you access it
evaluates to its initial value, or to what it's been changed to. The last
two lines should, I would have thought, evaluate to the same value, but they
don't.
f - function () {
x - NULL;
x$a - 0;
Wow, those are much more elegant. Thanks!
Peter suggests:
df[] - lapply(df, factor, levels=allLevels, labels=seq_along(allLevels))
Henrique suggests:
df[] - as.numeric(unlist(df))
In both of those cases, why is the [] needed? When I evaluate df vs. df[],
they both look the same, but
Hi,
I've got a data frame with multiple factor columns, but they should share
the same set of labels, such as this tiny example:
df - data.frame (
a = factor( c( bob, alice, bob ) ),
b = factor( c( kenny, alice, alice ) )
);
In my data, though, the strings are enormous. I
Sorry for spamming. I swear I had worked on that problem a long time before
posting.
But I just figured it out: I have to change the values, which are
represented as integers, not strings. So the following code will do it:
df - data.frame (
a = factor( c( bob, alice, bob ) ),
What is the function set()? Is that a typo? When I type ?set I get
nothing, and when I try to evaluate that code R tells me it can't find the
function.
--
View this message in context:
http://n4.nabble.com/tapply-syntax-tp1692503p1694586.html
Sent from the R help mailing list archive at
When I tried ??tree, I found something called dendrogram that looks like it
might be what you want.
--
View this message in context:
http://n4.nabble.com/Heirarchical-tree-data-structure-tp1692838p1694575.html
Sent from the R help mailing list archive at Nabble.com.
Hi,
I would expect the following:
paste(
as.character( cat( rep( ., 2 ) ) ),
a string,
as.character( cat( rep( ., 3 ) ) )
);
to yield this string: . . a string . . ., but instead it yields this:
. .. . .[1] a string
The third argument has been stuck immediately
Wow, you guys are awesome. Thanks!
--
View this message in context:
http://n4.nabble.com/c-or-cat-or-paste-all-cause-unwanted-reordering-tp1691133p1691198.html
Sent from the R help mailing list archive at Nabble.com.
__
R-help@r-project.org mailing
I just had to solve this problem for myself, after not having luck with the
code posted above. I'm posting in case others need a completely general
function.
riffle - function (a,b) {
# Interleave a b, starting with a, without repeating.
x - NULL; count = 1;
23 matches
Mail list logo