r

Gantt charts with R

Has anybody used R to create a Gantt chart? The only solution that I'm aware of is this, but I'm looking for something more sophisticated, if possible (looking more or less like this or this). P.S. I could live without the dependency arrows. P.S.2 Which are the magic words that must be given in the search textbox of R Graphical Manual...

R xy scatter plot marker color

Trying to do an xy scatter plot with the z value being denoted by the color of the xy point. Data: 1.1, 32.27, 19.4 1.2, 21.34, 18 1.4, 47.45, 19.4 R code: inp <- scan("beps.txt",list(x=0,y=0,z=0)) plot(inp$x, inp$y,pch=".") Creates a great scatter plot, but I would like the points to be colored by the Z value. ...

Extract "jagged" column from R data.frame/matrix using vector of column numbers

I have a data.frame x in R for which dim(x) = (m,n) and a vector y of numbers of length m and with values between 1 and n. In other words, y has an entry for each row in x and each value is a valid column number in x. I would like to extract a "jagged" column of numbers from x using the column numbers in y. For example, if y <- c(2,4,1...

read csv with dates and numbers with R statistical software

I have a problem when I import a csv file with R: example lines to import: 2010-07-27;91 2010-07-26;93 2010-07-23;88 I use the statement: data <- read.csv2(file="...", sep=";", dec=".", header=FALSE) when I try to aggregate this data with other ones originated by statistical analysis using cbind, the date is showed as an integer n...

R: Filling missing dates in a time series ???

Hello I have a zoo time series with missing days. In order to fill it and have a continuous series I do... I generate a chron date-time sequence from start to end. I merge my series with this one. I use na.locf to substitute NAs with las obsservation. I remove the syntetic chron sequence. Can I do same easier? Maybe with some index...

How to vectorize this operation on every row of a matrix in R

I have a matrix filled with TRUE/FALSE values and I am trying to find the index position of the first TRUE value on each row (or return NA if there is no TRUE value in the row). The following code gets the job done, but it uses an apply() call, which I believe is just a wrapper around a for loop. I'm working with some large datasets and ...

R: apply over two data.frames

I'm using R, and I have two data.frames, A and B. They both have 6 rows, but A has 25000 columns (genes), and B has 30 columns. I'd like to apply a function with two arguments f(x,y) where x is every column of A and y is every column of B. So far it looks like this: i = 1 for (x in A){ j = 1 for (y in B){ out[i,j] <- f(x...

Windows batch R Sweave error loading packages

I am having trouble finding clear documentation on how to set up a batch file for a Sweave document on Windows XP. I am using the batch files that are found here I have created a batch file names run.bat which contains the following: Sweave myFile.Rnw The first thing I do in my Sweave file after setting the wd is read in a dataset ...

Basic lag in R vector/dataframe

Hi all, Will most likely expose that I am new to R, but in SPSS, running lags is very easy. Obviously this is user error, but what I am missing? x <- sample(c(1:9), 10, replace = T) y <- lag(x, 1) ds <- cbind(x, y) ds Results in: x y [1,] 4 4 [2,] 6 6 [3,] 3 3 [4,] 4 4 [5,] 3 3 [6,] 5 5 [7,] 8 8 [8,] 9 9 [9,] 3 3 [1...

ggplot2: overlay control group line on graph panel set

I have a stacked areaplot made with ggplot2: dists.med.areaplot<-qplot(starttime,value,fill=dists,facets=~groupname, geom='area',data=MDist.median, stat='identity') + labs(y='median distances', x='time(s)', fill='Distance Types')+ opts(title=subt) + scale_fill_brewer(type='seq') + facet_wrap(~groupname, ncol=2) + g...

Running an Rscript on Mac OS X

Hi All, I have a BATCH File script on a Windows machine that consists of the following line: c:\R\bin\Rscript.exe "c:\Users\user\Documents\Shares.R" I want to do the same thing but using Mac OS X at the moment I am using Automator => Run Shell Script and the following line: open "/usr/bin/Rscript" "/Users/usr/Documents/Shares.R" ...

How to plot the probabilistic density function of a function?

Assume A follows Exponential distribution; B follows Gamma distribution How to plot the PDF of 0.5*(A+B) ...

In R, how can an element of a vector of functions be selected and applied?

I have an R question--I want to make a vector of functions, and then be able to call one of the functions by name. However, when I use this name, I want to use a tag which maps to that name, so that I can chance which name I use without having to change the code. For example: #define tag tag<-"F" #define functions f <- function(x) prin...

scatterplot with equal axes

Hi, I have a data set like this one below: DataFrame <- data.frame(x=runif(25),y=runif(25), z=sample(letters[1:4],25,rep=TRUE)) and using the Lattice package, I can make a scatter plot with equal axes (with a 1:1 line going through the centre) with the following lines: xyplot(y ~ x | z, data=DataFrame, ...

R. Zoo. Repeat the first day data through all the day.

Hello I have a zoo series. It lasts 10 years and its frequency is 15min. I'd like to get a new zoo series (or vector) with the same number of elements, whith each element equal to the first element of the day. That's, The first element everyday is repeated throughout the wole day. This is not same as aggregate(originalseries,as.Date,h...

Drawdown duration

Hello How can I get the duration of the drawdowns in a zoo serie? the drawdowns can be calculated with cummax(mydata)-mydata. Whenever this value is above zero I have a drawdown. The Drawdown is the measure of the decline from a historical peak (maximum). It lasts till this value is reached again. ...

Cashflow diagram in R?

A cashflow diagram is often used when explaining derivatives in financial engineering. It shows the payoffs at different times. I couldn't find a great example online, but it looks something like this: I would like to make something roughly equivalent using ggplot2. My thought was to use a stacked bar plot, where the zero axis is s...

calculating sums of unique values in a log in R

I have a data frame with three columns: timestamp, key, event which is ordered by time. ts,key,event 3,12,1 8,49,1 12,42,1 46,12,-1 100,49,1 From this, I want to create a data frame with timestamp and (all unique keys - all unique keys with cumulative sum 0 up until a given timestamp) divided by all unique keys until the same ti...

How to create a status line with ttk?

How do you create your status line at the bottom of your window? An inactive entry does not look very nice. What other options are there? Is possible to integrate a progress bar which is visible only on demand? (I am using tk and ttk from within R.) EDIT: Now here is my second version, which works fine for me, but I would like to disp...

Help with sprintf function in R.

Hi All, I have the following R code: df <- xmlToDataFrame(/Users/usr/Desktop/shares.xml) df$timeStamp <- strptime(as.character(df$XTimeStamp), "%H:%M:%OS") df$SharePrice <- as.numeric(as.character(df$SharePrice)) sapply(df, class) options("digits.secs"=3) diff <- diff(df$SharePrice) diff sink (file="c:/xampp/htdocs/data.xml", type="out...