I have no problem plotting the following cumulative frequency graph plot
like this.
library(Hmisc)
pre.test <- rnorm(100,50,10)
post.test <- rnorm(100,55,10)
x <- c(pre.test, post.test)
g <- c(rep('Pre',length(pre.test)),rep('Post',length(post.test)))
Ecdf(x, group=g, what="f", xlab='Test Results', label.cu...
I'm trying to create a large XML tree in R. Here's a simplified version of the code:
library(XML)
N = 100000#In practice is larger 10^8/ 10^9
seq = newXMLNode("sequence")
pars = as.character(1:N)
for(i in 1:N)
newXMLNode("Parameter", parent=seq, attrs=c(id=pars[i]))
When N is about N^6 this takes about a minute, N^7 takes about f...
I created my own new R library (called "Media"). There is no problem when I try to load it with RGui, and I can call the functions defined in the new package. This is how I load it:
> library(Media)
But, I'm also trying to call that functions from Java/JRI code, and when I load the new R package, Java doesn't seem to find the paca...
Hi,
I am wondering if there is a way to transform a matrix of 2 column into a multimap or list of list.
The first column of the matrix is an id (with possibly duplicated entries) and the 2nd column is some value.
For example,
if I have to following matrix
m<-matrix(c(1,2,1,3,2,4), c(3,2))
i would like to transform it into the follo...
The standard stats::kruskal.test module allows to calculate the kruskal-wallis test on a dataset:
>>> data(diamonds)
>>> kruskal.test.test(price~carat, data=diamonds)
Kruskal-Wallis rank sum test
data: price by carat by color
Kruskal-Wallis chi-squared = 50570.15, df = 272, p-value < 2.2e-16
this is correct, it is giving me a prob...
Hello,
check this example:
> a = matrix(1:9, nrow = 3, ncol = 3, dimnames = list(LETTERS[1:3], LETTERS[1:3]))
> a
A B C
A 1 4 7
B 2 5 8
C 3 6 9
the table displays correctly. There are two different ways of writing it to file...
write.csv(a, 'a.csv') which gives as expected:
"","A","B","C"
"A",1,4,7
"B",2,5,8
"C",3,6,9
and write...
I'm creating a plot in R, and need to add an en dash to some axis labels, as opposed to your everyday hyphen.
axis(1, at=c(0:2), labels=c("0-10","11-30","31-70"))
I'm running R version 2.8.1 on Linux.
...
In SPSS, it is (relatively) easy to create a cross tab with multiple variables using the factors (or values) as the table heading. So, something like the following (made up data, etc.). Q1, Q2, and Q3 each have either a 1, a 2, or a 3 for each person. I just left these as numbers, but they could be factors, neither seemed to help solv...
I have two sparse matrices, m1 and m2:
> m1 <- Matrix(data=0,nrow=2, ncol=1, sparse=TRUE, dimnames=list(c("b","d"),NULL))
> m2 <- Matrix(data=0,nrow=2, ncol=1, sparse=TRUE, dimnames=list(c("a","b"),NULL))
> m1["b",1]<- 4
> m2["a",1]<- 5
> m1
2 x 1 sparse Matrix of class "dgCMatrix"
b 4
d .
> m2
2 x 1 sparse Matrix of class "dgCMatrix"
...
I have what may be a very simple question. I want to process a column of POSIXct objects from a dataframe and generate a vector of datetime strings. I tried to use the following sapply call
dt <- sapply(df$datetime, function(x) format(x,"%Y-%m-%dT%H:%M:%S"))
but to no avail. I keep getting the following error:
Error in prettyNu...
Hi,
I am trying to remove an object from the parent environment.
rm_obj <- function(obj){
a <-deparse(substitute(obj))
print (a)
print(ls(envir=sys.frame(-1)))
rm(a,envir=sys.frame(-1))
}
> x<-c(1,2,3)
> rm_obj(x)
[1] "x"
[1] "rm_obj" "x"
Warning message:
In rm(a, envir = sys.frame(-1)) : object 'a' not found
This will he...
Hi I'm having a bit of a problem programming R for Sweave, and the #rstats twitter group often points here, so I thought I'd put this question to the SO crowd. I'm an analyst- not a programmer- so go easy on me my first post.
Here's the problem: I am drafting a survey report in Sweave with R and would like to report the marginal return...
That's x \ y using mathematical notation. Suppose
x <- c(0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,1,2,1,1,1,3)
y <- c(0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,1,1)
How can I get a vector with ALL the values in x that are not in y. i.e the result should be:
2,1,1,3
There is a similar question here. However, none of the answers returns the re...
I have a data.frame:
df<-data.frame(a=c("x","x","y","y"),b=c(1,2,3,4))
> df
a b
1 x 1
2 x 2
3 y 3
4 y 4
What's the easiest way to print out each pair of values as a list of strings like this:
"x1", "x2", "y1", "y2"
...
Suppose we have generated a matrix A where each column contains one of the combinations of n elements in groups of k. So, its dimensions will be k,choose(n,k). Such a matrix is produced giving the command combn(n,k). What I would like to get is another matrix B with dimensions (n-k),choose(n,k), where each column B[,j] will contain the e...
Does anybody know of a way of generating a boxplot in R with a line (or another symbol) in the value corresponding to the mean?
Thank you!
...
I know I can use the RODBC library for accessing excel (.xls) docs from within Windows, but is there something similar for the Numbers program that come with iWorks? If not, what other solutions are there for easily editing a spreadsheet (like a lookup table) and accessing it within R? I know there the is an internal R editor, but I d...
I'm trying to access $a using the following example:
df<-data.frame(a=c("x","x","y","y"),b=c(1,2,3,4))
> df
a b
1 x 1
2 x 2
3 y 3
4 y 4
test_fun <- function (data.frame_in) {
print (data.frame_in[1])
}
I can now access $a if I use an index for the first column:
apply(df, 1, test_fun)
a
"x"
a
"x"
a
"y"
...
I'm writing an R package that's going to be used by others, so I'm trying to get this one right! I want to use roxygen for documentation and RUnit for unit testing, but I haven't used them before.
What packages exist (either on CRAN or elsewhere) that use either of these tools well?
...
I ran the following code in order to recode the variable. Unfortunately, when I move to run an logit model (using the Zelig package), I get an error message that the variable length differ for this variable.
## Independent Variable - Partisanship (ANES 2004)
data04$V043114
part <- data04$V043114
attributes(part)
summary(part)
partb < p...