[R] faster way?
Hi, Is there a faster way to do this? It takes forever, even on a moderately sized dataset. n - dim(dsn)[1] dsn2 - dsn[order(-dsn$xhat),] dsn2[1, cumx] - dsn2[1, xhat] for (i in 2:n) { dsn2[i, cumx] - dsn2[i - 1, cumx] + dsn2[i, xhat] } [[alternative HTML version deleted]] __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
[R] colorRamp
Hi, I am using colorRamp in the following way. I am *sure* there is a better way to do this, so if you'd be so kind to show me the true R way: Step 0: Create a new variable, say, x, that maps some other continuous variable I have onto the [0,1] line. Step 1: Store the result from colorRamp (a function), into, say, test test - colorRamp(mypalette) Step 2: In my data frame, data data$colorTemp - test(data$x) Step 3: Write a new function bob - function(temp) { rgb(temp[1],temp[2],temp[3],maxColorValue=255) } Step 4: for (i in 1:dim(data)[1]) data[i,color] - bob(data[i, colorTemp]) Step 5: map(states, region=data$region, fill=T, col=data$color) Thanks in advance! Rick __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] princomp/biplot
Infinite values? On Sep 2, 2006, at 3:48 PM, Nair, Murlidharan T wrote: I am getting the following error when I an trying to use princomp princomp(unique.data) Error in cov.wt(z) : 'x' must contain finite values only What do I look for? __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting- guide.html and provide commented, minimal, self-contained, reproducible code. __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
[R] working with summarized data
The data sets I am working with all have a weight variable--e.g., each row doesn't mean 1 observation. With that in mind, nearly all of the graphs and summary statistics are incorrect for my data, because they don't take into account the weight. For example median is incorrect, as the quantiles aren't calculated with weights: sum( weights[X median(X)] ) / sum(weights) This should be 0.5... of course it's not. Unfortunately, it seems that most(all?) of R's graphics and summary statistic functions don't take a weight or frequency argument. (Fortunately the models do...) Am I completely missing how to do this? One way would be to replicate each row proportional to the weight (e.g. if the weight was 4, we would 3 additional copies) but this will get prohibitive pretty quickly as the dataset grows. Thanks in advance! __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] working with summarized data
Unfortunately, it seems that most(all?) of R's graphics and summary statistic functions don't take a weight or frequency argument. (Fortunately the models do...) I have been been meaning to add this functionality to my graphics package ggplot (http://had.co.nz/ggplot), but unfortunately haven't had time yet. I'm guessing you want something like: * scatterplot: scale size of point according to weight (can do) * bar chart: bars should have height proportional to weight (can do) * histogram: area proportion to weighting variable (have some half finished code to do) * smoothers: should automatically use weights * boxplot: use weighted quantiles/letter statistics (is there a function for that?) What else is there? densityplot is the only other one I can think of at the moment... With the rest of those, I could certainly live without it though! Thanks! __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.