[R] timeseries highlighting

2012-01-30 Thread Alexy Khrabrov
I'd like to plot a given time series in a primary color but highlight a segment of it in a different color. Is there an elegant way to do it? A+ __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the postin

[R] rbind a heterogeneous row

2011-03-22 Thread Alexy Khrabrov
I have a dataframe with many rows like this: > df X1 X2 X3 X4 X5 X6 X7 week d sim1 FALSE TRUE TRUE TRUE TRUE TRUE TRUE1 0.3064985 sim1 is the rowname, X1..X7,week,d are the column names. X1..X7 are factors, booleans in this case. I need to add another r

[R] applying to dataframe rows

2011-03-15 Thread Alexy Khrabrov
How do I apply a function to every row of a dataframe most naturally? Specifically, I'd like to filter out any row which contains an Inf in any column. Since all columns are numeric, I guess max should work on a row... -- Alexy __ R-help@r-project.or

Re: [R] Developing a web crawler

2011-03-03 Thread Alexy Khrabrov
On Mar 3, 2011, at 4:22 AM, antujsrv wrote: > > I wish to develop a web crawler in R. As Rex said, there are faster languages, but R string processing got better due to the stringr package (R Journal 2010-2). When Hadley is done with it, it will be like having it all in R! -- Alexy _

[R] the features of the truth

2011-03-01 Thread Alexy Khrabrov
This is really a statistics problem, so I wonder which R packages can be employed best to solve and visualize it. I run a lot of simulations to approach the truth. The truth is a result of very complex computations, and is a real number. The closer it is to 0, the truthier it is. Each simula

Re: [R] .libPaths(new) stopped working in 2.10

2009-12-06 Thread Alexy Khrabrov
On Sun, Dec 6, 2009 at 3:04 PM, Duncan Murdoch wrote: > Does that directory exist?  .libPaths("foobar") silently does nothing, > because (on my system) "foobar" is not a directory. (This is documented > behaviour, though it would perhaps be friendlier if it gave a warning when > it dropped a reque

Re: [R] .libPaths(new) stopped working in 2.10

2009-12-06 Thread Alexy Khrabrov
I have the .libPaths() defined in my .Rprofile, and it stopped having any effect. Even if I try to do it in the REPL, as: > x <- > paste(Sys.getenv("HOME"),"/Library/R/",paste(R.version$major,as.integer(R.version$minor),sep='.'),"/library",sep='') > x [1] "/Users/alexyk/Library/R/2.10/library"

[R] .libPaths(new) stopped working in 2.10

2009-12-06 Thread Alexy Khrabrov
I used to have the following in my .Rprofile: if (length(.libPaths())==1) .libPaths(paste(Sys.getenv("HOME"),"/Library/R/",paste(R.version$major,as.integer(R.version$minor),sep='.'),"/library",sep='')) -- and it added my user-defined library directory. Then I installed packages there, so during

[R] comma-separated thousands in numbers on plot axes?

2009-06-28 Thread Alexy Khrabrov
How can I make R separate thousands, millions, etc., on the plot axes, with commas? Cheers, Alexy __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.h

[R] compressing the plot's white space

2009-06-27 Thread Alexy Khrabrov
I need to fit a graph into a column of a 2-column paper. I found that just specifying width and height parameters (3.2in x 3.5in) to plot doesn't decrease the fonts of the main title, axis titles, and labeling numbers, and tick sizes. So I have to add cex to all labels and titles and manage ticks

[R] sorting by creation time in ls()

2009-03-17 Thread Alexy Khrabrov
When trying to remember what did I do in the session, especially after coming back to it after a few days, I'd like to mimic Unix's ls -ltrh -- does R retain the timing a certain variable is created? If not, would it make a useful addition, to have ls with an option to sort by creation tim

[R] factors to integers preserving value in a dataframe

2009-02-27 Thread Alexy Khrabrov
I want to produce a dataframe with integer columns for elements of string pairs: pairs <- c("10 21","23 45") pairs.split <- lapply(pairs,function(x)strsplit(x," ")) pdf <- as.data.frame(pairs.split) names(pdf) <- c("p","q") -- at this point things look good, except the columns are factors, as

Re: [R] accessing and preserving list names in lapply

2009-02-26 Thread Alexy Khrabrov
res <- lapply(1:length(L),do.one) Actually, I do res <- lapply(:length(L),function(x)do.one(L[x])) -- this is the price of needing the element's name, so I have to both make do.one extract the name and the meat separately inside, and lapply becomes ugly. Yet the obvious alternatives -- ex

[R] accessing and preserving list names in lapply

2009-02-26 Thread Alexy Khrabrov
Sometimes I'm iterating over a list where names are keys into another data structure, e.g. a related list. Then I can't use lapply as it does [[]] and loses the name. Then I do something like this: do.one <- function(ldf) { # list-dataframe item key <- names(ldf) meat <- ldf[[1]] mydf

[R] growing dataframes with rbind

2009-02-24 Thread Alexy Khrabrov
I'm growing a large dataframe by composing new rows and then doing row <- compute.new.row.somehow(...) d <- rbind(d,row) Is this a fast/preferred way? Cheers, Alexy __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEA

[R] 1.095e+09 for integers

2009-02-22 Thread Alexy Khrabrov
I've had a very long file written out by R with write.table, with fields of time values, converted from POSIXlt as.numeric. Among 2.5 million values, very few had 6 trailing zeroes, and those were output in scientific notation as in the subject. Is this the default behavior for long integ

Re: [R] name scoping within dataframe index

2009-01-26 Thread Alexy Khrabrov
On Jan 26, 2009, at 2:12 PM, Duncan Murdoch wrote: df[get("colname", parent.frame()) == value,] Actually, what I propose is a special search rule which simply looks at the enclosing dataframe.name[...] outside the brackets and looks up the columns first. Yes, I understood that, and I ex

Re: [R] name scoping within dataframe index

2009-01-26 Thread Alexy Khrabrov
On 1/26/2009 1:46 PM, Alexy Khrabrov wrote: Every time I have to prefix a dataframe column inside the indexing brackets with the dataframe name, e.g. df[df$colname==value,] -- I am wondering, why isn't there an R scoping rule that search starts with the dataframe names, as if we&#

[R] name scoping within dataframe index

2009-01-26 Thread Alexy Khrabrov
Every time I have to prefix a dataframe column inside the indexing brackets with the dataframe name, e.g. df[df$colname==value,] -- I am wondering, why isn't there an R scoping rule that search starts with the dataframe names, as if we'd said with(df, df[colname==value,]) -- wouldn't that

[R] Functional pattern-matching in R

2008-10-29 Thread Alexy Khrabrov
I found there's a very good functional set of operations in R, such as apply family, Hadley Wickham's lovely plyr, etc. There's even a Reduce (a.k.a. fold). Now I wonder how can we do pattern-matching? E.g., now I split dimensions like this: m <- dim(V)[1] # R n <- dim(V)[2

Re: [R] svm models in a loop

2008-10-11 Thread Alexy Khrabrov
On Oct 12, 2008, at 2:26 AM, Prof Brian Ripley wrote: You need to use substitute() on the call. Something like sapply(1:5,function(i) eval(substitute(svm(person_oid ~ ., data=zrr[1:N,]), list(N=100*i)) ) Thanks! On Sun, 12 Oct 2008, Alexy Khrabrov wrote: I want to train

[R] svm models in a loop

2008-10-11 Thread Alexy Khrabrov
I want to train svm models on increasingly large training data subsets of some zrr as follows: > m <- sapply(1:5,function(i) svm(person_oid~.,data=zrr[1:100*i,]))# (*) However, when I inspect m[1], it literally shows > m[1] [[1]] svm(formula = person_oid ~ ., data = zrr[1:N, ]) -- as

[R] subsetting dataframe by rownames to be excluded

2008-10-11 Thread Alexy Khrabrov
Is there a way to select a subset of a dataframe consisting of all those rows with rownames *except* from a subset of rownames to be excluded? Example: > a <- data.frame(x=1:10,y=10:1) > a <- a[order(a$y),] # to make rownames differ visually > a[8,] x y 3 3 8 > a["8",] x y 8 8 3 > a[-

[R] R/OCaml?

2008-10-09 Thread Alexy Khrabrov
Did anyone try to write R extensions in OCaml? What would it entail to enable it? Cheers, Alexy __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide

Re: [R] namespaces

2008-10-02 Thread Alexy Khrabrov
2008 at 11:03 AM, Alexy Khrabrov <[EMAIL PROTECTED]> wrote: I'd like to control my namespace thoroughly, separated by task. Is there a way, in R session, to introduce namespaces for tasks dynamically and switch them as needed? Or, is there a combination of load/save worksp

[R] namespaces

2008-10-02 Thread Alexy Khrabrov
I'd like to control my namespace thoroughly, separated by task. Is there a way, in R session, to introduce namespaces for tasks dynamically and switch them as needed? Or, is there a combination of load/save workspace steps which can facilitate this? Cheers, Alexy

[R] partitioning vectors of intervals

2008-09-27 Thread Alexy Khrabrov
I have two pairs of time intervals: coarse- and fine-grained. They're components of their respective dataframes, looking like, coarse:endtimestarttime 1t1_end t1_start 2 t2_end t2_start ... fine: is the same, except that i

[R] 10-minute presentation of R as a machine learning platform

2008-09-26 Thread Alexy Khrabrov
Greetings -- I'd like to present R to our university research group as a viable platform to do machine learning applications for human behavior modeling. The actual research will be further specialized, but general activities -- acquiring/interfacing with the data, specifying/learning a mo

Re: [R] creating horizontal dataframes with column names

2008-09-16 Thread Alexy Khrabrov
quot;col1","Col2","COL3") --- On Wed, 17/9/08, Alexy Khrabrov <[EMAIL PROTECTED]> wrote: From: Alexy Khrabrov <[EMAIL PROTECTED]> Subject: [R] creating horizontal dataframes with column names To: [EMAIL PROTECTED] Received: Wednesday, 17 September, 2008, 1:52

[R] creating horizontal dataframes with column names

2008-09-16 Thread Alexy Khrabrov
Greetings -- in order to write back to SQL databases, one needs to create a dataframe with values. I can get column names of an existing table with sqlColumns. Say I have a vector of values (if they're all the same type), or a list (if different). How do I create a dataframe with column

[R] splitting time vector into days

2008-09-09 Thread Alexy Khrabrov
Greetings -- I have a dataframe a with one element a vector, time, of POSIXct values. What's a good way to split the data frame into periods of a$time, e.g. days, and apply a function, e.g. mean, to some other column of the dataframe, e.g. a$value? Cheers, Alexy __

[R] annotating objects in workspace

2008-09-05 Thread Alexy Khrabrov
Is there a way to associate descriptions with the objects in the workspace, and later retrieve them to know what the object was created for? Thanks, Alexy __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do r

[R] dealing with NAs in time series

2008-09-05 Thread Alexy Khrabrov
Certain timeseries I have had outliers, which I removed by assigning NA to their positions. Now acf() refuses to go to work. What's the right way to remove outliers from ts objects, and what are teh standard ways to interpolate NAs in them? Cheers, Alexy _

[R] modeling interval data, a.k.a. irregular timeseries

2008-09-03 Thread Alexy Khrabrov
Greetings -- I've got some sensor data of the form t1_1, t1_2 t2_1, t2_2 ... tN_1,tN_2 -- time intervals measuring starts and stops of sensor activity. I'd like to see whether there's any regularity in it. Seems natural to consider these data timeseries -- except most of the timeseries p

Re: [R] figure margins too large for a barplot in png, pdf ok

2008-05-07 Thread Alexy Khrabrov
On May 6, 2008, at 10:30 PM, Prof Brian Ripley wrote: What were H & W? For png() they are (by default) in pixels, for pdf() in inches. You haven't told us your OS, but I guess Mac OS. Please update to R 2.7.0: that offers you two new png() devices for higher-quality plots, and various o

[R] figure margins too large for a barplot in png, pdf ok

2008-05-06 Thread Alexy Khrabrov
I've used to have a script with a barplot command it in, preceded by a png: png(graph.file,height=H,width=W) barplot(t,names.arg=breaks[2:(length(t)+1)],tck=gridlines) -- worked before R 2.6.2. When I tried it in R 2.6.2, which I have for a while but didn't run with that script, it complain

[R] preallocating matrices and rda read-back objects

2008-04-08 Thread Alexy Khrabrov
I've read in Phil Spector's new book that it's a good idea to preallocate a big matrix, like u <- matrix(0,nrow,ncol) # (1) Now, I read contents of a huge matrix from a Fortran binary dump. u <- readBin(con,what="double",n=nrow*ncol) # (2) If I do (1) and then (2), u is a vector, obviously it

[R] reading in a Fortran binary array

2008-04-08 Thread Alexy Khrabrov
Greetings -- I'd like to avoid converting a Fortran array of floats into ASCII and back reading it in R. Furthermore it's much faster to dump large arrays in binary, as they take up much less space with full precision -- many decimal points take up many bytes in ASCII versus four or eight

[R] exporting a split list

2007-11-27 Thread Alexy Khrabrov
Using wk <- with(d, split(word, kind)), I get the following class table: wk$`1` [1] "a" "bra" ... # (*) wk$`10` "ca" "dabra" ... Now I need to export it in the following format: classnum_members examples 1 23 a bra ... 104 ca

[R] scan(file, encoding=?)

2007-11-24 Thread Alexy Khrabrov
I'm trying to read a file in Windows CP1251 encoding (8-byte Cyrillics). My Mac's iconv understands it fine under that alias. Alas, I get an error, invalid multibyte string when trying to read it. When I convert it to UTF-8 with iconv and read without encoding=, all is well. However, I'

Re: [R] ragged array with append

2007-11-24 Thread Alexy Khrabrov
On Nov 24, 2007, at 2:07 PM, Chuck Cleland wrote: > with(d, split(word, kind)) > > # OR > > with(d, split(as.character(word), kind)) Awesome! Scoping: how do I get the result back to the top level? > with(d, wk <- split(word,kind)) > wk Error: object "wk" not found -- trying to create it at

[R] ragged array with append

2007-11-24 Thread Alexy Khrabrov
I wonder what's the right way in R to do the following -- placing objects of the same kind together in subarrays of varying length. Here's what I mean: > word <- c("a","b","c","d","e","f","g","h","i","j") > kind <- c(1,1,1,2,3,4,5,5,7,7) > d <- data.frame(word,kind) > d word kind 1

[R] [:]

2007-11-24 Thread Alexy Khrabrov
What are idioms for taking a head or a tail of a vector, either up to an index, or from an index to the end? Also -- is it necessary to use length(v) to refer to the last element? E.g., Python has v[:3] # indices 0,1,2 v[3:] # indices 3,4,... v[-1] # the last element of v v[:-1] # all but las

[R] printing levels as tuples

2007-11-22 Thread Alexy Khrabrov
I'm running rle() on a long vector, and get a result which looks like > uc Run Length Encoding lengths: int [1:16753] 1 1 1 1 1 1 1 1 1 1 ... values : int [1:16753] 29462748 22596107 18322820 14323315 12684505 9909036 7296916 6857692 5884755 5883697 ... I can print uc$names or uc$levels

[R] uniq -c

2007-11-21 Thread Alexy Khrabrov
Is there an R analog of the Unix command uniq -c: http://en.wikipedia.org/wiki/Uniq Given an array x, uniq -c replaces each contiguous subsequence of identical numbers with a tuple (count, number). E.g. $ cat > usample 10 10 9 8 8 7 7 7 6 3 1 1 1 0 $ uniq -c usample 2 10 1 9

Re: [R] shrink a dataframe for plotting

2007-11-21 Thread Alexy Khrabrov
On Nov 21, 2007, at 1:24 PM, Thibaut Jombart wrote: > Alexy Khrabrov wrote: > >> I get tables with millions of rows. For plotting to a screen-size >> jpg, obviously just about 1000 points are enough. Instead of feeding >> plot() the original millions of rows, I'

[R] shrink a dataframe for plotting

2007-11-21 Thread Alexy Khrabrov
I get tables with millions of rows. For plotting to a screen-size jpg, obviously just about 1000 points are enough. Instead of feeding plot() the original millions of rows, I'd rather shrink the original dataframe, using some kind of the following interpolation: -- split dataframe into chu

[R] asymptote

2007-11-20 Thread Alexy Khrabrov
I have a graph which looks like hyperbole. I'd like to fit a straight line to the lower segment going to infinity, approaching the X axis -- I'm interested in the angle. If I'd do it manually, I'd cut off a certain initial part of the range, [0..x_min], and then do an lm with the rest. Y

Re: [R] xy.coords and log10

2007-11-20 Thread Alexy Khrabrov
xy.coords can have a log="xy" parameter which then plot interprets to use log scale. I wonder whether plot can be instructed in a similar way to use log10 scale instead of natural logs. Cheers, Alexy On Nov 20, 2007, at 7:01 PM, Duncan Murdoch wrote: > On 11/20/2007 10:41 AM, A

[R] xy.coords and log10

2007-11-20 Thread Alexy Khrabrov
Is there a way to teach xy.coords, when given log="xy", or just "x" or "y" separately, to do a decimal log10 instead of the natural log? Cheers, Alexy __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the

Re: [R] reading graph metadata text from a file

2007-11-20 Thread Alexy Khrabrov
n") > > Naturally, this could all be "functionized" and the various text > arguments > passed as arguments to the function (see ?plot.default or its > code); or they > could be components of a list, or ... > > > Bert Gunter > Genentech Nonclinical Statistics &

Re: [R] assign if not set; stand-alone R script, source'able too?

2007-11-19 Thread Alexy Khrabrov
quot; | R --vanilla --slave Wonder if there's a way to have a single file which is a stand-alone command script, and can be source()'d in R. Cheers, Alexy On Nov 20, 2007, at 4:03 AM, Marc Schwartz wrote: > > On Tue, 2007-11-20 at 03:32 +0300, Alexy Khrabrov wrote: >> What&#

[R] assign if not set

2007-11-19 Thread Alexy Khrabrov
What's the idiom of assigning a default value to a variable if it's not set? In Ruby one can say v ||= default -- that's an or-assign, which triggers the assignment only if v is not set already. Is there an R shorthand? Cheers, Alexy __ R-help@r

[R] reading graph metadata text from a file

2007-11-19 Thread Alexy Khrabrov
I'd like to produce graphs with titles, axis labels, and legend as parameters read from a separate text file. Moreover, I'd like to use the legend for a short summary of the data -- not necessarily for describing the line colors per se. How do we do this? Cheers, Alexy ___

[R] running sum of a vector

2007-11-07 Thread Alexy Khrabrov
I need a vector with sums of vectors up to each position in the original. The imperative version is simple: # running sum: the traditional imperative way sumr.1 <- function(x) { s <- c() ss <- 0 for (i in 1:length(x)) { ss <- ss + x[i] s[i] <- ss } s } Yet I want a f

Re: [R] R as a programming language

2007-11-07 Thread Alexy Khrabrov
With all due respect to the great book -- of which I own 2 copies I bought new -- it's not an "O'Reilly Programming in " book. The idea of a programming book like that is to thoroughly treat the language from a programmer's standpoint, in a fairly standard way, such as Ruby or Python. As

Re: [R] R as a programming language

2007-11-07 Thread Alexy Khrabrov
On Nov 7, 2007, at 4:13 PM, Duncan Murdoch wrote: >> And, still no option processing as in GNU long options, or python >> or ruby's optparse. >> What's the semantics of parameter passing -- by value or by >> reference? > > By value. Thanks Duncan! So if I have a huge table t, and the idea w

[R] R as a programming language

2007-11-07 Thread Alexy Khrabrov
Greetings -- coming from Python/Ruby perspective, I'm wondering about certain features of R as a programming language. Say I have a huge table t of the form run ord unitwords new 1 1 69391013641 1 2 275 1001518 1 3 33141008