I'm learning R and I'm curious... I need a function that does this:
> fillInTheBlanks(c(1, NA, NA, 2, 3, NA, 4))
[1] 1 1 1 2 3 3 4
> fillInTheBlanks(c(1, 2, 3, 4))
[1] 1 2 3 4
and I produced this one... but I suspect there's a more R way to do this.
fillInTheBlanks <- function(v) {
## replace each NA with the latest preceding ava...
Possible Duplicates:
Best IDE / TextEditor for R
Recommendations for Windows text editor for R
Dear All,
I teach a large introductory R course (about 100 students), and would like to recommend suitable text editors for R. The students who attend this course are first year mathematics undergraduates doing their very first cour...
I'm a developer up in Portland, OR. I'm wondering if anyone can assist:
I'm working on Loess fit models using R, once I have the fit
accomplished, I'm looking to back-out the equation of the
fitted non-linear curve, wondering if there is a way to
determine this equation in R? I've been looking but can't find
any literature. For me, the ...
I am currently using cast on a melted table to calculate the total of each value at the combination of ID variables ID1 (row names) and ID2 (column headers), along with grand totals for each row using margins="grand_col".
c <- cast(m, ID1 ~ ID2, sum, margins="grand_col")
ID1 ID2a ID2b ID2c ID2d ID2e (all)
1 ID1a ...
I would like to know how to quickly find the specific function called by a generic function for a specific object. Example :
library(spatial)
data(redwood)
K <- Kest(redwood)
plot(K)
This is not an usual plot, it's a plot build for a Kest() object. So to investigate in order to find the function used, I do :
class(K)
I get
"fv...
I have some survey data that I want to describe by political party and state.
I'm having some trouble with the by() aggregation command. It works with lots of functions, but just not length(). Eg:
by(x, list(party=nn$info$party,state=nn$info$st),mean)
works fine but not
by(x, list(party=nn$info$party,state=nn$info$st),length)
Whi...
Hi,
I'm having a little trouble with getting ggplot2 to work as I want. Basically, I'd like to compare actual observations vs. approximated by putting them in one single plot. For example,
> library(ggplot2)
> df.actual <- data.frame(x = 1:100, y = (1:100) * 2)
> df.approx <- data.frame(x = 1:150, y = (1:150) * 2 + 5 + rnorm(150, mea...
Is there an easy way to view the source of an R package (or a method in a package), from within the interactive environment?
...
Hi all,
I'm trying to normalize a big amount of Affymetrix CEL files using R. However, some of them appear to be truncated, so when reading them i get the error
Cel file xxx does not seem to have the correct dimensions
And the normalization stops. Manually removing the corrupted files and restart every time will take very long. Do yo...
RGoogleDocs is fantastic. It allows one to store data on Google and read it in in real time to R. I tried to install it on a computer the other day and lo and behold all I could find was RGoogleData in RForge. What is the relationship between the two packages? I tried to google search RGoogleData and RGoogleDocs in the same search and fo...
I'm using R to loop through the columns of a data frame and make a graph of the resulting analysis. I don't get any errors when the script runs, but it generates a pdf that cannot be opened.
If I run the content of the script, it works fine. I wondered if there is a problem with how quickly it is looping through, so I tried to force it ...
Whenever I run this code , the first plot would simply overwrite the previous one. Isnt there a way in R to separate to get two plots ?
plot(pc)
title(main='abc',xlab='xx',ylab='yy')
plot(pcs)
title(main='sdf',xlab='sdf',ylab='xcv')
...
I was wondering if there is a way to include error terms for a linear regression model like
r = lm(y ~ x1+x2) ?
...
I'm reading a table and it contains strings that describe timestamps. I just want to convert from string to a built-in datetime type...
R> Q <- read.table(textConnection('
tsstring
1 "2009-09-30 10:00:00"
2 "2009-09-30 10:15:00"
3 "2009-09-30 10:35:00"
4 "2009-09-30 10:45:00"
5 "2009-09-30 11:00:00"
'), as.is=TRUE, heade...
Let's say I have a data matrix d
pc = prcomp(d)
# pc1 and pc2 are the principal components
pc1 = pc$rotation[,1]
pc2 = pc$rotation[,2]
Then this should fit the linear regression model right?
r = lm(y ~ pc1+pc2)
But then I get this error :
Errormodel.frame.default(formula = y ~ pc1+pc2, drop.unused.levels = TRUE) :
unequ...
Is there an equivalent of dir function (python) in R?
When I load a library in R like -
library(vrtest)
I want to know all the functions that are in that library.
In Python, dir(vrtest) would be a list of all attributes of vrtest.
I guess in general, I am looking for the best way to get help on R while running it in ESS on linux...
First I will have to apologise for my ignorance as I'm sure this is a very simple question but I am very new to R. My question is that I have a data frame that looks like this;
countrydes Insured
USA 4500
CANADA 4500
USA 7500
CANADA 7600
All I want to do is aggregate the sum of...
I want to construct a new centrality measure using igraph, preferably in R. How would I begin this? For example, would I be better adding to the igraph C library or the R interface?
Thanks
Conor
...
For a linear model with 2 variables
r = lm(y ~ x1+x2)
When I run plot(r) , I get a bunch of plots such as residuals vs fitted values and so on , but I can only look at one of them at a time . Isnt there a way to seperate them ?
...
I'm trying to get a better understanding on FA, hope you can take a look at this, my biggest problem is how to interpret FA model in R.
My results look like this:
What values in my results should I be looking at and what is a good indication of FA analysis?
Call:
factanal(x = m2, factors = 2)
Uniquenesses:
v1 v2 v3 v4 v5 v6 v7 v8 v9 v...