For 1,000,000 observations, I observed a discrete event, X, 3 times for the control group and 10 times for the test group.
I need to preform a Chi square test of independence in Matlab. This is how you would do it in r:
m <- rbind(c(3, 1000000-3), c(10, 1000000-10))
# [,1] [,2]
# [1,] 3 999997
# [2,] 10 999990
chisq.test(...
I'm using reshape in R to compute aggregate statistics over columns of a data.frame. Here's my data.frame:
> df
a a b b ID
1 1 1 1 1 1
2 2 3 2 3 2
3 3 5 3 5 3
which is just a little test data.frame to try and understand the reshape package. I melt, and then cast, to try and find the mean of the as and the bs:
> melt(df, id = "ID...
Another rather basic question for which I can't find a definitive answer online:
I have a data frame containing (in random places) a character value (say "foo")that I want to replace with a NA.
What's the best way to do so across the whole data frame?
Thanks,
Roberto
...
I noticed that in the library folder of my Revolution R installation that there are some packages unique to Revolution. So I copied them to my regular R distribution and those packages worked fine.
Can I use the Revolution packages free of charge in a commercial environment? My understanding is that anyone who contributes to R needs to...
As a recent graduate, I was considering doing some freelance data analysis work. While there are numerous firms offering similar services, I would direct my services towards small "mom and pop" business and the self-employed.
Does anyone have experiance with this? What's been your experiance?
...
I would like to use Perl to take a previously generated SPSS syntax file and format it for use in an R environment.
This is probably a very simple task for those familiar with Perl and regex, but I am stumbling.
The steps as I've laid them out for this Perl script are as follows:
Read in SPSS file
Find appropriate chunks of SPSS fil...
In a loop, I am trying to get a column vector of class factor into numeric.
If there were not a loop, the code would look like
c1$values <- as.numeric(as.character(c1$values))
But how do I reference c1$values with a loop? I have tried two approaches:
get(paste('c',i,"$values", sep=""))
just does not work even outside the loop, wh...
I have an array with dates as indices which I'm plotting. I'd like to plot a LOESS curve along with it. However, the input for loess is a formula. Is there a good way to define a formula from array index to value which I can then give to the loess function?
...
Hi,
Is this method broken in R? I am using it to find roots of the following function:
f(x) = 2.5*exp(-0.5*(2*0.045 - x)) + 2.5*exp(-0.045) + 2.5*exp(-1.5*x) - 100
It is giving an answer of -38.4762403 which is not even close (f(x) = 2.903809e+25 for x=-38.4762403). The answer should be around 0.01-0.1. This function should converge..
...
I have this
for(i in 1:10)
and within it, I have a data frame:
e.g.
df<-1:100
and I want to assign the dataframe to a specific name which I want to create
something like: (not that it works)
paste("name", variable[i])<- df
Edit:
How would I then go about accessing those constructed values in another loop (assuming i've us...
Hi everyone,
I use SPSS everyday but have really been trying to learn R. The major thing that is holding me back is my need to easily generate tables, banners, and cross-tabs for the market research that I do. I love the Custom Tables option in SPSS and am looking for advice on how to replicate it with R.
I believe R has a ton of adv...
I want to save the R output to a specific place, but what I want to do is add the time and day to the file(according to the system time).
29-Jul-2010 15.35.txt
anyway to do it?
I know about Sys.time and date() but they both contain : which windows xp doesn't like.
...
What is a good library for wavelets in R?
...
In a loop, I am trying to perform a simple renaming of the variables in a df.
Without the loop, this works perfectly:
names(c1) <- c("sales", "month")
With a loop-friendly approach ("1" in place of i in the dry-run example) the following correctly references names(c1):
names(get(paste("c","1", sep="")))
but as I write the whole op...
Hello,
I need to remove the ticks and major line from a generated axis using grid.yaxis.
According to ?grid.yaxis there is an "edits" parameter that will let me configure the "major", "ticks" and "labels".
However, I cant find how to use the edits parameter.
Here's some example code that will draw an axis in the center.
grid_test_axi...
When I run R scripts I go do something else on a different desktop. If I don't check frequently, I never know when something is finished. Is there a way to invoke a beep (like a system beep) or get R to play a sound or notify growl via some code at the end of my script?
...
I have a list of vectors which are time series of inequal length. My ultimate goal is to plot the time series in a ggplot2 graph. I guess I am better off first merging the vectors in a dataframe (where the shorter vectors will be expanded with NAs), also because I want to export the data in a tabular format such as .csv to be perused by ...
How can I make sqlSave to write only a subset of columns.
I've a (MS-Access) table with e.g. columns A, B, C en D and if I send a sqlSave command with a data frame with columns A, B en D (no C) I get the message:
Error in odbcUpdate(channel, query, mydata, coldata[m, ], test = test, :
missing columns in 'data'
Calls: sqlSave -> sqlw...
I am looking to extract the p-value generated from an anova in R.
Here is what I am running:
test <- aov(asq[,9] ~ asq[,187])
summary(test)
Yields:
Df Sum Sq Mean Sq F value Pr(>F)
asq[, 187] 1 3.02 3.01951 12.333 0.0004599 ***
Residuals 1335 326.85 0.24483
---
Signif. codes: 0 ...
I'm trying to calculate asset-weighted returns by asset class. For the life of me, I can't figure out how to do it using the aggregate command.
My data frame looks like this
dat <- data.frame(company, fundname, assetclass, return, assets)
I'm trying to do something like (don't copy this, it's wrong):
aggregate(dat, list(dat$asset...