In R, I have two vectors:
a <- c(1, 2, 3, 4)
b <- c(NA, 6, 7, 8)
How do I find the element-wise mean of the two vectors, removing NA, without a loop? i.e. I want to get the vector of
(1, 4, 5, 6)
I know the function mean(), I know the argument na.rm = 1. But I don't know how to put things together. To be sure, in reality I have th...
A question about this R code:
library(RODBC)
ch <- tryCatch(odbcConnect("RTEST"),
warning=function(w){print("FAIL! (warning)");return(NA)},
error=function(e){print(paste("ERROR:",geterrmessage()));return(NA)})
df <- tryCatch(sqlQuery(ch,"SELECT Test from tblTest"),
warning=function(w){print("FAIL! (warning)");return(NA)},
erro...
Hi,
I am running R-2.11.1-x64, on a Win7 machine, with all packages updated through the update command.
I am trying to install the Deducer package. For that I ran:
install.packages("Deducer",,"http://rforge.net/")
install.packages('iplots',,'http://www.rforge.net/')
install.packages('JavaGD',,'http://www.rforge.net/')
install.packages(...
I'm porting an application written in R that currently runs under Windows over to Linux (Fedora 12) and am having some problems. Currently, under Windows I invoke R to run as a batch process as:
Rterm.exe --no-save --no-restore --quiet < myRprog.r > myRprog.log 2>&1
This little batch gem executes the program myRprog.r and outputs the...
Is it possible to use include files in R like in most programming languages, for example C?
...
If i want to look through a long output or variable in R, is there an equivalent to the bash command more?
...
Whenever I want to do something "map"py in R, I usually try to use a function in the apply family. (Side question: I still haven't learned plyr or reshape -- would plyr or reshape replace all of these entirely?)
However, I've never quite understood the differences between them [how {sapply, lapply, etc.} apply the function to the input/...
I have some R code inside a file called analyse.r. I would like to be able to, from the command line (CMD), run the code in that file without having to pass through the R terminal and I would also like to be able to pass parameters and use those parameters in my code:
eg. C:>(execute r script) analyse.r C:\file.txt
and this would execu...
I have several questions to do with handling some data in R:
I am using this statement: detailsTable <- read.table(file=commandArgs()[6], header=TRUE, col.names=c("a", "b", "c", "d", "e")) and it seems that the table is not being loaded correctly... but if I specify the path of the file I am loading excplicitly then all goes well. What...
Right now, I use a combination of Python and R for all of my data processing needs. However, some of my datasets are incredibly large and would benefit strongly from multithreaded processing.
For example, if there are two steps that each have to performed on a set of several millions of data points, I would like to be able to start the...
This is a newbie question in R. I am downloading yahoo finance monthly stock price data using R where the ticker names are read from a text file . I am using a loop to read the ticker names to download the data and putting them in a list. My problem is some ticker names may not be correct thus my code stops when it encounters this case...
I have a data frame with 251 observations and 45 variables. There are 6 observations in the middle of the data frame that i'd like to exclude from my analyses. All 6 belong to one level of a factor. It is easy to generate a new data frame that, when printed, appears to exclude the 6 observations. When I use the new data frame to plot var...
I'd like to convert my csv files into xts objects as efficiently as possible. I seem to be stuck though with having to first applying the read.zoo method to create a zoo objects before being able to convert it to an xts object.
gold <- read.zoo("GOLD.CSV", sep=",", format="%m/%d/%Y", header=TRUE)
Gold <- as.xts (gold, order.by=index(go...
Have been using STATA to run negative binomial regressions in a replication. Not sure what is under the hood on how STATA does this, but wanted to know if there is an R function/package that does the same thing? The R will give me a better idea of how this works, since I can see the code.
...
When I call rnorm passing a single value as mean, it's obvious what happens: a value is generated from Normal(10,1).
y <- rnorm(20, mean=10, sd=1)
But, I see examples of a whole vector being passed to rnorm (or rcauchy, etc..); in this case, I am not sure what the R machinery really does. For example:
a = c(10,22,33,44,5,10,30,22,10...
Simple (?) question:
How can I make a R script to stop? So no normal ending of all the code. Is there something like a 'return' or 'exit' function? I want ending my script to run in case of an error. Cannot find it in the documentation?
...
The question title says it all. Using R CMD Sweave my .tex file is always generated in my HOME directory. Is it possible to change this? I mean i could mv it with a shell script, but I guess there`s some better trick to do it :)
@Dirk:
I used the script that I posted here and pdflatex does not find the file because it's always written ...
I generate a QQ plot to compare the distribution of my ranom number generator with a beta distribution. I can do this using the usual plot commands in R via
samples1 <- read.csv("test1-clean.dat")
qqplot( samples1$p0, qbeta(seq(0,1,length=length(samples1$p0)),1,3) )
abline( 0, 1 )
but I want to use the ggplot2 library, and I just can...
i am using rpy2-2.0.7 (i need this to work with windows 7, and compiling the binaries for the newer rpy2 versions is a mess) to push a two-column dataframe into r, create a few layers in ggplot2, and output the image into a <.png>.
i have wasted countless hours fidgeting around with the syntax; i did manage to output the files i neede...
The following code works well:
p <- ggplot(df,aes(x=x,y=y))
p <- p + geom_tile(aes(fill=z))
p
It plots a nice heatmap. Here df contains x and y, created using expand.grid(), and z which contains the value at each (x,y) co-ordinate.
This code, on the other hand
p <- ggplot(df,aes(x=x,y=y))
p <- p + coord_map(project="lagrange")
p <- ...