Displaying 20 results from an estimated 95 matches for "macrakis".
2008 Nov 29
2
Using grep() to subset lines of text
I have two vectors, a and b. b is a text file. I want to find in b those
elements of a which occur at the beginning of the line in b. I have the
following code, but it only returns a value for the first value in a, but I
want both. Any ideas please.
a = c(2,3)
b = NULL
b[1] = "aaa 2 aaa"
b[2] = "2 aaa"
b[3] = "3 aaa"
b[4] = "aaa 3 aaa"
2009 Feb 17
2
cumsum vs. sum
I recently traced a bug of mine to the fact that cumsum(s)[length(s)]
is not always exactly equal to sum(s).
For example,
x<-1/(12:14)
sum(x) - cumsum(x)[3] => 2.8e-17
Floating-point addition is of course not exact, and in particular is
not associative, so there are various possible reasons for this.
Perhaps sum uses clever summing tricks to get more accurate results?
In some
2009 May 20
2
Class for time of day?
What is the recommended class for time of day (independent of calendar
date)?
And what is the recommended way to get the time of day from a POSIXct
object? (Not a string representation, but a computable representation.)
I have looked in the man page for DateTimeClasses, in the Time Series
Analysis Task View and in Spector's Data Manipulation book but haven't found
these. Clearly I can
2009 Feb 22
4
'unique' error message is printed despite silent=TRUE (PR#13547)
In 2.8.0/Windows Vista:
When 'unique' gives a type error message, it prints out even if errors
are being caught:
> try(unique(quote(hello)),silent=TRUE)
hello
This comes from the .Internal unique routine:
> try(.Internal(unique(quote(hello),NULL,NULL)),silent=TRUE)
hello
I guess it is using the internal equivalent of print rather than the
internal equivalent of stop.
2009 Feb 10
1
Variable/function namespaces WAS: Bug in subsetting data frame (PR#13515)
On Tue, Feb 10, 2009 at 10:11 AM, Duncan Murdoch <murdoch at stats.uwo.ca> wrote:
> Stavros Macrakis wrote:
>> On Tue, Feb 10, 2009 at 8:31 AM, Duncan Murdoch <murdoch at stats.uwo.ca>wrote:
>>> The evaluator recognizes the context of usage and will get the
>>> function for a function call....
>> Can you point me to chapter and verse in the language definition.....
2009 Jun 26
3
Automatically placing a legend in an area with the most white space...
At one point I believe I heard of an R package that would automatically find the most empty space in a plot, and then that answer could then be used to intelligently place a legend.
I would like to try to apply that R package to the contrived example shown below, so thank you for any hints or tips that can be provided.
x = seq(0, 1000, by = 1)
y1_vals<-rnorm(1000, mean = 0, sd = 50)
2009 Dec 18
2
Vectorized switch
What is the 'idiomatic' way of writing a vectorized switch statement?
That is, I would like to write, e.g.,
vswitch( c('a','x','b','a'),
a= 1:4,
b=11:14,
100 )
=> c(1, 100, 13, 4 )
equivalent to
ifelse( c('a','x','b','a') ==
2011 Oct 19
2
Speed difference between df$a[1] and df[1,"a"]
I was surprised to find that df$a[1] is an order of magnitude faster than
df[1,"a"]:
> df <- data.frame(a=1:10)
> system.time(replicate(100000, df$a[3]))
user system elapsed
0.36 0.00 0.36
> system.time(replicate(100000, df[3,"a"]))
user system elapsed
4.09 0.00 4.09
A priori, I'd have thought that combining the row and column
2009 Mar 09
3
E`<`<rrors in recursive default argument references
Tested in: R version 2.8.1 (2008-12-22) / Windows
Recursive default argument references normally give nice clear errors.
In the first set of examples, you get the error:
Error in ... :
promise already under evaluation: recursive default argument
reference or earlier problems?
(function(a = a) a ) ()
(function(a = a) c(a) ) ()
(function(a = a) a[1] ) ()
(function(a = a)
2011 Apr 04
2
General binary search?
Is there a generic binary search routine in a standard library which
a) works for character vectors
b) runs in O(log(N)) time?
I'm aware of findInterval(x,vec), but it is restricted to numeric vectors.
I'm also aware of various hashing solutions (e.g. new.env(hash=TRUE) and
fastmatch), but I need the greatest-lower-bound match in my application.
findInterval is also slow for
2009 Jul 29
3
Object equality for S4 objects
To test two environments for object equality (Lisp EQ), I can use 'identity':
> e1 <- environment(local(function()x))
> e2 <- environment(local(function()x))
> identical(e1,e2) # compares object identity
[1] FALSE
> identical(as.list(e1),as.list(e2)) # compares values as name->value mapping
[1] TRUE # (is there a
2009 Jan 08
1
R and Excel
...t.
The R GUI series like Rattle come even closer to Excel...so a VBA
_R_ExCel package might be useful to ordinary folks .
Besides Excel costs money, so adding R functions to Open Office would
help both of them ( if not attempted already)
Regards,
Ajay
www.decisionstats.com
On 1/8/09, Stavros Macrakis <macrakis at alum.mit.edu> wrote:
>>
>> "Some people familiar with R describe it as a supercharged version of
>> Microsoft's Excel spreadsheet software..."
>>
>
> It is easy to ridicule this line from the NYT article. But this is not only
> a ve...
2009 Feb 08
3
Best 64-bit Linux distro for R?
The R FAQ is very helpful about installing R on various Linuxes, but doesn't
seem to discuss the advantages of one distribution over another. I am new
to Linux (though not to Unix!), and would appreciate some guidance from
those with experience.
I plan to set up a headless Linux x86 server for the sole purpose of running
64-bit R. Are there reasons to prefer some Linux distributions over
2009 Sep 02
2
Documentation for is.atomic and is.recursive
The documentation for is.atomic and is.recursive is inconsistent with
their behavior in R 2.9.1 Windows.
? is.atomic
???? 'is.atomic' returns 'TRUE' if 'x' is an atomic vector (or 'NULL')
???? and 'FALSE' otherwise.
???? ...
???? 'is.atomic' is true for the atomic vector types ('"logical"',
???? '"integer"',
2008 Dec 08
4
R and Scheme
I've read in many places that R semantics are based on Scheme semantics. As
a long-time Lisp user and implementor, I've tried to make this more precise,
and this is what I've found so far. I've excluded trivial things that
aren't basic semantic issues: support for arbitrary-precision integers;
subscripting; general style; etc. I would appreciate corrections or
additions from
2010 Dec 10
1
Stricter read.table?
read.table gives idiosyncratic results when the input is formatted
strangely, for example:
read.table(textConnection("a'b\nc'd\n"),header=FALSE,fill=TRUE,sep="",quote="'")
=> "c'd" "a'b" "c'd"
2009 Apr 20
2
The assign(paste(...,i),...) idiom
Judging from the traffic on this mailing list, a lot of R beginners
are trying to write things like
assign( paste( "myvar", i), ...)
where they really should probably be writing
myvar[i] <- ...
Do we have any idea where this bizarre habit comes from?
-s
2009 May 18
1
Generic 'diff'
I would like to apply a function 'f' to the lagged version of a vector and
the vector itself.
This is easy to do explicitly:
mapply( f, v[-1], v[-length(v)] )
or in the case of a pointwise vector function, simply
f( v[-1], v[-length(v)] )
This is essentially the same as 'diff' but with an arbitrary function, not
'-'.
Is there a standard way to do this? Is
2011 Jun 13
1
Composing two n-dimensional arrays into one n+1-dimensional array
If I have 2 n-dimensional arrays, how do I compose them into a n+1-dimension
array?
Is there a standard R function that's something like the following, but that
gives clean errors, handles all the edge cases, etc.
abind <- function(a,b) structure( c(a,b), dim = c(dim(a), 2) )
m1 <- array(1:6,c(2,3))
m2 <- m1 + 10
abind(m1,m2)
==>
, , 1
[,1] [,2] [,3]
[1,] 1 3 5
2011 Jul 28
1
Reading name-value data
I have a file of data where each line is a series of name-value pairs, but
where the names are not necessarily the same from line to line, e.g.
a=1,b=2,d=5
b=4,c=3,e=3
a=5,d=1
I would like to create a data frame which lines up the data in the
corresponding columns. In this case, this would be
data.frame( a = (1, NA, 4), b = (2, 4, NA), c = (NA, 3, NA), d = (5, NA,
1), e = (NA, 3,