r

Any interesting analysis using R and Adwords?

Just curious if anyone has attempted to use R with the Adwords API for analytical or statistical purposes. I'd love to see the type of implementation and what you are trying to solve/answer using R. Any link to scripts you could share would be great Thanks ...

using grid and ggplot2 to create join plots using R

I would like to know what can I do to fix a grid of plots. The plots are arranged in an array so that all the plots in a row have the same Y axis variable and all the plots in a column have the same X axis variable. When joined together in a grid this creates a multiplot. I disable the labels on most of the plots excepting the outer one...

How do I find the edges of a vertex using igraph and R?

Say I have this example graph, i want to find the edges connected to vertex 'a' d <- data.frame(p1=c('a', 'a', 'a', 'b', 'b', 'b', 'c', 'c', 'd'), p2=c('b', 'c', 'd', 'c', 'd', 'e', 'd', 'e', 'e')) library(igraph) g <- graph.data.frame(d, directed=FALSE) print(g, e=TRUE, v=TRUE) I can easily find a vertex: V(g)[V(...

error when trying to import ps file by grImport in R

I need to create a pdf file with several chart created by ggplot2 arranged in a A4 paper, and repeat it 20-30 times. I export the ggplot2 chart into ps file, and try to PostScriptTrace it as instructed in grImport, but it just keep giving me error of "Unrecoverable error, exit code 1". I ignore the error and try to import and xml file...

invalid multibyte character crashes when script is loaded from source (umlauts / special characters)

EDIT: Thx to suggestions from the mailing list I realized that the problem I got has nothing to do with Sweave or Latex. It´s some Mac OS X related issue. Whenever I run my script by selecting all and sending it to R it works. When I use source("myplainRcode.R") i get the error message stated below finally I got sweave working ...

Running an external script from Access

Hi all, I want my Access application to run an external program (in this case a R script) after the user clicks a button. I use this code: Dim RetVal RetVal = Shell("""C:\Program Files\R\R-2.10.1\bin\R.exe"" CMD BATCH --no-environ --silent --no-restore --no-save ""c:\test.R"" ""c:\test-result.txt""", vbHide) MsgBox RetVal This works ...

R: "Error in m[, 1L] : incorrect number of dimensions" when installing a package

When trying to install a package in R I get the following odd error and R does not load and return the CRAN selection menu. What causes this? > install.packages("rJava") Warning in install.packages("rJava") : argument 'lib' is missing: using '/home/jal/R/x86_64-pc-linux-gnu-library/2.11' --- Please select a CRAN mirror for use in this...

How do I get ggplot to order facets correctly?

I am trying to facet about 14 plots based on a variable that runs from 2-14. The plots show up in the order: 10,11,12,13,14,15,2,3,4,5,6,7,8,9 How do I get them to order from 2-15? update: ok, so I made it a factor using data$var=as.factor(data$var). The Levels are Levels: 10 11 12 13 14 15 2 3 4 5 6 7 8 9 How do I reorder those? ...

R: rJava package install failing

When installing rJava using the install.packages("rJava") command I get the following error: checking Java support in R... present: interpreter : '/usr/bin/java' archiver : '/usr/bin/jar' compiler : '/usr/bin/javac' header prep.: '/usr/bin/javah' cpp flags : '-I/usr/lib/jvm/java-6-sun-1.6.0.20/jre/../include -I/usr/lib/jvm/java-...

Horizontal scale bar in R plot

When I plot my fitted models in R, I get the output with a vertical scale bar. Can some one kindly tell me how to place a horizontal scale bar in R plots instead of vertical? Thanks in advance. ...

How to subtract years in R?

I have a date in R, e.g. dt = as.Date('2010/03/17'); I would like to subtract 2 years from this date, without worrying about leap years and such issues, getting as.Date('2010-03-17'). How would I do that? Thanks! ...

R - Sorting and Sub-setting Maximum Values within Columns

I am trying to iteratively sort data within columns to extract N maximum values. My data is set up with the first and second columns containing occupation titles and codes, and all of the rest of the columns containing comparative values (in this case location quotients that had to be previously calculated for each city) for those occu...

orderBy with changes in decreasing and increasing sorting

Is there a standard way of sorting a data.frame by several columns, but with changes in decrease or increase? For example, you may want to order a data.frame by one variable (decreasing) and by the next (increasing). Is there something like: mydf[ order(mydf$myvariable,mydf$myvariable2,decreasing=c(FALSE,TRUE)), ] ...

avoidind a loop in R

I will like to avoid a loop in the following code: delta_S <- function(Ro, Rr, Ir, S1, S2, S3, S4, chromaty) { .... etc .....} for (i in 1:nrow(Rrecon)) { gri[i, 6] <- delta_S(Ro=as.vector(Rrecon[i, ]), Rr=data_base$bck, Ir=data_base$Ir, S1=data_base$s1, S2=data_base$s2, S3=data_base$s3, S4=data_base$s4, chromaty="tetra") } My pr...

Split a vector into chunks in R

Hi, I have to split a vector into n chunks of equal size in R. I couldn't find any base function to do that. Also Google didn't get me anywhere. So here is what I came up with, hopefully it helps someone some where. x <- 1:10 n <- 3 chunk <- function(x,n) split(x, factor(sort(rank(x)%%n))) chunk(x,n) $`0` [1] 1 2 3 $`1` [1] 4 5 6 7 ...

Reshape data from long to wide, with time in new wide variable name

I have a data frame that I would like to merge from long to wide format, but I would like to have the time embedded into the variable name in the wide format. Here is an example data set with the long format: id <- as.numeric(rep(1,16)) time <- rep(c(5,10,15,20), 4) varname <- c(rep("var1",4), rep("var2", 4), rep("var3", 4), rep("var4"...

R + ggplot: plotting irregular time series

I have data at a number of days since an event. This data is sampled irregularly - my time points are like 0, 5, 6, 10, 104 days. I don't have specific date-time information - i.e. I have no idea when in real life the event I'm studying occurred. I'd like to plot, using ggplot, my time series. I can use, say p <- ggplot(data,aes(x=tim...

How can I use pattern to combine data frames using a wildcard?

A series of functions generate varying number of data frames (minimum of 1 and a max of 11). I'd like to combine them using rbind. If I knew the names, I could easily just rbind(d1,d2...) but can't do that since I have to combine a different number of data frames each time. So lags=rbind(pattern("lags_2_Y*")) didn't work. I can get the...

Do while loop in R

I have a Program in R where i'm using do while loop in the following format for(i in 1:n) { repeat { #code if(condition){break} } } I have a problem even if the condition in if statement is true the loop is been executed still.Can anyone help me with this Thank you ...

mapply recycling arguments

I have written a function that will transform a number in base 10 to another base (I'm only interested in base 2 - 9). My current functions to convert base 10 to base 2 looks like: cb2 <- function(num){ td<-{} a <- {} while (num 2 > 0 ){ a <- num %% 2 td <- paste(td,a, sep="") num <- as.integer(num / ...