r

Problem with R rendering base Graphics in CentOS 4

Hi we're trying to get R with the standard gui loaded onto CentOS 4, and under certain users R will not render certain graphics. When logged in as root the graphics render, but under the restricted user they don't. The graphics don't render with the error: > testdata <- rbind(c(1,2,3,4,5,6),c(3,4,5,4,6,2),c(3,6,7,2,2,1),c(5,4,9,8,9,1)...

emacs, auctex, noweb-mode - how to keep screen from recentering around point?

When in auctex and noweb-mode (using Sweave in emacs), I find it distracting when the screen recenters itself as I use next-line, previous-line, etc. (C-n, C-p, and mouse-1). Does anyone know how to turn it off? Thanks much! ...

How to select rows from data.frame with 2 conditions

I have an aggregated table: > aggdata[1:4,] Group.1 Group.2 x 1 4 0.05 0.9214660 2 6 0.05 0.9315789 3 8 0.05 0.9526316 4 10 0.05 0.9684211 How can I select the x value when I have values for Group.1 and Group.2? I tried: aggdata[aggdata[,"Group.1"]==l && aggdata[,"Group.2"]==lamda,"x"] ...

Reorder dataframe columns while ignoring unidentified columns

I'm thinking there's got to be a better way to do this. I'm trying to reorder the columns in a dataframe. I have a list, ordered.colnames, representing the new ordering -- but some of the columns don't exist in dataset. To avoid the Error "undefined columns selected", I've wrapped the relevant slicing in a try() function. The following...

Preventing overwriting of files when using save() or save.image()

I am trying to find a way to stop accidental overwriting of files when using the save() and save.image() function in R. ...

melt to two variable columns

I have the following variables in a data frame [1] "Type" "I.alt" "idx06" "idx07" "idx08" "farve1" "farve2" If I do dm <- melt(d, id=c("Type","I.alt")) i get theese variables "Type" "I.alt" "variable" "value" where "idx06", "idx07", "idx08", "farve1", "farve2" is represented in "variable". But what I really want is...

Multiple data points in one R ggplot2 plot

I have two sets of data points that both relate to the same primary axis, but who differ in secondary axis. Is there some way to plot them on top of each other in R using ggplot2? What I am looking for is basically something that looks like this: 4+ | | x . + 220 3+ . . | | x | 2+ . + 210 | ...

how to make a (ggplot) line plot with different color segments conditional on direction

As per Shanes excellent solution of another question, I now realise that I do not know how to do this. My original approach was to use melt the data (thanks again shane): dm1 <- melt(d[,c("Type","I.alt","idx06","idx07","idx08")], id=c("Type","I.alt")) dm2 <- melt(d[,c("Type","I.alt","farve1","farve2")], id=c("Type","I.alt")) colnames(d...

Time series in R

Hi, I am tracking my body weight in a spread sheet but I want to improve the experience by using R. I was trying to find some information about time series analysis in R but I was not succesful. The data I have here is in the following format: date -> weight -> body-fat-percentage -> water-percentage e.g. 10/08/09 -> 84.30 -> 18.20 -...

[R] constrained least squares

I am fitting a simple regression in R on gas usage per capita. The regression formulas looks like: gas_b<-lm(log(gasq_pop)~log(gasp)+log(pcincome)+log(pn)+log(pd)+log(ps)+log(years),data=gas) summary(gas_b) I want to include a linear constraint that the beta coefficients of log(pn)+log(pd)+log(ps)=1 (sum to one). Is there a simple wa...

Working with Data.frames in R (Using SAS code to describe what I want)r

I've been mostly working in SAS of late, but not wanting to lose what familiarity with R I have, I'd like to replicate something basic I've done. You'll forgive me if my SAS code isn't perfect, I'm doing this from memory since I don't have SAS at home. In SAS I have a dataset that roughly is like the following example (. is equivalent o...

Placement of axis labels at minor breaks with ggplot2

I am using ggplot2 to do some plotting of genomic data, so the basic format is that there is a chromosome and a position along it. I convert the positions to be on a continuous scale, then put the breaks at the boundaries of the chromosomes with: scale_x_continuous("Genome Position", breaks = c(0, cumsum(chromosome_length))) That look...

Double For loops in R

How do you properly write a double for loop in R? For example, in C I would do int i, j; for (i = 1; i < 6; i++) { for (j=i; j <= 3; j++) { printf("%i,%i\n",i,j); } // Do more operations for i > 3... } which would generate the (artificial) sequence: 1,1 1,2 1,3 2,2 2,3 3,3 In R you do not get the same behaviour...

(R) Perform an operation on all pairs of rows in a table?

Is there a simple way of performing an operation on all possible pairs of rows in a table? For example, if I had four rows, I would want the operation to be applied to rows 1 and 2, 1 and 3, 1 and 4, 2 and 3, 2 and 4, and finally rows 3 and 4. ...

Can you use the lapply() function to alter the value of input?

I was wondering whether it is possible to use the lapply() function to alter the value of the input, similar to: a1<-runif(100) a2<-function(i){ a1[i]<-a1[i-1]*a1[i];a1[i] } a3<-lapply(2:100,a2) I'm looking for something akin to a for() loop, but using the lapply() infrastructure. I haven't been able to get rapply() to do this. The r...

How to view the contents of parsed R functions?

R is a functional programming language, and one of it's primary benefits is it's ability to create open and transparent functions. As John Chambers says in his excellent book "Software for Data Analysis: Programming with R": Computations are organized around functions, which can encapsulate specific, meaningful computational results...

Merge many data frames from csv files

I'd like to merge a bunch of data frames together (because it seems many operations are easier if you're only dealing w/ one, but correct me if I'm wrong). Currently I have one data frame like this: ID, var1, var2 A, 2, 2 B, 4, 5 . . Z, 3, 2 Each ID is on a single row w/ several single measurements I also have a csv file...

R Package for Bayesian Belief Networks

Is anyone aware of an R package for Bayesian Belief Networks (BBN) that can handle latent (hidden) nodes? I am referring to process learning the structure and the parameters of the model. Based on the documentation, the "bnlearn" package does not provide for such capability. In addition, is anyone aware of R packages that allow for ma...

How to find top n% of records in a column of a dataframe using R

Hi there, I have a dataset showing the exchange rate of the Australian Dollar versus the US dollar once a day over a period of about 20 years. I have the data in a data frame, with the first column being the date, and the second column being the exchange rate. Here's a sample from the data: >data V1 V2 1 12/12/19...

R: getting a function name as a string

Say I have a bunch of functions, each with something likeMyFunction.1, etc. I want to pass these functions into another function, which prints out a small report. Ideally I'd like to be able to label sections of a report by which function is being used to generate the results. So are there any nice ways of getting the name of a pred...