[R] xmlToDataFrame very slow

2013-07-30 Thread Stavros Macrakis
I have a modest-size XML file (52MB) in a format suited to xmlToDataFrame (package XML). I have successfully read it into R by splitting the file 10 ways then running xmlToDataFrame on each part, then rbind.fill (package plyr) on the result. This takes about 530 s total, and results in a data.fram

Re: [R] execute array of functions

2012-02-14 Thread Stavros Macrakis
That won't work because R has special rules for evaluating things in the function position. Examples: *OK* min(1:2) "min"(1:2) f<-min; f(1:2) do.call(min,list(1:2)) do.call("min",list(1:2)) # do.call converts string->function *Not OK* ("min")(1:2) # string in function positi

Re: [R] R development master class: NYC, Dec 12-13

2011-11-15 Thread Stavros Macrakis
> Last time, I was told that I couldn't list my R package and associated papers as a research activity with > substantial impact because it was outside my official scope of work. (Even though I wrote it so I could > *do* my work.) That seems wrong. My impression is that "method" papers were frequ

[R] Kleinberg's burst detection algorithm

2011-10-21 Thread Stavros Macrakis
Has anyone here implemented Jon Kleinberg's burst detection algorithm ("Bursty and Hierarchical Structure in Streams" http://www.cs.cornell.edu/home/kleinber/bhs.pdf)? I'd rather not reimplement if there's already running code available Thanks, -s [[alternative HTML vers

Re: [R] Reading name-value data

2011-07-29 Thread Stavros Macrakis
ote: > Use plyr::rbind.fill? That does match up columns by name. > Hadley > > On Thu, Jul 28, 2011 at 5:23 PM, Stavros Macrakis > wrote: > > 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 f

[R] Reading name-value data

2011-07-28 Thread Stavros Macrakis
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 wo

[R] Composing two n-dimensional arrays into one n+1-dimensional array

2011-06-13 Thread Stavros Macrakis
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(

[R] Approximate name matching

2011-05-09 Thread Stavros Macrakis
Is there R software available for doing approximate matching of personal names? I have data about the same people produced by different organizations and the only matching key I have is the name. I know that commercial solutions exist, and I know I code code this from scratch, but I'd prefer to bu

Re: [R] General binary search?

2011-04-06 Thread Stavros Macrakis
-s On Wed, Apr 6, 2011 at 12:59, Martin Morgan wrote: > On 04/04/2011 01:50 PM, William Dunlap wrote: > >> -Original Message- >>> From: r-help-boun...@r-project.org >>> [mailto:r-help-boun...@r-project.org] On Behalf Of Stavros Macrakis >

[R] General binary search?

2011-04-04 Thread Stavros Macrakis
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

[R] Quantile with discrete types

2010-12-10 Thread Stavros Macrakis
I don't understand why 'quantile' works in this case: > tt <- rep(c('a','b'),c(10,3)) > sapply(0:6/6,function(q) quantile(tt,probs=q,type=1)) 0% 16.7% 33.3% 50% 66.7% 83.3% 100% "a" "a" "a" "a" "a" "b" "b" and also > qua

[R] Stricter read.table?

2010-12-10 Thread Stavros Macrakis
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" read.table(textConnection("a'b\nc'd\nf'\n'\n"),header=FALSE,fill=TRUE,sep="",quote="'") => "f'" "\n

Re: [R] solving cubic/quartic equations non-iteratively

2010-01-22 Thread Stavros Macrakis
On Tue, Jan 5, 2010 at 5:25 PM, Carl Witthoft wrote: > quote: > > There are certainly formulas for solving polynomials numerically up to > 4th degree non-iteratively, but you will almost certainly get better results > using iterative methods. > > I must be missing something here. Why not use t

Re: [R] solving cubic/quartic equations non-iteratively

2010-01-05 Thread Stavros Macrakis
There are certainly formulas for solving polynomials numerically up to 4th degree non-iteratively, but you will almost certainly get better results using iterative methods. Even the much more trivial formula for the 2nd degree (quadratic) is tricky to implement correctly and accurately, see: * Ge

Re: [R] Problem with expand.grid

2009-12-22 Thread Stavros Macrakis
Unfortunately, expand.grid doesn't validate the class of its argument, so it is reporting an internal error rather than something more intelligible. On Tue, Dec 22, 2009 at 11:19 AM, Keith Jewell wrote: > Just confirming it isn't the bug fixed in 2.11.0dev, and giving an even > simpler example: >

[R] Method dispatch for function

2009-11-18 Thread Stavros Macrakis
How can I determine what S3 method will be called for a particular first-argument class? I was imagining something like functionDispatch('str','numeric') => utils:::str.default , but I can't find anything like this. For that matter, I was wondering if anyone had written a version of `methods` whi

Re: [R] Suppressing final spaces in data.frame printouts

2009-11-11 Thread Stavros Macrakis
solved the problem in R or ESS -s On Wed, Nov 11, 2009 at 8:43 PM, RICHARD M. HEIBERGER wrote: > On Wed, Nov 11, 2009 at 8:12 PM, Stavros Macrakis > wrote: > > Thanks for the suggestion. I'mm familiar with the truncate-lines > variable, > > but that'

Re: [R] Suppressing final spaces in data.frame printouts

2009-11-11 Thread Stavros Macrakis
:40 PM, Richard M. Heiberger wrote: > Stavros Macrakis wrote: > >> I could of course write my own print function for this, but was >> wondering if there was a standard way of doing it. If not in R, >> perhaps there is some way to have ESS delete the final spaces? >>

[R] Suppressing final spaces in data.frame printouts

2009-11-11 Thread Stavros Macrakis
When printing data.frames, R aligns columns by padding with spaces. For example, print(data.frame(x=c('a','bb','ccc')),right=FALSE)   x 1 a  |-- vertical bar shows end of line 2 bb |-- vertical bar shows end of line 3 ccc|-- vertical bar shows end of

Re: [R] Book on R programming

2009-08-31 Thread Stavros Macrakis
I recommend you skim the Chambers book at Google Books or Amazon before buying it as a guide to programming in R. It is a fascinating book, but is more a discursive reflection on the history and philosophy of R than a practical guide to programming in R. It certainly explains the rationale for ma

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

2009-08-21 Thread Stavros Macrakis
On Thu, Aug 20, 2009 at 1:27 PM, David Winsemius wrote: ... > But an extremely simple modification "succeeds": > >  if ( 0 ) {" >  commented with zero >  "} else {" >  commented with one >  "} > > Returns: > [1] "\ncommented with one\n" Yes, but of course that executes neither one nor the other.

[R] Keeping track of memory usage

2009-08-20 Thread Stavros Macrakis
How can I determine how much memory a given piece of my code is allocating (directly or indirectly)? -- essentially, the space analogue of system.time, something like this: system.space( x <- rnorm(1) ) 1 Vcells system.space( for (i in 1:1000) x <- rnorm(1) ) 1

Re: [R] Object equality for S4 objects

2009-07-30 Thread Stavros Macrakis
On Thu, Jul 30, 2009 at 4:03 PM, Martin Morgan wrote: > S4 objects are mutable in the sense that one can write replacement methods > for them Understood, but I don't think that's the usual meaning of 'mutable'. -s __ R-help@r-project.org m

Re: [R] Object equality for S4 objects

2009-07-30 Thread Stavros Macrakis
On Thu, Jul 30, 2009 at 12:01 PM, Martin Morgan wrote: > S4 objects do not have the semantics of environments, but of lists (or of > most other R objects), so it is as meaningful to ask why identical(s1, s2) > returns TRUE as it is to ask why identical(list(x=1), list(x=1)) returns TRUE. Thanks

[R] Object equality for S4 objects

2009-07-29 Thread Stavros Macrakis
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 na

Re: [R] quoting expressions in a list

2009-07-16 Thread Stavros Macrakis
On Thu, Jul 16, 2009 at 4:44 PM, Erik Iverson wrote: > I have a list of logical expressions, and I would really like it if the > "names" of the components of the list were identical to the corresponding > logical expression. > > So, as an example: > > df.example <- data.frame(a = 1:10, b = rnorm(

Re: [R] Simple cat statement - output truncated

2009-07-16 Thread Stavros Macrakis
Kevin, The habitués of this mailing list get irritated when users mail in problem reports which don't include enough information to reproduce the problem, as requested in the standard footer of r-help mail ("PLEASE ... provide commented, minimal, self-contained, reproducible code.") This irritatio

Re: [R] dereferencing in R

2009-07-16 Thread Stavros Macrakis
What do you mean by 'passing an array reference' and 'dereferencing' and what do you mean by an 'R script'? What language(s) are you accustomed to? If you mean 'passing an array value' to an 'R function', you just use the argument name. Since R uses call-by-value (modulo the substitute mechanism

Re: [R] Trig functions strange results

2009-07-14 Thread Stavros Macrakis
On Tue, Jul 14, 2009 at 1:45 PM, Nair, Murlidharan T wrote: > I am trying to calculate coordinate transformations and in the process of > debugging my code using debug I found the following > > Browse[1]> direction[i] > [1] -1.570796 > Browse[1]> cos(direction[i]) > [1] 6.123032e-17 > Browse[1]>

Re: [R] strange strsplit gsub problem 0 is this a bug or a string length limitation?

2009-07-10 Thread Stavros Macrakis
On Fri, Jul 10, 2009 at 8:58 AM, Marc Schwartz wrote: > Review the Note in ?as.character: > "as.character truncates components of language objects to 500 characters > (was about 70 before 1.3.1)." > If this limitation is too hard to fix, shouldn't it at least give a warning or an error?

Re: [R] Question in using e1071 svm routine

2009-07-07 Thread Stavros Macrakis
Isn't the initial value of the variable T equal to the constant TRUE? So unless he's modified the value of T, shouldn't it work? -s On 7/7/09, Max Kuhn wrote: > Unlike Splus, R does not use T for TRUE. > > On Tue, Jul 7, 2009 at 6:05 PM, Michael wrote: >> Hi all, >> >> I've got the fo

Re: [R] Numbering sequences of non-NAs in a vector

2009-07-07 Thread Stavros Macrakis
Here's one possibility: vv <- c(10,8,1,3,0,8,NA,NA,NA,NA,2,1,6,NA,NA,NA,0,5,1,9) > (1+cumsum(diff(is.na(c(vv[1],vv)))==1)) * !is.na(vv) [1] 1 1 1 1 1 1 0 0 0 0 2 2 2 0 0 0 3 3 3 3 On Tue, Jul 7, 2009 at 5:08 PM, Krishna Tateneni wrote: > Greetings, I have a vector of the form: > [10,8,1,3,0,

Re: [R] Automatically placing a legend in an area with the most white space...

2009-06-28 Thread Stavros Macrakis
install.packages('plotrix') On Sun, Jun 28, 2009 at 3:51 PM, Jason Rupert wrote: > ... > Error in legend(emptyspace(rep(x_vals_1, 3), c(y1_vals, y2_vals, y3_vals)), > : > could not find function "emptyspace" > > I've searched via RSeek, but I have not been able to find anything on this > functi

Re: [R] How do I get just the two last tokens of each string in a vector?

2009-06-26 Thread Stavros Macrakis
One way is: a <- c(" %L H*L L*H H%", "%L H* H%", "%L L*H %", "%L L*H %" ) > sub("^.*(^| )([^ ]+ [^ ]+$)","\\2",a) [1] "L*H H%" "H* H%" "L*H %" "L*H %" Just be aware that this is not terribly efficient for very large strings. -s On Fri, Jun 26, 2009 at 7:21 AM, Fredrik Karlsson

Re: [R] How to avoid ifelse statement converting factor to character

2009-06-26 Thread Stavros Macrakis
It gives me a headache, too! I think you'll have to wait for a more expert user than me to supply explanations of these behaviors and their rationales. -s On 6/26/09, Craig P. Pyrame wrote: > Stavros Macrakis wrote: >> On Thu, Jun 25, 2009 at 12:47 PM, Craig P. P

Re: [R] How to avoid ifelse statement converting factor to character

2009-06-25 Thread Stavros Macrakis
On Thu, Jun 25, 2009 at 12:47 PM, Craig P. Pyrame wrote: > The man page Stavros quotes states that the class attribute of the result is > taken from 'test', which clearly is not the case: Actually, the behavior is documented pretty clearly: The mode of the answer will be coerced from logical

Re: [R] How to avoid ifelse statement converting factor to character

2009-06-25 Thread Stavros Macrakis
Erratum: >     ifelse(TRUE,dd,dd) => 1230786000 (class numeric) should be ifelse(TRUE,tt,tt) => 1230786000 (class numeric) __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.

Re: [R] How to avoid ifelse statement converting factor to character

2009-06-25 Thread Stavros Macrakis
On Wed, Jun 24, 2009 at 9:04 PM, Rolf Turner wrote: >  Do not get your knickers in a twist.  R works simply and straightforwardly >  in simple straightforward situations. Though I find R an incredibly useful tool, alas, it is simply not true that "R works simply and straightforwardly in simple str

Re: [R] How to avoid ifelse statement converting factor to character

2009-06-24 Thread Stavros Macrakis
On Wed, Jun 24, 2009 at 12:34 PM, Mark Na wrote: > The problem is that after running the ifelse statement, data$SOCIAL_STATUS > is converted from a factor to a character. > Is there some way I can avoid this conversion? I'm afraid that ifelse has very bizarre semantics when the yes and no argument

Re: [R] first value...

2009-06-23 Thread Stavros Macrakis
I think what you mean is that you want to find the position of the first non-NA value in the vector. is.na returns a boolean vector of the NA values, so: xx <- c(NA,NA,NA,2,3,NA,4) > which(!is.na(xx))[1] [1] 4 The other proposed solution, which(diff(is.na(inc)) < 0) is incorrect: > which(

Re: [R] [Rd] Floating point precision / guard digits? (PR#13771)

2009-06-20 Thread Stavros Macrakis
On Sat, Jun 20, 2009 at 4:10 PM, Dr. D. P. Kreil wrote: > Ah, that's probably where I went wrong. I thought R would take the > "0.1", the "0.3", the "3", convert them to extended precision binary > representations, do its calculations, an the reduction to normal > double precision binary floats w

Re: [R] [Rd] Floating point precision / guard digits? (PR#13771)

2009-06-20 Thread Stavros Macrakis
(I am replacing R-devel and r-bugs with r-help as addressees.) On Sat, Jun 20, 2009 at 9:45 AM, Dr. D. P. Kreil wrote: > So if I request a calculation of "0.3-0.1-0.1-0.1" and I do not get 0, > that is not an issue of rounding / underflow (or whatever the correct > technical term would be for th

Re: [R] tapply with cbinded x

2009-06-16 Thread Stavros Macrakis
On Tue, Jun 16, 2009 at 5:16 AM, Stefan Uhmann wrote: > why does this not work? > > df <- data.frame(var1 = c(3,2,1), var2 = c(6,5,4), var3 = c(9,8,7), >fac = c('A', 'A', 'B')) > tapply(cbind(df$var1, df$var2, df$var3), df$fac, mean) > Because tapply is defined for atomic vectors and not

Re: [R] Referencing data frames

2009-06-15 Thread Stavros Macrakis
On Mon, Jun 15, 2009 at 12:38 PM, Payam Minoofar < payam.minoo...@meissner.com> wrote: > ...I would like to have a function acquire an object by reference, and > within the function create new objects based on the original object and then > use the name of the original object as the base for the n

Re: [R] function inside ifelse

2009-06-15 Thread Stavros Macrakis
Of course functions can be used inside ifelse. They should return vectors. Be careful of the effect of recycling: ifelse(c(F,T,F,T,F,T),1:3,10:20) [1] 10 2 12 1 14 3 with functions: > f<- function(x) x/mean(x) > ifelse(c(F,T,F,T,F,T),sqrt(1:3),f(10:20)) [1] 0.667 1.4142136 0.800 1.0

Re: [R] Tables without names

2009-06-12 Thread Stavros Macrakis
On Fri, Jun 12, 2009 at 6:09 AM, Duncan Murdoch wrote: > On 11/06/2009 5:35 PM, Stavros Macrakis wrote: > >> A table without names displays like a vector: >> >>> unname(table(2:3)) >>[1] 1 1 1 >> >> and preserves the table class (as with unnam

[R] Tables without names

2009-06-11 Thread Stavros Macrakis
A table without names displays like a vector: > unname(table(2:3)) [1] 1 1 1 and preserves the table class (as with unname in general): > dput(unname(table(2:3))) structure(c(1L, 1L), .Dim = 2L, class = "table") Does that make sense? R is not consistent in its treatment of such

Re: [R] using regular expressions to retrieve a digit-digit-dot structure from a string

2009-06-09 Thread Stavros Macrakis
On Tue, Jun 9, 2009 at 7:44 AM, Mark Heckmann wrote: > Thanks for your help. Your answers solved the problem I posted and that is > just when I noticed that I misspecified the problem ;) > My problem is to separate a German texts by sentences. Unfortunately I > haven't found an R package doing th

Re: [R] Splicing factors without losing levels

2009-06-09 Thread Stavros Macrakis
On Tue, Jun 9, 2009 at 11:16 AM, Titus von der Malsburg wrote: > On Tue, Jun 09, 2009 at 11:04:03AM -0400, Stavros Macrakis wrote: > > This may seem like a minor point, but I think it is worthwhile using > > descriptive names for functions. > > Makes sense. I thought I'

Re: [R] Splicing factors without losing levels

2009-06-09 Thread Stavros Macrakis
Various people have provided technical solutions to your problem. May I suggest, though, that 'splice' isn't quite the right word for this operation? Splicing two pieces of rope / movie film / audio tape / wires / etc. means connecting them at their ends, either at an extremity or in the middle,

Re: [R] if else

2009-06-08 Thread Stavros Macrakis
On Mon, Jun 8, 2009 at 3:36 PM, Don MacQueen wrote: Though I do agree that the way you've written the general case with any/ is.na and sum/na.rm is cleaner and clearer because more general, I don't agree at all with what you say about nested ifelse's vs. a series of assignments: > In my opinion

Re: [R] if else

2009-06-08 Thread Stavros Macrakis
On Mon, Jun 8, 2009 at 1:48 PM, Cecilia Carmo wrote: > I have the following dataframe: > firm<-c(rep(1:3,4)) > year<-c(rep(2001:2003,4)) > X1<-rep(c(10,NA),6) > X2<-rep(c(5,NA,2),4) > data<-data.frame(firm, year,X1,X2) > data > > So I want to obtain the same dataframe with a variable X3 that is:

Re: [R] Done: Fast way of finding top-n values of a long vector

2009-06-05 Thread Stavros Macrakis
On Fri, Jun 5, 2009 at 4:09 AM, Allan Engelhardt wrote: > I'm all done now. The "max2" version below is what I went with in the end > for my proposed change to caret::nearZeroVar (which used the "sort" method). > Max Kuhn will make it available on CRAN soon. It speeds up that routine by > a fac

[R] all.equal(0,0i)

2009-06-02 Thread Stavros Macrakis
> all.equal(0,0i) [1] "Modes: numeric, complex" [2] "target is numeric, current is complex" > all.equal(1,1+0i) [1] "Modes: numeric, complex" [2] "target is numeric, current is complex" Is this the intended behavior? In general, all.equal is strict about argument mode, thus TRUE/1 and 1/'1' do n

Re: [R] Error:non-numeric argument in my function

2009-06-01 Thread Stavros Macrakis
On Mon, Jun 1, 2009 at 11:33 AM, Wacek Kusnierczyk < waclaw.marcin.kusnierc...@idi.ntnu.no> wrote: > ... there is an ugly lack of consistency here:... > I agree that it's inconsistent that 1:'2' --> 1:2 # this doesn't seem to be documented in ? seq 1+ '2' --> error 1+facto

Re: [R] R Solves Shakespeare Authorship Question

2009-06-01 Thread Stavros Macrakis
I don't know why this paper is getting our attention here -- it is just an undergraduate student term paper for a computer science course on statistics and data mining. -s On Mon, Jun 1, 2009 at 5:48 PM, wrote: > On Sat, 30-May-2009 at 07:42PM -0700, Arthur Burke wrote: > > |> Thos

Re: [R] Error:non-numeric argument in my function

2009-06-01 Thread Stavros Macrakis
type of offending object was found. If > the message said that a list of class > 'data.frame' was found (probably the leading > case), then that would be much more helpful. > > Patrick Burns > patr...@burns-stat.com > +44 (0)20 8525 0696 > http://www.burns-stat.com

Re: [R] Error:non-numeric argument in my function

2009-05-31 Thread Stavros Macrakis
On Sun, May 31, 2009 at 6:10 PM, jim holtman wrote: > Message is very clear: > > > 1 * 'a' > Error in 1 * "a" : non-numeric argument to binary operator Though the user should have been able to figure this out, perhaps the error message could be improved? After all, it is not the fact that the o

Re: [R] maxtrix to permutation vector

2009-05-29 Thread Stavros Macrakis
)) > m y x x y a 1 3 b 2 4 > melt(m) x y value 1 a x 1 2 b x 2 3 a y 3 4 b y 4 > as.matrix(melt(m)) x y value [1,] "a" "x" "1" [2,] "b" "x" "2" [3,] "a" "y" "3" [4,]

Re: [R] maxtrix to permutation vector

2009-05-29 Thread Stavros Macrakis
Not sure what you mean by "permutations" here. I think what you mean is that given a matrix m, you want a matrix whose rows are c(i,j,m[i,j]) for all i and j. You can use the `melt` function in the `reshape` package for this. See below. Hope this helps, -s > library(reshape) > me

[R] max.col specification

2009-05-29 Thread Stavros Macrakis
I'm not sure I understand the max.col spec or its rationale. In particular: * What is the significance and effect of "assuming that the entries are probabilities", as they do not seem to be limited to the interval [0,1]? * In what contexts is it useful for max.col to consider numbers within a cer

Re: [R] custom sort?

2009-05-28 Thread Stavros Macrakis
I couldn't get your suggested method to work: `==.foo` <- function(a,b) unclass(a)==unclass(b) `>.foo` <- function(a,b) unclass(a) < unclass(b) # invert comparison is.na.foo <- function(a)is.na(unclass(a)) sort(structure(sample(5),class="foo")) #-> 1:5 -- not reversed What am I mis

[R] RODBC package: how to check whether connection is open

2009-05-28 Thread Stavros Macrakis
What is the recommended way of checking whether an RODBC connection is open? Since odbcValidChannel is not exported from namespace RODBC, I suppose I shouldn't be using it. This is the best I could come up with, but it seems a bit 'dirty' to be using a tryCatch for something like this: odbcOpe

Re: [R] custom sort?

2009-05-28 Thread Stavros Macrakis
I agree that it is surprising that R doesn't provide a sort function with a comparison function as argument. Perhaps that is partly because calling out to a function for each comparison is relatively expensive; R prefers vector operations. That said, many useful custom sorts are easy to define by

[R] R Books listing on R-Project

2009-05-27 Thread Stavros Macrakis
I was wondering what the criteria were for including books on the Books Related to R page . (There is no maintainer listed on this page.) In particular, I was wondering why the following two books are not listed: * Andrew Gelman, Jennifer Hill, *Data

Re: [R] Defining functions - an interesting problem

2009-05-27 Thread Stavros Macrakis
The 'ties.method' argument to 'rank' is the *third* positional argument to 'rank', so either you need to put it in the third position or you need to use a named argument. The fact that the variable you're using to represent ties.method is called ties.method is irrelevant. That is, this: ra

Re: [R] How to exclude a column by name?

2009-05-27 Thread Stavros Macrakis
On Wed, May 27, 2009 at 6:37 AM, Zeljko Vrba wrote: > Given an arbitrary data frame, it is easy to exclude a column given its > index: > df[,-2]. How to do the same thing given the column name? A naive attempt > df[,-"name"] did not work :) > Various ways: Boolean index vector: df[ , nam

[R] OWL (Web Ontology Language) in R?

2009-05-26 Thread Stavros Macrakis
Is anyone working on an R package for manipulating OWL (Web Ontology Language), either natively or via an external library? I don't see anything obviously relevant in CRAN, though of course OWL functionality could be built up starting with the XML package. Thanks, -s [[alter

Re: [R] XML parse error

2009-05-24 Thread Stavros Macrakis
On Sun, May 24, 2009 at 12:28 PM, kulwinder banipal wrote: > It is for sure little complicated then a plain XML file. The format of > binary file is according to XML schema. I have been able to get C parser > going to get information from binary with one caveat - I have to manually > read the XM

Re: [R] Class for time of day?

2009-05-22 Thread Stavros Macrakis
On Fri, May 22, 2009 at 12:28 PM, Gabor Grothendieck < ggrothendi...@gmail.com> wrote: ...The way this might appear in code is if someone wanted to calculate the > number of one hour intervals in 18 hours. One could write: > > t18 <- times("18:00:00") > t1 <- times("1:00:00") > as.numeric(t18) /

Re: [R] Class for time of day?

2009-05-22 Thread Stavros Macrakis
On Fri, May 22, 2009 at 10:03 AM, Gabor Grothendieck < ggrothendi...@gmail.com> wrote: > Regarding division you could contribute that to the chron package. > I've contributed a few missing items and they were incorporated. > Good to know. Maybe I'll do that > Giving an error when it does n

Re: [R] Class for time of day?

2009-05-22 Thread Stavros Macrakis
On Thu, May 21, 2009 at 8:28 PM, Gabor Grothendieck wrote: > It uses hours/minutes/seconds for values < 1 day and uses days and > fractions > of a day otherwise. > Yes, my examples were documenting this idiosyncracy. > For values and operations that it has not considered it falls back to > the

Re: [R] Class for time of day?

2009-05-21 Thread Stavros Macrakis
On Wed, May 20, 2009 at 12:28 PM, Gabor Grothendieck < ggrothendi...@gmail.com> wrote: > There is a times class in the chron package. Perfect! Just what I was looking for. On Wed, May 20, 2009 at 12:19 PM, jim holtman wrote: > If you want the hours from a POSIXct, here is one way of doing it

[R] Class for time of day?

2009-05-20 Thread Stavros Macrakis
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 Analysi

Re: [R] Too large a data set to be handled by R?

2009-05-20 Thread Stavros Macrakis
On Tue, May 19, 2009 at 11:59 PM, tsunhin wong wrote: > In order to save time, I am planning to generate a data set of size > 1500 x 2 with each data point a 9-digit decimal number, in order > to save my time. > I know R is limited to 2^31-1 and that my data set is not going to > exceed this

Re: [R] Functions returning functions

2009-05-20 Thread Stavros Macrakis
On Wed, May 20, 2009 at 7:21 AM, Paulo Grahl wrote: > A <- function(parameters) { > # calculations w/ parameters returning 'y' > tmpf <- function(x) { # function of 'y' } > return(tmpf) > } > > The value of the parameters are stored in an environment local to the > function. Then I ca

Re: [R] exists function on list objects gives always a FALSE

2009-05-19 Thread Stavros Macrakis
On Tue, May 19, 2009 at 12:07 PM, Žroutík wrote: > > SmoothData <- list(exists=TRUE, span=0.001) > > exists("SmoothData$span") > FALSE > As others have said, this just checks for the existence of a variable with the (strange) name "SmoothData$span". In some sense, in R semantics, xxx$yyy *alway

Re: [R] Generic 'diff'

2009-05-18 Thread Stavros Macrakis
ding your objection. -s > On Mon, May 18, 2009 at 5:48 PM, Stavros Macrakis > wrote: > > I guess I wasn't very clear. The goal is not to define diff on a > different > > object type, but to have a different 'subtraction' operator with the same &g

Re: [R] Generic 'diff'

2009-05-18 Thread Stavros Macrakis
od for that. For > some examples see: > > methods(diff) > > > > On Mon, May 18, 2009 at 4:24 PM, Stavros Macrakis > wrote: > > I would like to apply a function 'f' to the lagged version of a vector > and > > the vector itself. > > > > This i

[R] Generic 'diff'

2009-05-18 Thread Stavros Macrakis
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

Re: [R] Concatenating two vectors into one

2009-05-18 Thread Stavros Macrakis
If you want to concatenate the *vectors*, you need 'c', which will also coerce the elements to a common type. If you want to concatenate the corresponding *elements* of the vectors, you need 'paste', which will coerce them to character strings. -s On 5/18/09, Henning Wildhagen wrote:

Re: [R] Gamma function

2009-05-16 Thread Stavros Macrakis
What exactly is the R code you wrote for your function f? Without that, it will be hard to help you. -s On Sat, May 16, 2009 at 2:48 AM, Kon Knafelman wrote: > > Hi Guy, > > I am having trouble graphing the following function > > √2Γ(n/2)/[√n - 1Γ((n - 1)/2 for the values of n betw

Re: [R] newbie: closing unused connection + readline

2009-05-16 Thread Stavros Macrakis
On Sat, May 16, 2009 at 9:11 AM, Aval Sarri wrote: > ...I tried something line this also: > > mydataframe <- read.table (socket, sep=","); > > but does not work says no input lines. > > this also. > > mydataframe <- read.table (readLine(socket), sep=","); Sorry, I didn't see this before my last e

Re: [R] newbie: closing unused connection + readline

2009-05-16 Thread Stavros Macrakis
On Sat, May 16, 2009 at 8:34 AM, Aval Sarri wrote: > # Create a socket from which to read lines - one at a time (record) > reader.socket <-   socketConnection( host = 'localhost', 5000, >                                     server = TRUE, blocking = TRUE, >                                     open

[R] Converting numbers to and from raw

2009-05-15 Thread Stavros Macrakis
How can I convert an integer or double to and from their internal representation as raws of length 4 and 8? The following works for positive integers (including those represented as floats): # Convert integer (represented as integer or double) to sequence # of raw bytes, least-significant byte fi

Re: [R] can you tell what .Random.seed *was*?

2009-05-15 Thread Stavros Macrakis
On Fri, May 15, 2009 at 12:07 PM, Stavros Macrakis wrote: > system.time(whatseed(runif(1))) Sorry, though I got lucky and my overall result is roughly correct, this is an incorrect time measure. It should be r <- runif(1); system.time(whatseed(r)) because R's call-by-need sema

Re: [R] can you tell what .Random.seed *was*?

2009-05-15 Thread Stavros Macrakis
On Thu, May 14, 2009 at 3:36 PM, G. Jay Kerns wrote: > set.seed(something) > x <- rnorm(100) > y <- runif(500) > # bunch of other stuff ... > Now, I give you a copy of my script.R (with the set.seed statement > removed, of course) together with the .RData file that was generated > by the save.imag

Re: [R] Beyond double-precision?

2009-05-11 Thread Stavros Macrakis
On Sat, May 9, 2009 at 12:17 PM, Berwin A Turlach wrote: > log(H) = log(n) - log( 1/x_1 + 1/x_2 + ... + 1/x_n) >...But we need to calculate the logarithm of a sum from the logarithms of the >individual terms. > ...The way to calculate log(x+y) from lx=log(x) and ly=log(y) ... >  max(lx,ly) + log

[R] Inconsistency in representation of variables

2009-05-11 Thread Stavros Macrakis
In stats::D, I was wondering why variables are represented as symbols in expressions, but as strings in lists of variables: D(quote(x^2),"x") => 2*x D(quote(x^2),quote(x)) => error Variable must be a character string Strings are not allowed in the expression to denote variables: D(qu

Re: [R] integrate lgamma from 0 to Inf

2009-04-27 Thread Stavros Macrakis
On Wed, Apr 22, 2009 at 3:28 AM, Andreas Wittmann wrote: > i try to integrate lgamma from 0 to Inf. Both gamma and log are positive and monotonically increasing for large arguments. What can you conclude about the integrability of log(gamma(x))? -s __

[R] The assign(paste(...,i),...) idiom

2009-04-20 Thread Stavros Macrakis
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 _

Re: [R] Loop question

2009-04-18 Thread Stavros Macrakis
On Fri, Apr 17, 2009 at 10:12 PM, Brendan Morse wrote: > ...I would like to automatically generate a series of matrices and > give them successive names. Here is what I thought at first: > > t1<-matrix(0, nrow=250, ncol=1) > > for(i in 1:10){ >        t1[i]<-rnorm(250) > } > > What I intended was

Re: [R] (no subject)

2009-04-18 Thread Stavros Macrakis
> mylist <- c( 2,1,3,5,4 )<<< make a vector of numbers > sort(mylist) [1] 1 2 3 4 5 <<< in sorted order > mylist <- c( "this", "is", "a", "test") > sort(mylist) [1] "a""is" "test" "this" <<< in sorted order > order(mylist) [1] 3 2 4 1

Re: [R] Using trace

2009-04-17 Thread Stavros Macrakis
e({cat(sprintf("x= %i\n",x));return}),print=T) > [1] "fact" >> fact(4) > Tracing fact(4) on entry > x= 4 > Tracing fact(x - 1) on entry > x= 3 > Tracing fact(x - 1) on entry > x= 2 > Tracing fact(x - 1) on entry > x= 1 > Tracing fact(x - 1) on

Re: [R] Using trace

2009-04-17 Thread Stavros Macrakis
<- x*fact(x-1) > + print(sys.call()) > + cat(sprintf("X is %i\n",x)) > + print(ans) > + } >> fact(4) > fact(x - 1) > X is 0 > [1] 1 > fact(x - 1) > X is 1 > [1] 1 > fact(x - 1) > X is 2 > [1] 2 > fact(x - 1) > X is 3 > [1] 6 > fact(4) &

Re: [R] Intersection of two sets of intervals

2009-04-15 Thread Stavros Macrakis
There is a very nice "intervals" package in CRAN. It is impressively efficient even for intersections of many millions of intervals. If I remember correctly, it is purely in-core, so on a 32-bit R you'll be limited to something like 100 million intervals. Is that enough for your application?

Re: [R] Forcing the extrapolation of loess through the origin

2009-04-14 Thread Stavros Macrakis
On Tue, Apr 14, 2009 at 1:08 PM, wrote: > I'm fitting a line to my dataset. Later I want to predict missing values that > exceed the [min,max] interval of my empirical data, therefore I choose > surface="direct" for extrapolation. > > l1<-loess(y1~x1,span=0.1,data.frame(x=x1,y=y1),control=loess

Re: [R] Automating object creation

2009-04-14 Thread Stavros Macrakis
It is certainly possible to create x2, x4, etc. using something like assign( sprintf("x%d",i), ...value... ). But are you sure you need separate *variables* x2, x4, etc.? Why not create a list of vectors addressible as x[2] etc.? You can do that with x <- list() (to define the data type of x as

Re: [R] Concatenation, was Re: Physical Units in Calculations

2009-04-13 Thread Stavros Macrakis
On Mon, Apr 13, 2009 at 5:15 AM, Peter Dalgaard wrote: > Stavros Macrakis wrote: >> ...c of two time differences is currently a numeric vector, >> losing its units (hours, days, etc.) completely. > > That's actually a generic feature/issue of c(). ... > There is s

Re: [R] Finding the 5th percentile

2009-04-13 Thread Stavros Macrakis
quantile( dsamp100, 0.05 ) On Mon, Apr 13, 2009 at 10:41 AM, Henry Cooper wrote: > dsamp100<-coef(100,39.83,5739,2869.1,49.44) __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www

  1   2   3   >