Patrick Burns wrote:
'The R Inferno' page 78 is one source you can
look at.
Patrick Burns
wow .. nice! .. thanks for posting this reference.
Esmail
__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read
Hello
I have a matrix of size rows x cols.
I also have a vector of size rows.
The vector contains index values that corresponds to rows in the matrix.
I would like to re-arrange/sort the contents of the matrix according
to the entries in the vector. Can this be done efficiently in R and
Hi David,
This was useful, thanks.
The example was just that, there are no as, b,s etc I was
just trying to show what I was trying to do.
Using m[v,]
where m was the matrix in my example and v the vector of
index values works great as you suggested Thanks.
R is quite a powerful language as
Doran, Harold wrote:
lm(y ~ x-1)
solve(crossprod(x), t(x))%*%y# probably this can be done more
efficiently
You could do
crossprod(x,y) instead of t(x))%*%y
that certainly looks more readable (and less error prone) to an R newbie
like myself :-)
Hi Kenn,
Thanks for the suggestions, I'll have to see if I can figure out how to
convert the relatively simple call to lm with an equation and the data file
to the functions you mention (or if that's even feasible).
Not an expert in statistics myself, I am mostly concentrating on the
Gabor Grothendieck wrote:
On Wed, Feb 18, 2009 at 7:27 AM, Esmail Bonakdarian esmail...@gmail.com wrote:
Gabor Grothendieck wrote:
See ?Rprof for profiling your R code.
If lm is the culprit, rewriting your lm calls using lm.fit might help.
Yes, based on my informal benchmarking, lm
Gabor Grothendieck wrote:
See ?Rprof for profiling your R code.
If lm is the culprit, rewriting your lm calls using lm.fit might help.
Yes, based on my informal benchmarking, lm is the main bottleneck, the rest
of the code consists mostly of vector manipulations and control structures.
I
Hello all,
I am just wondering if any of you are doing most of your scripting
with Python instead of R's programming language and then calling
the relevant R functions as needed?
And if so, what is your experience with this and what sort of
software/library do you use in combination with
Hello!
On Tue, Feb 17, 2009 at 5:58 PM, Warren Young war...@etr-usa.com wrote:
Esmail Bonakdarian wrote:
I am just wondering if any of you are doing most of your scripting
with Python instead of R's programming language and then calling
the relevant R functions as needed?
No, but if I
On Tue, Feb 17, 2009 at 6:05 PM, Barry Rowlingson
b.rowling...@lancaster.ac.uk wrote:
2009/2/17 Esmail Bonakdarian esmail...@gmail.com:
When I need to use the two together, it's easiest with 'rpy'. This
lets you call R functions from python, so you can do:
from rpy import r
r.hist(z
Hello all,
I need some help with a nice R-idiomatic and efficient solution to a
small problem.
Essentially, I am trying to eliminate randomly half of the entries in
a vector that contains index values into some other vectors.
More details:
I am working with two strings/vectors of 0s and 1s.
(sorry if this is a duplicate-problems with posting at my end)
Hello all,
I need some help with a nice R-idiomatic and efficient solution to a
small problem.
Essentially, I am trying to eliminate randomly half of the entries in
a vector that contains index values into some other vectors.
Gene Leynes wrote:
This is my first help post, hope it works!
Just check out the sample function
At the command line type:
?sample
I think it will be pretty clear from the documentation.
Yes, most excellent suggestion and quite helpful!
Thanks,
Esmail
Jim Porzak wrote:
The user of your R script sees only the outputs you create. The R source
is hidden.
Ah .. that sounds great .. I wish I had known about this a month ago!
I'll have to check it out - thanks!
Esmail
HTH,
Jim Porzak
..
Would the R script that is being run be hidden from
Spencer Graves wrote:
If you want to hide the fact that you are using R -- especially if
you charge people for your software that uses R clandestinely -- that's
a violation of the license (GPL).
No on both accounts .. but thanks for pointing this out none the less.
hadley wickham wrote:
2008/6/20 [EMAIL PROTECTED] [EMAIL PROTECTED]:
If you do nothing to your code, in 18 months time its performance will
have doubled because computers will have become faster. Your code
will not get easier to understand by itself.
Very nicely put .. and true too!
Paul Adams wrote:
Hello everyone,=I have a question as to how to remove the column headers
in a data file and then replace those with titles from another file in this case
the file labeled ann (
in which the titles are all in one column).
Maybe this will help partially.
I am not sure on
Hi,
I have matrix of bits and a target vector. Is there an
efficient way to search the rows of the matrix for the target?
I am interested in the first row index where target is found.
Example:
source(lookup.R)
[,1] [,2] [,3] [,4] [,5]
[1,]10110
[2,]110
Henrique Dallazuanna wrote:
Try this:
which(apply(t(m) == target, 2, all))
Wow! .. talk about concise! Neat! Thanks.
This will return all matches correct? So if I only wanted
the first I'd simply subscript [1] into it.
Do you think the fact that it searches the whole matrix instead
of
Dimitris Rizopoulos wrote:
try this:
match.pat - function (mat, target, nomatch = -1) {
f1 - do.call(paste, c(as.data.frame(mat), sep = \r))
f2 - paste(target, collapse = \r)
ind - f1 %in% f2
if (any(ind)) which(ind)[1] else nomatch
}
Thanks! More R for me to sink my teeth in :-)
# determine which data matches
matches - t(pop) == target # 't' due to matching in column order
# colSums equal to COLS will indicate matches
which(colSums(matches) == COLS)
Neat! .. somewhat similar to the solution I came up with in the
meantime, only yours works :-)
Thanks Jim.
Esmail
Hello, I have the following task I'd like to accomplish:
A file contains 5 columns of data (several hundred rows), let's call
them a, b, c, d and e (ie these are their column headers)
I also have a set of definitions, e.g.,
f = a + b
g = a * 3
h = c + d
etc.
I would like to write out a new
Hi Erik,
Erik Iverson wrote:
Esmail -
Are these 5 vectors of data stored in a data.frame? I assume so.
Yes, I do a simple load() call first to read the .rda file ...
test2 - transform(test, d = 2*a + b, e = 3*c)
save(test2, file = test2.Rdata)
Does this help?
Yes it does .. this is
jim holtman wrote:
yourDF - cbind(yourDF, f=yourDF$a+yourDF$b, g=yourDF$a * 3,
h=yourDF$c + yourDF$d)
Thanks Jim, I also learned about the transform() method from Erik
which will also work beautifully.
Esmail
__
R-help@r-project.org mailing list
steven wilson wrote:
I'm planning to install Linux on my computer to run R (I'm bored of
W..XP). However, I haven't used Linux before and I would appreciate,
if possible, suggestions/comments about what could be the best option
install,
Hi,
I have used Linux since the early 1990s starting
FWIW, those who are curious about Linux but are not willing
or ready to abandon the Windows platform can now very easily
try out Ubuntu without having to repartition their hard drive.
Wubi is a project that installs Ubuntu under Windows so that it
can be uninstalled easily and requires no
hadley wickham wrote:
Hi,
I tried this suggestion as I am curious about bottlenecks in my own
R code ...
Why not try profiling? The profr package provides an alternative
display that I find more helpful than the default tools:
install.packages(profr)
install.packages(profr)
Warning
Esmail Bonakdarian wrote:
hadley wickham wrote:
Hi,
I tried this suggestion as I am curious about bottlenecks in my own
R code ...
Why not try profiling? The profr package provides an alternative
display that I find more helpful than the default tools:
install.packages(profr
Tubin wrote:
In the past few weeks I have had to give myself a crash course in R, in order
to accomplish some necessary tasks for my job. During that time, I've found
this forum to be helpful time and time again - usually I find the answer to
my problem by searching the archives; once or twice
Bill Cunliffe wrote:
For example, based on a certain condition, I may want to exit my code early:
# Are there the same number of assets in prices and
positions?
if (nAssetPositions != nAssetPrices) {
cat(Different number of assets! \n\n)
Hi Duncan,
Duncan Murdoch wrote:
Duncan Murdoch wrote:
Esmail Bonakdarian wrote:
Hello all,
I have a matrix of bit values.
I compute certain values based on the bits in each row. There may be
*duplicate* entries in the matrix, ie several rows may be identical.
These rows change over time
Neil Shephard wrote:
Loops are not massively efficient within R.
Look into using the apply() family of functions
(eapply()/lapply()/mapply/rapply()/tapply()).
Didn't someone post not too long ago that apply is
internally represented as a for-loop? Or am I not
remembering this correctly?
The
Hello all,
I need to tap into the collective wisdom of the group re an issue of
efficiency.
A sketch of the situation:
Let's say 4000 observations in variables Y, X1, X2 , X3 and X4.
I would like to feed various combinations of this expression
Y ~ X1+X2+X3+X4 +
Edward Wijaya wrote:
Hi,
Currently the R script I have is executed with this command:
$ R CMD BATCH mycode.R
And the output is stored in mycode.Rout.
Is there a way I can issue command from shell (like above)
so that the output is printed to STDOUT?
It's troublesome to open the Rout file
Prof Brian Ripley wrote:
On Tue, 20 May 2008, Esmail Bonakdarian wrote:
Edward Wijaya wrote:
Hi,
Currently the R script I have is executed with this command:
$ R CMD BATCH mycode.R
And the output is stored in mycode.Rout.
Is there a way I can issue command from shell (like above)
so
Anh Tran wrote:
Hi,
What's one way to convert an integer to a string with preceding 0's?
such that
'13' becomes '013'
to be put into a string
I've tried formatC, but they removes all the zeros and replace it with
blanks
Hi,
try sprintf:
i=13
cat(sprintf(%05d\n, i))
00013
HTH,
Tony Plate wrote:
You probably should check this section in your R-help subscription
options (via https://stat.ethz.ch/mailman/options/r-help/, I think):
Receive your own posts to the list?
Tony,
Like jt I too have it set to receive my own messages, but I too
don't see them. I wonder if
Charilaos Skiadas wrote:
On May 13, 2008, at 5:52 AM, Esmail Bonakdarian wrote:
Tony Plate wrote:
You probably should check this section in your R-help subscription
options (via https://stat.ethz.ch/mailman/options/r-help/, I think):
Receive your own posts to the list?
Tony,
Like jt I
Greg Snow wrote:
-Original Message-
From: [EMAIL PROTECTED]
[mailto:[EMAIL PROTECTED] On Behalf Of Esmail Bonakdarian
Sent: Sunday, May 11, 2008 7:25 AM
To: Prof Brian Ripley
Cc: [EMAIL PROTECTED]
Subject: Re: [R] Random number generation
[snip]
What I read doesn't seem
Wensui Liu wrote:
Hi, dear all,
I just switch to vista (ultimate) and have heard there is some problem
for the installation of xemacs on vista. Is there any insight or
experience that you could share? I really appreciate any input.
thank you so much!
Hi,
I don't know about XEmacs, but I am
Stephan Kolassa wrote:
Have you tried successively removing/commenting parts of the script
before the sample() command until the problem goes away? That way you
should be able to pinpoint the offending script command.
Hi,
This brings up a question I have .. is there a way to do *block*
Hello there,
Prof Brian Ripley wrote:
On Sun, 11 May 2008, Esmail Bonakdarian wrote:
Stephan Kolassa wrote:
Have you tried successively removing/commenting parts of the script
before the sample() command until the problem goes away? That way you
should be able to pinpoint the offending
Hello,
which.max() only returns one index value, the one for the
maximum value. If I want the two index values for the two
largest values, is this a decent solution, or is there a
nicer/better R'ish way?
max2 -function(v)
{
m=which.max(v)
v[m] = -v[m]
m2=which.max(v)
result=c(m,
Dimitris Rizopoulos wrote:
try this:
v - rnorm(10)
v
order(v, decreasing = TRUE)[1:2]
Wow .. that is slick! First I thought, wait .. I don't want to
reorder the elements, but this doesn't - it just returns the index
values in order. I don't really get that from reading the documentation,
it's
Marc Schwartz wrote:
I might be tempted to take a more generic approach, where one can
provide an argument to the function to indicate that I want the 'top x'
maximum values and to give the user the option of returning the indices
or the values themselves.
Perhaps:
which.max2 - function(x,
Hello,
Still a newbie with R, though I have learned a lot from reading
this list. I'm hoping someone can help with this question:
I have two vectors, one for variables, and one for bits.
I want to build a string (really a formula) based on the values in my
vector of 1s and 0s in bits. If I
Jorge Ivan Velez wrote:
Hi Esmail,
Try this:
vars=c('X.1', 'X.2', 'X.3', 'X.4', 'X.5')
bits=c(1, 0, 1, 1, 0)
paste(vars[which(bits==1)],collapse=+)
HTH,
Jorge
Wow .. that is beautiful :-) .. and exactly what I was looking
for (and suspected existed).
I ended up doing this:
Once again I need to tap into the collective knowledge here.
Let's say I have the following columns and data below
Y X1 X2 X3 X4
I would like to generate additional new columns and column names
(ie the data would be squared - and I'd like the column names to
reflect this) like:
Y X1 X2 X3 X4
This has been an interesting discussion, and brings up two questions
for me:
Is there a good collection of hints/suggestions for R language idoms in terms
of efficiency? For instance I read not to use for-loops, so I used apply only to
later read that apply is internally implemented as a for so
See ?Rprof for the tool. For the tips, I think you just need to hang
around here a while. I don't know of a nice collection (but I'm sure
there are several.)
Duncan Murdoch
Hi,
thanks .. several folks pointed me to Rprof, I'll take a look.
Yes, I have been reading the list, the
I realize the R developers are probably overwhelmed and have little time
for this, but the documentation really needs some serious reorganizaton.
A good through description of basic variable types would help a lot,
e.g. the difference between lists, arrays, matrices and frames.
Agreed,
Thank you Rob, I just downloaded it and it looks very useful.
In the meantime I think I solved my immediate problem (and while
pluggin' away also deepened my understanding - or so I will at least
claim :-)
Esmail
I don't know if you will find this helpful, but one of the better online
Hello all,
I am trying to implement a simple Genetic Algorithm. I am doing this
in R since I want access to the statistical functions (eg lm) it
provides.
I'm not new to programming, or GAs, but I am totally new to R (the
package and the language), and I am hoping someone could help with
these
Hello!
Dear Esmail,
you really have to have a look at some introduction to R (e.g.
http://cran.r-project.org/doc/manuals/R-intro.pdf), but see the Manual
section in R website (http://www.r-project.org/). That would answer many
of your questions.
point well taken, I am a bit in a
54 matches
Mail list logo