r

Function within function not activating as expected

I have a function that I use to get a "quick look" at a data.frame... I deal with a lot of survey data and this acts as a quick tool to see what's what. f.table <- function(x) { if (is.factor(x[[1]])) { frequency <- function(x) { x <- round(length(x)/n, digits=2) } x <- na.omit(melt(x,c())) ...

Post-hoc pairwise fisher exact test

I used to have 2 factor by 2 level experiment that got made into a 3 factor by 2 level experiment. By using paste I could make 4 unique groups from my two factors and run a fisher test with the outcome being whether an organism lived or died. fisher.test(mortal$alv.dead,paste(mortal$Strain,mortal$capsule)) But then when I wanted to i...

Changing size of points in R

I would like to make a scatter plot using R base graphics, though I can use ggplot if it is necesary. I have a data frame containing the x and y coordinates, and also two other covariates, call them a and b. I would like the size of each point to vary with a (high values of a -> larger points) and the brightness/solidity of each point ...

Plotting two variables as lines using ggplot2

Hi all, A very newbish question, but say I have data like this: test_data <- data.frame( var0 = 100 + c(0, cumsum(runif(49, -20, 20))), var1 = 150 + c(0, cumsum(runif(49, -10, 10))), date = seq.Date(as.Date("2002-01-01"), by="1 month", length.out=100)) How can I plot both time series var0 and var1 on the same graph, with date on the ...

R How to adjust only size of y axis labels

Hi, how can I adjust only the size of Y-axis labels in R? I know that cex.axis alters the size of the axis labels but it affects ONLY the x-axis...why? and how can I adjust the y axis ? any ideas? Thanks!! ...

How do I convert Rd files to pdf for a package that I am creating in R?

Hello, I am writing a package in R and I would appreciate some example bash code to process the Rd files to latex and then to pdf. It is in the directory ~/mypkg/dev/. I have generated the file structure and Rd templates. from ~/mypkg/dev/man, I have tried R CMD Rdconv -o mypkg-package.tex --type=latex mypkg-package.Rd mypkg-pack...

How do I include plotting symbol glyphs in a text annotation in ggplot2?

I'd like to include the glyph used in a scatter plot directly in a text annotation. E.g., Suppose I have: g <- g + geom_text(aes(x=14, y = 17, label="GOOD")) where g is a scatter plot w/ a linear trend line, labeled by "GOOD" at (14,17). Instead of "GOOD", I'd like to have "X = GOOD" where X is a plotting glyph (e.g., a hollow t...

How to add nice formated anotations to a R base graph using expression and the value of a variable?

Say, I have a variable rv which has some numerical value. Now, I want to plot the value of this variable on a base plot but preceded by a nicely formatted symbol e.g., r subscript m, using expression. To write on the plot I use mtext. However, what I get is either the value of the variable, but no nicely formatted symbol (left annotation...

Mathematical notion/superscripts in Rd files

I'm working on filling in an Rd file for a function. When I use \eqn{2^{x}} in the Details section, then build and install the package, there is no superscripted exponent. Looking at R-exts.pdf, it points to Poisson.Rd as an example on how to use \eqn or \deqn. In the example in that file, there is a superscripted exponent. When I loo...

How does one pass multiple data types in llply?

I have a function that requires both a S4 object and a data frame as arguments. But functions like lapply and llply will only allow one list and one function. example: new_list=llply(list, function) I could make a single list with alternating S4 object and data but llply will push one list item at a time which means that it will eithe...

if values of two columns are equal, change the value of resultant column to NA and if not keep to original value of resultant column - using R

Hi R users, This question is similar to the previous one. I am providing this example data to get my question across. id=c(1,2,3,4,5,6,7,8,9,10) var1=c(0,1,2,0,6,9,0,0,3,0) var2=c(0,0,2,3,0,0,0,5,0,0) var3=c(0,1,4,3,6,9,0,5,3,0) data=data.frame(id,var1,var2, var3) What I need is: if values of var1==var2, then make var3==NA but i...

How to use string variables to create variables list for ddply?

Using R's builtin ToothGrowth example dataset, this works: ddply(ToothGrowth, .(supp,dose), function(df) mean(df$len)) But I would like to have the subsetting factors be variables, something like factor1 = 'supp' factor2 = 'dose' ddply(ToothGrowth, .(factor1,factor2), function(df) mean(df$len)) That doesn't work. How should this ...

How to read logical data from a file in R

I generated a file which contains a logical value either a "TRUE" or a "FALSE" on each line. Now I would like to read the logical data from the file into R. However the data that are read in are of mode "character" not logical values. I was wondering how to read the data as logical values from the file. My R code is cat(FALSE,"\n", fil...

R, change the spacing of tick marks on the axis of a plot?

Hello How can I change the spacing of tick marks on the axis of a plot? What parameters should I use with base plot or with rgl? cheers ...

R: 4D plot, x, y, z, colours

Hello Could you give me an example on how to use rgl to plot 3 variables at the axes x, y and z and a fourth one with different colours? thanks ...

r row-wide conditional replacement

Friends I'm trying t set up a matrix or data.frame for a canonical correlation analysis. The original dataset has a column designating one of x conditions and subsequent columns of explanatory variables. I need to set up an array that sets an indicator variable for each condition "x". eg. Columns in df are: ID cond task1 taskN A, x...

R and SPSS difference

i will be analysing vast amount of network traffic related data shortly. i will pre-process the data in order to analyse it. i have found that R and SPSS are among the most popular tools for statistical analysis. i will also be generating quite a lot of graphs and charts. so i was wondering what is the basic difference between these two ...

producing a correct and complete xml unit testing report (for Hudson)

I'm extending RUnit (a unit testing suite for R) so that it produces also output that can be read by Hudson. actually I already have something that does this, but it does not handle 'deactivated' tests. to see what I mean, have a look at the r-forge project 'rtest' (it temporarily identifies itself as RUnit, but it further works rather...

correctly lagging with irregularly spaced data

Hello, I have some irregularly spaced data, say table A. The frequency is every 2-5 days. I have another data set, table B, which has entries for every weekday. I want to run the following regression: A_{t} = alpha + beta1 * B_{t-2 months} + error where, when I lag B, if there isn't something that isn't exactly 60 days ago, e.g. if 60...

Can scan (or any import function) return partial results after it bump into errors?

Is there anything I can do to get partial results from after bumping into errors in a big file? I am using the following command to import data from files. This is the fastest way I know, but it's not robust. It can easily screw up everything because of a small error. I hope at least there is way that scan(or any reader) can quickly retu...