Often in R, there are a dozen functions scattered across as many packages--all of which have the same purpose but of course differ in accuracy, performance, theoretical rigor, and so on.
How do you gather all of these in one place before you start your task?
So for instance: the generic plot function. Setting secondary ticks is much ea...
I'm looking to get a count for the following data frame:
> Santa
Believe Age Gender Presents Behaviour
1 FALSE 9 male 25 naughty
2 TRUE 5 male 20 nice
3 TRUE 4 female 30 nice
4 TRUE 4 male 34 naughty
of the number of children who believe. What command would I use to...
I noticed something in R ,
say pc is the result of applying PCA to a data matrix and
pc$x is my sample principal component matrix .
when try plot(pc$x) , it will only plot the first principal component (pc1) against the second (pc2) , but I actually have more than 2 principal components. how do I show all of them ?
...
I have a script called foo.R that includes another script other.R, which is in the same directory:
#!/usr/bin/env Rscript
print("Hello")
source("other.R")
But I want R to find that other.R no matter what the current working directory.
In other words, foo.R needs to know its own path. How can I do that?
...
I don't think I need to explain exactly what the code does. The point is that while performing the chisq.test outside the loop, I get a result like this (expected):
Chi-squared test for given probabilities
data: observed
X-squared = 185912, df = 5, p-value < 2.2e-16
but when I try to do the test in a loop, the expected resu...
In Emacs Speaks Statistics for R, how can the auto replacement of "_" with "<-" be turned off?
...
I'm using R to loop through a data frame, perform a calculation and to make a plot.
for(i in 2 : 15){
# get data
dataframe[,i]
# do analysis
# make plot
a <- plot()
}
Is there a way that I can make the plot object name 'a', using the value of 'i'? For example, a + "i" <- plot(). Then I want to add that to a vector so I have a seri...
I'm trying to use ggplot2 to create and label a scatterplot. The variables that I am plotting are both scaled such that the horizontal and the vertical axis are plotted in units of standard deviation (1,2,3,4,...ect from the mean). What I would like to be able to do is label ONLY those elements that are beyond a certain limit of standard...
I have data nested in to levels:
L1 L2 x1 x2 x3 x4
A This 20 14 12 15
A That 11 NA 8 16
A Bat Na 22 13 9
B This 10 9 11 6
B That 3 3 1 NA
B Bat 4 10 2 8
Now I want something simply - and I feel I have been able to do this just last month. But something has gone missing in my head: I want percentages (ignoring NA), ...
HI all,
I was trying to load a certain amount of Affymetrix CEL files, with the standard BioConductor command (R 2.8.1 on 64 bit linux, 72 GB of RAM)
abatch<-ReadAffy()
But I keep getting this message:
Error in read.affybatch(filenames = l$filenames, phenoData = l$phenoData, :
allocMatrix: too many elements specified
What's th...
I asked this question yesterday about storing a plot within an object. I tried implementing the first approach (aware that I did not specify that I was using qplot() in my original question) and noticed that it did not work as expected.
library(ggplot2) # add ggplot2
string = "C:/example.pdf" # Setup pdf
pdf(string,h...
I am trying to write a function that uses Newton's method (coefficients+(inverse hessian)*gradient) to iteratively find the coefficients for a loglinear model.
I am using the following code:
##reading in the data
dat<-read.csv('hw8.csv')
summary(dat)
# data file containing yi and xi
attach(dat)
##Creating column o...
still trying to get into the R logic... what is the "best" way to unpack the results from a function returning multiple values?
I can't do this apparently:
R> functionReturningTwoValues <- function() { return(c(1, 2)) }
R> functionReturningTwoValues()
[1] 1 2
R> a, b <- functionReturningTwoValues()
Error: unexpected ',' in "a,"
R> c(a...
I'm getting a result I don't understand in R.
If I use strptime with a year and day formatted %Y-%m (like "2009-12"), I get an NA result. But if I add a day, like "2009-12-01", and change the format string accordingly, I do get a result. Example:
> strptime("2009-12",format="%Y-%m")
[1] NA
> strptime("2009-12-03",format="%Y-%m-%d")
[1]...
In R, how do I make a (bar)plot's y axis labels parallel to the X axis instead of parallel to the Y axis?
...
Is there a function to get an index (row number and column number) for a matrix?
Suppose that I have a simple matrix:
a <- matrix(1:50, nrow=5)
Is there an easy way to get back something like c(3, 5) for the number "23", for instance? In this case, saying which(a==23) just returns 23.
This seems to work but I'm sure that there'...
I have the following setup:
emp <- structure(list(s = structure(c(1L, 2L, 2L, 2L, 7L, 7L, 3L, 4L, 4L, 4L, 4L, 8L, 8L, 8L, 9L, 9L, 9L, 9L, 10L, 5L, 5L, 6L), .Label = c("8", "24", "31", "78", "135", "142", "30", "98", "117", "123"), class = "factor", scores = structure(c(1, 2, 14, 3, 5, 17, 18, 20, 11, 13), .Dim = 10L, .Dimnames = list(c(...
let's say, I have this xml file:
<?xml version="1.0" encoding="UTF-8" ?>
<TimeSeries>
<timeZone>1.0</timeZone>
<series>
<header/>
<event date="2009-09-30" time="10:00:00" value="0.0" flag="2"></event>
<event date="2009-09-30" time="10:15:00" value="0.0" flag="2"></event>
<event date="2009-09-30" time="10:30:00" value...
I recently discovered that you can conditionally assign a value with an if-else block.
y <- if(condition) 1 else 2
I realise that the use case for this is limited: if you have vectorised code, you would use the ifelse function instead. There is a performance benefit: if-else runs about 35x faster than ifelse in the scalar case on my ...
I am trying to use a java package from R. Rjava provides a way to call java from R, but wrapping all the methods is impractical. Does anyone know of a script that generates wrappers for a package (say, by processing the relevant javadoc)?
...