Re: [R] Replacing values of a matrix with values from corresponding rows of another matrix

2013-07-15 Thread Blaser Nello
For small matrix you could use a for-loop. for (i in 1:nrow(randomized)){ randomized[i,randomized[i,]!=0] - sample(original[i,original[i,]!=0]) } randomized If you have a larger matrix sapply is probably faster randomized - t(sapply(1:nrow(randomized), function(i) {

Re: [R] Scatter plot with error bars

2013-06-28 Thread Blaser Nello
Are you sure, you want to calculate 68% confidence intervals? Use the add-argument in ?errorbar to add to the previous plot. errbar(x2,y2,y2+1.96*SD2, y2-1.96*SD2, col=green,pch=19, add=TRUE) Best, Nello -Original Message- From: r-help-boun...@r-project.org

Re: [R] Transpose of the rows

2013-06-26 Thread Blaser Nello
reshape(dta, idvar=id, timevar=name, direction=wide) -Original Message- From: r-help-boun...@r-project.org [mailto:r-help-boun...@r-project.org] On Behalf Of Nico Met Sent: Mittwoch, 26. Juni 2013 13:38 To: R help Subject: [R] Transpose of the rows Dear R users, I am using a big data

Re: [R] help with plotmeans (gplots)

2013-06-26 Thread Blaser Nello
The formula in plotmeans compares vectors. This should work: data - unlist(data) times - rep(1:15, 100) plotmeans(data~times) Best, Nello -Original Message- From: r-help-boun...@r-project.org [mailto:r-help-boun...@r-project.org] On Behalf Of Simone Gabbriellini Sent: Mittwoch, 26.

Re: [R] Creating a matrix with an unknown variable

2013-06-26 Thread Blaser Nello
You have to define a function. For instance: Afct - function(delta){ D - c(-1, -2/3, -1/3, 0, 1/3, 2/3, 1) Dmat - matrix(D, nrow=7, ncol=7) Smat - Dmat-t(Dmat) A - exp(-(Smat/delta)^2) return(A) } Afct(2) Also try to avoid loops... Best, Nello

Re: [R] How to include ifelse condition to adjust QPLOT font size

2013-06-25 Thread Blaser Nello
If you want the size to depend on the data, then size needs to be inside aes(...). For instance: stat_bin(aes(label = sprintf(%.01f, (..count../288)*100), size=ifelse(..count..0, 2.5, 0)) ,color=red, vjust=-0.5, angle=0, geom=text) A better approach would be not to plot the unnecessary things at

Re: [R] Avoiding loops using 'for' and pairwise comparison of columns

2013-06-24 Thread Blaser Nello
Here's a possible solution to avoid the loop k - as.matrix(expand.grid(1:ncol(x),1:ncol(x))) a1 - as.data.frame(matrix(sapply(1:nrow(k), function(n) agree(x[,k[n,]])$value), nrow=ncol(x))) colnames(a1) - colnames(x) rownames(a1) - colnames(x) identical(a, a1) [1] TRUE Or if you want to avoid

Re: [R] how to get growth rate of a (time series) data?

2013-06-19 Thread Blaser Nello
diff(test$Y)/(test$Y)[-1] calculates (Y(t)-Y(t-1))/Y(t). To get (Y(t)-Y(t-1))/Y(t-1) instead, use diff(test$Y)/(test$Y)[-length(test$Y)] or better diff(test[,Y])/test[-nrow(test), Y] -Original Message- From: r-help-boun...@r-project.org [mailto:r-help-boun...@r-project.org] On Behalf

Re: [R] Returning combine output from R loop

2013-05-31 Thread Blaser Nello
In line with what you are doing now, but saving the intermediate results you could use something like this. a3 - a0 for( i in 1:3) { a1 - a0$initial_size+a0$grow a2- cbind(sp=a0$sp,initial_size=a1+i,yr=i) a3 - cbind(a3, a2) } a3 However, I would suggest one of the following solutions

Re: [R] help on multivariate time series in R

2013-05-30 Thread Blaser Nello
Check out the CRAN task view on time series analysis http://cran.r-project.org/web/views/TimeSeries.html. There is a topic Multivariate Time Series Models. -Original Message- From: r-help-boun...@r-project.org [mailto:r-help-boun...@r-project.org] On Behalf Of Aakanksha Dahiya01 Sent:

Re: [R] adding class attributes to strings: works in a loop, but not directly

2013-05-29 Thread Blaser Nello
There are two separate issues that seem to be unclear. Concerning the class assignment: You cannot assign a class to a character string. You can assign a class to an object that contains a character string: a - b # ok class(a) - AONmode # not ok class(b) - AONmode Error in class(b) - AONmode

Re: [R] Indexing within by statement - different coloured lines in abline wanted..

2013-05-27 Thread Blaser Nello
abline(lm(Response1~Predictor,data=Site),col=colours[as.numeric(Site[1,1 ])]) -Original Message- From: r-help-boun...@r-project.org [mailto:r-help-boun...@r-project.org] On Behalf Of Tom Wilding Sent: Montag, 27. Mai 2013 12:40 To: r-help@r-project.org Subject: [R] Indexing within by

Re: [R] adding rows without loops

2013-05-23 Thread Blaser Nello
Merge should do the trick. How to best use it will depend on what you want to do with the data after. The following is an example of what you could do. This will perform best, if the rows are missing at random and do not cluster. DF1 - data.frame(X.DATE=rep(01052007, 7), X.TIME=c(2:5,7:9)*100,

Re: [R] convert a character string to a name

2013-05-23 Thread Blaser Nello
If you want to use the character string: attach(dftest) aggregate(cbind(sapply(x_test, get))~z, data=dftest, FUN=mean) # or with(dftest,aggregate(cbind(sapply(x_test, get)),list(z),FUN=mean)) detach(dftest) Cheers, Nello -Original Message- From: r-help-boun...@r-project.org

Re: [R] Error in colMeans with multiple column data.frame

2013-05-15 Thread Blaser Nello
It looks like you should use by instead of tapply. Anyway, if you use dput(data) for sharing your data, it is much easier to get help. Best, Nello -Original Message- From: r-help-boun...@r-project.org [mailto:r-help-boun...@r-project.org] On Behalf Of Simonas Kecorius Sent:

Re: [R] Looping through names of both dataframes and column-names

2013-04-26 Thread Blaser Nello
Here are two possible ways to do it: This would simplify your code a bit. But it changes the names of x_cs to cs.x. for (df in nls) { assign(df, cbind(get(df), cs=apply(get(df), 2, cumsum))) } This is closer to what you have done. for (df in nls) { print(df) for (var in names(get(df)))

Re: [R] Loop for main title in a plot

2013-04-25 Thread Blaser Nello
You could use bquote. Something like this: a-c(1,2,3,4) b-c(1,2,3,4) nTrials - length(a) for (trial in 1:nTrials) { plot(x=a[1:trial], y=b[1:trial], ylab=expression(paste(Apple[P])), xlab=expression(paste(Banana^th)), main=bquote(italic(i-)~.(trial)^th~choice))

Re: [R] NAMESPACE and imports

2013-04-19 Thread Blaser Nello
Not sure this fixes your problem, but as far as I can know (and can tell from the manual: http://cran.r-project.org/doc/manuals/r-release/R-exts.pdf), importFrom needs to know what functions you are importing [e.g. importFrom(Hmisc, latex) importFrom(stats, anova)]. -Original

Re: [R] Levels and labels in factor

2013-04-10 Thread Blaser Nello
Perhaps write.dta(..., convert.factors=string) might help. -Original Message- From: r-help-boun...@r-project.org [mailto:r-help-boun...@r-project.org] On Behalf Of chong shiauyun Sent: Mittwoch, 10. April 2013 10:01 To: r-help@r-project.org Subject: [R] Levels and labels in factor Hi R

Re: [R] non linear equation

2013-04-10 Thread Blaser Nello
I would suggest to try different starting values. The following works for instance: n2-nls(proc~f(cls,a,b,c,d),data=bline,start=list(a=1000,b=-1,c=4,d=1),t race=TRUE) -Original Message- From: r-help-boun...@r-project.org [mailto:r-help-boun...@r-project.org] On Behalf Of Jorge I Velez

Re: [R] conditional Dataframe filling

2013-03-27 Thread Blaser Nello
Here's a possible solution. dd - structure(list(a = c(TRUE, FALSE, FALSE), b = c(TRUE, FALSE, TRUE), c = c(TRUE, FALSE, FALSE), d = c(TRUE, TRUE, FALSE)), .Names = c(a, b, c, d), row.names = c(NA,

Re: [R] edit.data() read-only?

2013-03-26 Thread Blaser Nello
Try ?View() -Original Message- From: r-help-boun...@r-project.org [mailto:r-help-boun...@r-project.org] On Behalf Of Ted Harding Sent: Dienstag, 26. März 2013 11:09 To: r-help@r-project.org Subject: [R] edit.data() read-only? Greetings All. The function edit.data() allows a convenient

Re: [R] NaNS Error Message

2013-03-26 Thread Blaser Nello
Only positive values of n are allowed into the loop... More importantly, is n ever larger than 52??? Because that results in nk20 (for k=1) and undefined gamma(nk2). Same goes for sn, if n100. Next time you may also want to write a reproducible example! -Original Message- From:

Re: [R] Increase font size in plots

2013-03-26 Thread Blaser Nello
You can use the par function instead. require('vioplot') data1-rnorm(100) data2-rnorm(10) data3-rnorm(1000) par(cex.lab=2, cex.axis=2) vioplot(data1,data2,data3) Best, Nello -Original Message- From: r-help-boun...@r-project.org [mailto:r-help-boun...@r-project.org] On Behalf Of Alaios

Re: [R] %*% what does this mean

2013-03-25 Thread Blaser Nello
Matrix Multiplication ?%*% -Original Message- From: r-help-boun...@r-project.org [mailto:r-help-boun...@r-project.org] On Behalf Of Shane Carey Sent: Montag, 25. März 2013 13:31 To: r-help@r-project.org Subject: [R] %*% what does this mean Hi I was working with a script and I came

Re: [R] Weighted Kaplan-Meier estimates with R (with confidenceintervals)?

2013-03-25 Thread Blaser Nello
The two confidence intervals should be different. In the first model you have 3 failures and the second one you have 300. More failures results in narrower confidence intervals. -Original Message- From: r-help-boun...@r-project.org [mailto:r-help-boun...@r-project.org] On Behalf Of

Re: [R] spatstat error

2013-03-22 Thread Blaser Nello
Why do you first say min(Datos$x) and then give the numeric value of this minimum? Just delete all numerical values: danta=ppp(Datos$x, Datos$y, c(min(Datos$x), max(Datos$x)), c(min(Datos$y), max(Datos$y))) or if you really want to type the numeric constants (probably a bad idea)

Re: [R] Trouble embedding functions (e.g., deltaMethod) in other functions

2013-03-22 Thread Blaser Nello
Instead of NaN's, I get the error message: Error in eval(expr, envir, enclos) : object 'z' not found. The reason you get the NaN's is, because you defined z in your global environment. The deltaMethod doesn't find the z defined in your function. I don't know why or how to fix this. Somebody

Re: [R] All unique combinations

2013-03-21 Thread Blaser Nello
It isn't entirely clear to me if you want to remove duplicates or expand your matrix. Check ?unique or ?expand.grid. Here are some guesses of what you may want to do. unique(TimeIndex) expand.grid(as.data.frame(TimeIndex)) expand.grid(as.data.frame(unique(TimeIndex))) TimeIndex2 -

Re: [R] values for the scree plot (package psych)

2013-03-21 Thread Blaser Nello
The plot shows the variation for each component and mypc$sdev gives you the standard deviation. If you want to know the variation, use mypc$sdev^2. -Original Message- From: r-help-boun...@r-project.org [mailto:r-help-boun...@r-project.org] On Behalf Of Dimitri Liakhovitski Sent:

Re: [R] adaptIntegrate function

2013-03-21 Thread Blaser Nello
Under ?adaptIntegrate, you will find the link to http://ab-initio.mit.edu/wiki/index.php/Cubature#Infinite_intervals, where it says that Integrals over infinite or semi-infinite intervals is possible by a change of variables. -Original Message- From: r-help-boun...@r-project.org

Re: [R] How can I eliminate a loop over a data.table?

2013-03-19 Thread Blaser Nello
It seems like this is what you want to do, although there is probably a better way to do it. A.DT - data.table(a1 = A.DT[,a1], a2=sort(ifelse(B.DT[,b2] = N/2 B.DT[,b1] A.DT[nrow(A.DT):1,a1], B.DT[nrow(A.DT):1,b1],

Re: [R] Difficulty with UNIQUE

2013-03-15 Thread Blaser Nello
with(price.lookup, list(Price_Line)) is a list! Use unique(unlist(with(price.lookup, list(Price_Line -Original Message- From: r-help-boun...@r-project.org [mailto:r-help-boun...@r-project.org] On Behalf Of Barry King Sent: Freitag, 15. März 2013 09:34 To: r-help@r-project.org

Re: [R] Data manipulation

2013-03-15 Thread Blaser Nello
Is this what you want to do? D2 - expand.grid(Class=unique(D$Class), X=unique(D$X)) D2 - merge(D2, D, all=TRUE) D2$Count[is.na(D2$Count)] - 0 W - aggregate(D2$Count, list(D2$Class, D2$X), sum) W Best, Nello -Original Message- From: r-help-boun...@r-project.org

Re: [R] holding argument(s) fixed within lapply

2013-03-13 Thread Blaser Nello
One way is to use the do.call function. For example: ret2 - lapply(X=mylist2, FUN=do.call, what=function(...) f2(y=Y, ...)) Best, Nello -Original Message- Date: Tue, 12 Mar 2013 22:37:52 -0400 From: Benjamin Tyner bty...@gmail.com To: r-help@r-project.org Subject: Re:

Re: [R] R function for estimating historical-VaR

2013-03-04 Thread Blaser Nello
Does it just not work or does it not do the right thing? The reason it doesn't work is that you are writing 'T = length(returns) x_foc = vector(length=n) N = T-(n+1)' on one line instead of using three lines. However, your description of what you want to do also doesn't seem to correspond to