[R] clogit, modeling change...
Hi, I've set up a discrete choice experiment on magazine preference following the guidelines from Azaiki. H Nishimura K. Design and Analysis of Choice Experiments Using R. A Brief Introuction from Agricultural Informatin Research 17(2), 2008. 86-94. I'm working with the clogit() function from the survival package. I've set up the data like this: Person Id / Choice Set / Stated Preference ... (the dots being magazine characteristics with price, print quality etc) 1 1 0 ... 1 2 0 ... 1 3 1 ... 2 1 0 ... 2 2 1 ... 2 3 0 ... 3 1 1 ... 3 2 0 ... 3 3 0 ... ... ... The clogit() gives me coefficients etc. However, the literature states that one can model change in, say, price. Answering questions like How many will read magazine 2 when price falls with $2?. Can someone please outline a simple example on how to calculate / model such a change? TIA // stefan __ R-help@r-project.org 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] Manually modifying an hclust dendrogram to remove singletons
Hi all, Thanks for the replies - they have helped shaped my thinking and are starting to push me in a better direction. Maybe I should explain a little more about what I'm trying to achieve. I am analysing satellite data across the global ocean, and am interested in trying to classify areas of the ocean according to the similarity between the pixels. Singletons in this case therefore represent individual pixels that are different to the rest in terms of the similarity metric, but aren't really all that interesting in terms of the broad picture - I consider them outliers or noise. However, they are annoying when it comes to splitting up the dendrogram, because I'm mainly interested in the reclassification of large areas of ocean at each step, rather than changes in the similarity. The dynamic tree-cut approach looks like a promising and sensible solution to the problem - I'll see if I can get something out of it. However, this discussion has started me wondering how I can use the spatial proximity of the pixels in the analysis - does anyone have any insights? Can the WGCNA approach be used in such a context? Best wishes, Mark Payne __ R-help@r-project.org 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] Fwd: help needed
On 05/25/2012 02:45 AM, QAMAR MUHAMMAD UZAIR wrote: ... I want to reshape it in the following FORMAT 19671968196919701971197219731974 10.870.870.870.870.71 20.870.870.870.870.72 OBVIOUSLY, I HAVE A LARGE AMOUNT OF DATA TO WORK WITH.i would also like to take into account the effect of leap year. For example if 1969 in a leap year then the column under it, has to have 1 extra reading. Hi Qamar, You can do something like this, assuming that your data frame is named qmu and the two columns are named V1 and V2: # extract years from the dates qmu$year-as.numeric(sapply(strsplit(as.character(qmu$V1),[.]),[,3)) # get a vector of the unique years uyears-unique(qmu$year) # make an empty list newqmu-list() # populate the list year by year for(i in 1:length(uyears)) newqmu[[i]]-qmu$V2[qmu$year==uyears[i]] This will give you a list with the same characteristics as you described. You can't have a data frame with different column lengths, so you would have to pad the shorter columns with NA values if you want a data frame. Jim __ R-help@r-project.org 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] levels of comma separated data
analyst41 at hotmail.com analyst41 at hotmail.com writes: I have a data set that has some comma separated strings in each row. I'd like to create a vector consisting of all distinct strings that occur. The number of strings in each row may vary. Thanks for any help. # # # Some data: d - data.frame(id = 1:5, text = c('one,two', 'two,three,three,four', 'one,three,three,five', 'five,five,five,five', 'one,two,three'), stringsAsFactors = FALSE ) # # # A function. I'm not a black belt at this, so there # are probably a more efficient way of writing this. fcn - function(x){ a - strsplit(x, ',') # Split the string by comma unique(a[[1]]) # Uniquify the vector } # # # Use the function with sapply. sapply(d[,2], fcn) __ R-help@r-project.org 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] Collecting results of a test with array
Dear contributors I have tried this experiment: x-c() for (i in 1:12){ x[i]-list(cbind(x1[i],x2[i])) #this is a list of 12 couples of time series I am using to perform a test } # that compares them 2 by 2 # # #trace statistic test-data.frame() cval-array( , dim=c(2,3,12)) for (i in 2:12){ for (k in 1:2){ for (j in 1:3){ result[k,j,i]- ((ca.jo(data.frame(x[i]),ecdet=none,type=trace, spec=longrun,K=2))@cval[k,j]) }}} I have a problem in collecting the results of a test. The function ca.jo creates an object with various attributes, one of which is the cval that i can access through @cval. The attribute cval is an object of dimension 2X3. I am running recursively the test with ca.jo for 12 couples of time series, so I have an output of 12 matrices of 2X3 elements and I would like to create an object like an array of dimension (2,3,12) which contains each matrix @cval produced by ca.jo for the 12 subjects that i tested. Can anyone help me with that? I hope my explanation of the problem is clear. Thanks in advance for any help. -- Francesca -- Francesca Pancotto, PhD Università di Modena e Reggio Emilia Viale A. Allegri, 9 40121 Reggio Emilia Office: +39 0522 523264 Web: http://www2.dse.unibo.it/francesca.pancotto/ -- [[alternative HTML version deleted]] __ R-help@r-project.org 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] glm(weights) and standard errors
Weighting can be confusing: There are three standard forms of weighting which you need to be careful not to mix up, and I suspect that the imputation weights are really a 4th version. First, there is case (replication) vs. precision weighting. A weight of 10 means one of - I have 10 observations identical to this one - This observation has a variance of sigma^2/10 as if it were the average of 10 observations. There are also sampling weights: - For each observation like this, I have 10 similar observations in the population (and I want to estimate a population parameter like the national average income or the percentage of votes at a hypothetical general election). What R does in lm/glm is precision weights. Notice that when the variance is estimated from data, the weights are really only relative: if all observations are weighted equally (all 10, say), you get a 10-fold increase in the estimated sigma^2 and a tenfold decrease in the unscaled variance-covariance matrix. So the net result is that the standard errors are the same (but they won't be if the weights are unequal). The three weighting schemes share the same formula for the estimates, but differ both in the estimated variance and df, and in the formula for the standard errors. Sampling weights are the domain of the survey package, but I don't think it does replication weights (someone called Thomas may chime in and educate me otherwise). I'm not quite sure, but I think you can get from a precision-weighted analysis to a case-weighted one just by adjusting the DF for error (changing the residual df to df+sum(w)-n, and sigma^2 proportionally). Imputation weights look like the opposite of case weights: You give 10 observations when in fact you have only one. An educated guess would be that you could do something similar as for case weights -- in this case sum(w) will be much less than n, so you will decrease the residual rather than increase it. I get this nagging feeling that it might still not be quite right, though -- in the cases where the imputations actually differ, do we get the extra variability of the variance right? Or maybe we don't need to care. There is a literature on the subject On May 25, 2012, at 09:21 , ilai wrote: I'm confused (I bet David is too). First and last models are the same, what do SE's have to do with anything ? naive - glm(extra ~ group, data=sleep) imputWrong - glm(extra ~ group, data=sleep10) imput - glm(extra ~ group, data=sleep10,weights=rep(0.1,nrow(sleep10))) lapply(list(naive,imputWrong,imput),anova) sapply(list(naive,imuptWrong,imput),function(x) vcov(x)[1,1]/vcov(x)[2,2]) # or another way to see it (adjust for the DF) coef(summary(naive))[2,2] - sqrt(198)/sqrt(18) * coef(summary(imput))[2,2] coef(summary(naive))[2,2] - sqrt(198)/sqrt(18) * coef(summary(imputWrong))[2,2] Are you sure you are interpreting Wood et al. correctly ? (I haven't read it, this is not rhetorical) On Wed, May 23, 2012 at 7:49 PM, Steve Taylor steve.tay...@aut.ac.nz wrote: Re: coef(summary(glm(extra ~ group, data=sleep[ rep(1:nrow(sleep), 10L), ] ))) Your (corrected) suggestion is the same as one of mine, and doesn't do what I'm looking for. -Original Message- From: David Winsemius [mailto:dwinsem...@comcast.net] Sent: Tuesday, 22 May 2012 3:37p To: Steve Taylor Cc: r-help@r-project.org Subject: Re: [R] glm(weights) and standard errors On May 21, 2012, at 10:58 PM, Steve Taylor wrote: Is there a way to tell glm() that rows in the data represent a certain number of observations other than one? Perhaps even fractional values? Using the weights argument has no effect on the standard errors. Compare the following; is there a way to get the first and last models to produce the same results? data(sleep) coef(summary(glm(extra ~ group, data=sleep))) coef(summary(glm(extra ~ group, data=sleep, weights=rep(10L,nrow(sleep) Here's a reasonably simple way to do it: coef(summary(glm(extra ~ group, data=sleep[ rep(10L,nrow(sleep)), ] ))) -- David. sleep10 = sleep[rep(1:nrow(sleep),10),] coef(summary(glm(extra ~ group, data=sleep10))) coef(summary(glm(extra ~ group, data=sleep10, weights=rep(0.1,nrow(sleep10) My reason for asking is so that I can fit a model to a stacked multiple imputation data set, as suggested by: Wood, A. M., White, I. R. and Royston, P. (2008), How should variable selection be performed with multiply imputed data?. Statist. Med., 27: 3227-3246. doi: 10.1002/sim.3177 Other suggestions would be most welcome. __ R-help@r-project.org 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@r-project.org mailing list
Re: [R] RODBC connect to Excel (64-bit Windows 7)
If you're using (R)ODBC, you need a workflow that is either 32bit or 64-bit, but not mixed. On a 64-bit Windows 7 machine, I can use 32-bit R and RODBC to read and write 32-bit Excel (etc) and similarly xlsreadwrite works 32-bit. I can use 64-bit R and XLConnect to read and write from excel spreadsheets that then open nicely in 32-bit Excel. Just requires a little care to know whether your workflow is 32 or 64 bit. Paul - Paul Bivand Associate Director of Analysis and Statistics Centre for Economic Social Inclusion 3rd floor, 89 Albert Embankment, London SE1 7TP Inclusion website www.cesi.org.uk On 23 May 2012 18:20, IzRey brett.israel...@gmail.com wrote: andrija djurovic djandrija at gmail.com writes: Hi to all. .. Thanks in advance Andrija I am having the exact same problem. Any luck with this yet? __ R-help@r-project.org 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@r-project.org 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] R+Stata batch mode
Dear R help, I am using Stata, and I use a Stata ado file (Rsource) to run R in batch mode within Stata Everything works fine except for the fact that I cannot export the graphics that I obtain with my computations written in my R source file I believe this is related to the global Rterm_options `--vanilla' that I need to precise to Rsource (otherwise it does not work) ... What kind of options should I precise instead in order to be able to use the R line : png('mygraph.png') dev.off() ? At the moment the file obtained (mygraph.png) is void ... but strangely enough the pictures are exported in a pdf file... which is not what I want anyway Any help ? Many thanks Best Regards [[alternative HTML version deleted]] __ R-help@r-project.org 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] Multiple cbind according to filename
Hi all, I'm just a beginner with R but I have not been able to search for any relevant answer to my problem. I apologize if it has in fact been asked before. Recently I've realized that I need to combine hundreds of pairs of data frames. The filenames of the frames I need to combine have unique strings. This is my best guess as to the approach to take: filenames-list.files() filenames [1] a1.csv a2.csv b1.csv b2.csv c1.csv c2.csv alldata-lapply(filenames, read.csv, header=TRUE) names(alldata)-filenames summary(alldata) Length Class Mode a1.csv 27 data.frame list a2.csv 27 data.frame list b1.csv 27 data.frame list b2.csv 27 data.frame list c1.csv 27 data.frame list c2.csv 27 data.frame list My next step would be to cbind files that share a common string at the beginning, such as: cbind(alldata[[1]],alldata[[2]]) cbind(alldata[[3]],alldata[[4]]) cbind(alldata[[5]],alldata[[6]]) ... but file list is hundreds of files long (but is sorted alphanumerically such as in this example - not sure if this is relevant). If I had to guess, I'd do something like this: which(names(alldata)==...), to identify which elements to combine based on unique filename OR x-seq(1,length(alldata), 2) y=x+1 z-cbind(x,y) z x y [1,] 1 2 [2,] 3 4 [3,] 5 6 to use the frame created in z to combine based on rows, then use a looped cbind function (or *apply function with nested cbind function?) using the previously returned indexes to create my new combined data frames, including a step to write the frames to a new unique filename (not sure how to do that step in this context). These last steps I've tried a lot of code but nothing worth mentioning as it has all failed miserably. I appreciate the help, M [[alternative HTML version deleted]] __ R-help@r-project.org 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] Manually modifying an hclust dendrogram to remove singletons
Hi, Thanks for the replies - they have helped shaped my thinking and are starting to push me in a better direction. Maybe I should explain a little more about what I'm trying to achieve. I am analysing satellite data across the global ocean, and am interested in trying to classify areas of the ocean according to the similarity between the pixels. Singletons in this case therefore represent individual pixels that are different to the rest in terms of the similarity metric, but aren't really all that interesting in terms of the broad picture - I consider them outliers or noise. However, they are annoying when it comes to splitting up the dendrogram, because I'm mainly interested in the reclassification of large areas of ocean at each step, rather than changes in the similarity. The dynamic tree-cut approach looks like a promising and sensible solution to the problem - I'll see if I can get something out of it. However, this discussion has started me wondering how I can use the spatial proximity of the pixels in the analysis - does anyone have any insights? Can the WGCNA approach be used in such a context? Best wishes, Mark Payne __ R-help@r-project.org 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] levels of comma separated data
On May 25, 4:46 am, Stefan ste...@inizio.se wrote: analyst41 at hotmail.com analyst41 at hotmail.com writes: I have a data set that has some comma separated strings in each row. I'd like to create a vector consisting of all distinct strings that occur. The number of strings in each row may vary. Thanks for any help. # # # Some data: d - data.frame(id = 1:5, text = c('one,two', 'two,three,three,four', 'one,three,three,five', 'five,five,five,five', 'one,two,three'), stringsAsFactors = FALSE ) # # # A function. I'm not a black belt at this, so there # are probably a more efficient way of writing this. fcn - function(x){ a - strsplit(x, ',') # Split the string by comma unique(a[[1]]) # Uniquify the vector} # # # Use the function with sapply. sapply(d[,2], fcn) Thanks - but this solves a slightly different problem - it outputs the unique values in each row. I want a list of the unique values in the whole data frame. In this case the output should be a single vector = c(one,two,three,four,five). __ r-h...@r-project.org mailing listhttps://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guidehttp://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. __ R-help@r-project.org 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] set tkscale by tkentry
Hi Greg and jverzaniNWBKZ, thank you very much for your help. I already thought about your solution jverzaniNWBKZ. I hoped I could find a simpler solution (such as refering to the global variable of scale). As this is not possible for some intervals, I will take your solution. Thanks again for the quick answers!!! jverzaniNWBKZ wrote Greg Snow 538280 at gmail.com writes: I believe that what is happening is that when you try to edit the entry widget any intermediate values get sent to the slider widget which then checks to see if they are in the allowable range and if it is not then it sets the value to either the minimum and maximum and sends that back to the entry widget while you are still trying to edit it. Even if you highlight a single digit and try to replace it with a different digit it first deletes the highlighted digit resulting in a number smaller than the minimum of the slider which then updates the entry widget to the minimum before the new digit can go in, then adding the new digit makes it larger than the slider maximum. Greg is right. You might try validating on focusout, rather than the key, but this is easy enough to do in R code, rather than let tcl do that work: a - 306870; b - 3026741 tt-tktoplevel() varalpha - tclVar(a) charalpha - tclVar(as.character(a)) scale - tkscale(tt, from=a, to=b, resolution=1, label=alpha, variable=varalpha, showvalue=TRUE, orient=horiz) ed - tkentry(tt, textvariable=charalpha) tkpack(ed) tkpack(scale) ## connect tkconfigure(scale, command=function(...) { tclvalue(charalpha) - as.character(tclvalue(varalpha)) }) valid_input - function(...) { val - as.numeric(tclvalue(charalpha)) if(a = val val = b) { message(set to , val) tclvalue(varalpha) - val } else { message(not valid...) tkfocus(ed) } } tkbind(ed, Return, valid_input) tkbind(ed, FocusOut, valid_input) __ R-help@ 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. -- View this message in context: http://r.789695.n4.nabble.com/set-tkscale-by-tkentry-tp4631174p4631281.html Sent from the R help mailing list archive at Nabble.com. __ R-help@r-project.org 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] Using robust std.errors instead of OLS std.errors in regression
I have to make a robust resettest. I have already calculated the robust standard errors but I don't know how to use these in my resettest. I have made the following code: labmodel2 - lm(formula = log(L) ~ log(W) + log(K) + log(Y), data=labordat) hc.cv - hccm(labmodel2, hc0) hc.cv robusttest - coeftest(labmodel2, hc.cv) robusttest But how to use the robust standard errors in a RESET test? Thank you :D -- View this message in context: http://r.789695.n4.nabble.com/Using-robust-std-errors-instead-of-OLS-std-errors-in-regression-tp4631293.html Sent from the R help mailing list archive at Nabble.com. __ R-help@r-project.org 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] KS test and plot max distance between two ecdf curves
Given this example a-c(0,70,50,100,70,650,1300,6900,1780,4930,1120,700,190,940, 760,100,300,36270,5610,249680,1760,4040,164890,17230,75140,1870,22380,5890,2430) b-c(0,0,10,30,50,440,1000,140,70,90,60,60,20,90,180,30,90, 3220,490,20790,290,740,5350,940,3910,0,640,850,260) out-ks.test(log10(a+1),log10(b+1)) # (1) max distance D out$statistic f.a-ecdf(log10(a+1)) f.b-ecdf(log10(b+1)) # (2) max distance D max(abs(f.a(x)-f.b(x))) plot(f.a, verticals=TRUE, do.points=FALSE, col=red) plot(f.b, verticals=TRUE, do.points=FALSE, col=green, add=TRUE) my questions are: - how to plot the max distance between the two ecdf curves in the above given graph? (sorry but for some reasons I can’t manage that…) -why of the difference between the max distance D calculated with ks.test() as in (1) and the max distance “manually” D calculated as in (2)? (I guess it has something to do with the fact that KS is obtained with a maximisation that depends on the range of x values not necessarly coincident in the two different approaches) thanks max -- View this message in context: http://r.789695.n4.nabble.com/KS-test-and-plot-max-distance-between-two-ecdf-curves-tp4631285.html Sent from the R help mailing list archive at Nabble.com. __ R-help@r-project.org 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] edgeR Time Series
I have a time serie of 10 time points, including Treated and Control samples. In total my data contains 20 columns. I have grouped Treated and Control samples into 3 categories, Early, mid and late. I want to compare The early Treated Group with the early Control group, The mid Treated with the mid Control and so on... Is this the correct way of making a design matrix? I am uncertain about the results I get. Time - factor(c(Early,Early,Early,Early,Mid,Mid,Late,Late,Late,Late,Early,Early,Early,Early,Mid,Mid,Late,Late,Late,Late)) Condition - factor(c(T,T,T,T,T,T,T,T,T,T,C,C,C,C,C,C,C,C,C,C)) data.frame(Sample=colnames(y),Time,Condition) Sample Time Condition 1 T0h Early T 2 T0.25h Early T 3 T0.5h Early T 4 T1h Early T 5 T2h Mid T 6 T3h Mid T 7 T6h Late T 8T12h Late T 9T24h Late T 10 T48h Late T 11C0h Early C 12 C0.25h Early C 13 C0.5h Early C 14C1h Early C 15C2h Mid C 16C3h Mid C 17C6h Late C 18 C12h Late C 19 C24h Late C 20 C48h Late C -- View this message in context: http://r.789695.n4.nabble.com/edgeR-Time-Series-tp4631289.html Sent from the R help mailing list archive at Nabble.com. __ R-help@r-project.org 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] Collecting results of a test with array
My first thought is to unlist them and stick them in a vector and then to form that vector into an array of the desired shape. Something like this: x - vector(list,12) for(i in 6*(1:12)){x[[i/6]] - matrix(i:(i+5), ncol = 2) } print(x) x.out - array(unlist(x), dim = c(2,3,12)) print(x.out) which I believe is what you want. [If not, I think it will at least get you started] Hope this helps, Michael On Fri, May 25, 2012 at 5:21 AM, Francesca francesca.panco...@gmail.com wrote: Dear contributors I have tried this experiment: x-c() for (i in 1:12){ x[i]-list(cbind(x1[i],x2[i])) #this is a list of 12 couples of time series I am using to perform a test } # that compares them 2 by 2 # # #trace statistic test-data.frame() cval-array( , dim=c(2,3,12)) for (i in 2:12){ for (k in 1:2){ for (j in 1:3){ result[k,j,i]- ((ca.jo(data.frame(x[i]),ecdet=none,type=trace, spec=longrun,K=2))@cval[k,j]) }}} I have a problem in collecting the results of a test. The function ca.jo creates an object with various attributes, one of which is the cval that i can access through @cval. The attribute cval is an object of dimension 2X3. I am running recursively the test with ca.jo for 12 couples of time series, so I have an output of 12 matrices of 2X3 elements and I would like to create an object like an array of dimension (2,3,12) which contains each matrix @cval produced by ca.jo for the 12 subjects that i tested. Can anyone help me with that? I hope my explanation of the problem is clear. Thanks in advance for any help. -- Francesca -- Francesca Pancotto, PhD Università di Modena e Reggio Emilia Viale A. Allegri, 9 40121 Reggio Emilia Office: +39 0522 523264 Web: http://www2.dse.unibo.it/francesca.pancotto/ -- [[alternative HTML version deleted]] __ R-help@r-project.org 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@r-project.org 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] Java problem - XLConnect/xlsx package
Hi, I hope you guys can help me, I already posted this question on stackoverflow but did not get any help (which worked). And I need to solve this problem as quick as possible: In our firm we migrated to windows 7 (64-bit) and also updated the java packages (1.6.0_24) and also R (to 2.15). Then I tried to install my packages which i use daily and one of em is the xlsx package. But if I load the package I get the following error: Error : .onAttach in attachNamespace() Error: .jnew( org/apache/poi/xssf/usermodel/XSSFWorkbook) I did seth a path variable to the java folder (where the jvm.dll is). Then I tried to install the XLConnect package (which would not be that difficult to re-write my code to that package), this package loads without problems, but if I try to load a workbook an error comes up: Error: NoSuchMethodError (Java): org.apache.xmlbeans.XmlOptions. setSaveAggressiveNamespaces()Lorg/apache/xmlbeans/XmlOptions; Since I've never worked with Java (not as a developer) I have no idea what I can do to solve the problem. I hope you can help me! Thank you very much. Best regards Rainer Here's my sessionInfo(): R version 2.15.0 (2012-03-30) Platform: i386-pc-mingw32/i386 (32-bit) locale: [1] LC_COLLATE=German_Austria.1252 LC_CTYPE=German_Austria.1252 [3] LC_MONETARY=German_Austria.1252 LC_NUMERIC=C [5] LC_TIME=German_Austria.1252 attached base packages: [1] stats graphics grDevices utils datasets methods base other attached packages: [1] XLConnect_0.1-9 XLConnectJars_0.1-4 rJava_0.9-3 knitr_0.5 loaded via a namespace (and not attached): [1] codetools_0.2-8 digest_0.5.2evaluate_0.4.2 formatR_0.4 highlight_0.3.1 [6] parser_0.0-14 plyr_1.7.1 Rcpp_0.9.10 stringr_0.6 tools_2.15.0 [[alternative HTML version deleted]] __ R-help@r-project.org 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] R+Stata batch mode
On May 25, 2012, at 14:46 , Francesco wrote: Dear R help, I am using Stata, and I use a Stata ado file (Rsource) to run R in batch mode within Stata Everything works fine except for the fact that I cannot export the graphics that I obtain with my computations written in my R source file I believe this is related to the global Rterm_options `--vanilla' that I need to precise to Rsource (otherwise it does not work) ... What kind of options should I precise instead in order to be able to use the R line : png('mygraph.png') dev.off() ? At the moment the file obtained (mygraph.png) is void ... but strangely enough the pictures are exported in a pdf file... which is not what I want anyway Any help ? Apologies if I'm being silly, but: You do know that the graphics commands need to go _between_ png() and dev.off()? Otherwise, perhaps the png device didn't start. There should be an error message in the output file in that case. -- Peter Dalgaard, Professor Center for Statistics, Copenhagen Business School Solbjerg Plads 3, 2000 Frederiksberg, Denmark Phone: (+45)38153501 Email: pd@cbs.dk Priv: pda...@gmail.com __ R-help@r-project.org 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] RODBC connect to Excel (64-bit Windows 7)
On Sun, Dec 4, 2011 at 9:40 AM, andrija djurovic djandr...@gmail.com wrote: Hi to all. I have a problem to connect to an Excel database using RODBC. There are tips for RODBC as well as some alternatives listed here: http://rwiki.sciviews.org/doku.php?id=tips:data-io:ms_windows -- Statistics Software Consulting GKX Group, GKX Associates Inc. tel: 1-877-GKX-GROUP email: ggrothendieck at gmail.com __ R-help@r-project.org 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] R memory allocation
Dear All, I am running R in a system with the following configuration *Processor: Intel(R) Xeon(R) CPU X5650 @ 2.67GHz OS: Ubuntu X86_64 10.10 RAM: 24 GB* The R session info is * R version 2.14.1 (2011-12-22) Platform: x86_64-pc-linux-gnu (64-bit) locale: [1] LC_CTYPE=en_US.UTF-8 LC_NUMERIC=C [3] LC_TIME=en_US.UTF-8LC_COLLATE=en_US.UTF-8 [5] LC_MONETARY=en_US.UTF-8LC_MESSAGES=en_US.UTF-8 [7] LC_PAPER=C LC_NAME=C [9] LC_ADDRESS=C LC_TELEPHONE=C [11] LC_MEASUREMENT=en_US.UTF-8 LC_IDENTIFICATION=C * I have a matrix of dimensions 12 rows X 29318 columns. The matrix contains numeric as well as NA values. I am using the* rcorr *function from the * Hmisc* package to get correlation information from the matrix (* rcorr(matrix)*). During the calculation I get the error *cannot allocate vector of size 6.7 GB*. When I check the memory allocation of my R session I get the following information *gc() used (Mb) gc trigger (Mb) limit (Mb) max used (Mb) Ncells 249638 13.4 467875 25.0 NA 407500 21.8 Vcells 1499217 11.52335949 17.9 7000 1970005 15.1 *Can someone please help me in finding a workaround to the problem. -Regards -- Swaraj Basu PhD Student (Bioinformatics - Functional Genomics) Animal Physiology and Evolution Stazione Zoologica Anton Dohrn Naples [[alternative HTML version deleted]] __ R-help@r-project.org 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] levels of comma separated data
On May 25, 7:23 am, analys...@hotmail.com analys...@hotmail.com wrote: On May 25, 4:46 am, Stefan ste...@inizio.se wrote: analyst41 at hotmail.com analyst41 at hotmail.com writes: I have a data set that has some comma separated strings in each row. I'd like to create a vector consisting of all distinct strings that occur. The number of strings in each row may vary. Thanks for any help. # # # Some data: d - data.frame(id = 1:5, text = c('one,two', 'two,three,three,four', 'one,three,three,five', 'five,five,five,five', 'one,two,three'), stringsAsFactors = FALSE ) # # # A function. I'm not a black belt at this, so there # are probably a more efficient way of writing this. fcn - function(x){ a - strsplit(x, ',') # Split the string by comma unique(a[[1]]) # Uniquify the vector} # # # Use the function with sapply. sapply(d[,2], fcn) Thanks - but this solves a slightly different problem - it outputs the unique values in each row. I want a list of the unique values in the whole data frame. In this case the output should be a single vector = c(one,two,three,four,five). Actually I figured it out after I posted this: levels(as.factor(unlist(strsplit(d$text,',' [1] five four one three two Thanks for pointing me the right way. __ R-help@r-project.org 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] Breakpoint in logistic GLM with 'segmented' package - error: replacement length zero
Hello all, I've been having trouble with assessing a breakpoint in a logistic GLM with two explanatory variables. For this analysis I've been using the 'segmented' package version 0.2-9.1. But I keep getting an error and I don't see where I would be going awry. The situation is the following: Two explanatory variables: bedekking - a variable with possible values between 0 and 1 - mine runs from 0.05 to 0.5, increasing with steps of 0.05 s.size - a count variable - increases from 3 to 25 with steps of 1, and from 25 to 60 with steps of 5 Each combination of s.size and bedekking has 100 repeats so the resulting dataframe 'dat.al2' consists of 3 observations of 3 variables. Because the response variable has values between 0 and 1, I used a logistic GLM: gmodel - glm(R.AUC ~ bedekking + s.size, data=dat.al2, family = quasibinomial(link=logit)) R.AUC increases with increasing s.size and decreasing bedekking, looking at the graph shows that the association reaches a plateau at a s.size of 10 and a bedekking of 0.45. So these are the values I use in 'psi' argument in the 'segmented' function psi.mod - list(0.45, 10) names(psi.mod) - c(bedekking, s.size) Then I attempt to run the 'segmented' function: seg.gm - segmented(obj = gmodel, seg.Z= ~bedekking + s.size, psi = psi.mod) When I run this, after half a minute I get the following error: Error in ifelse(is.list(o0), o0$dev.no.gap, 10^12) : replacement has length zero Does anybody know what might be causing this error, and could somebody point out where I might go wrong? Thanks in advance, Peter __ R-help@r-project.org 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] R+Stata batch mode
Dear Peter, You are absolutely right... I did not know that ;-) What to say ? Many thanks for your right answer to my silly question ;-) Best Regards On 25 May 2012 15:19, peter dalgaard pda...@gmail.com wrote: On May 25, 2012, at 14:46 , Francesco wrote: Dear R help, I am using Stata, and I use a Stata ado file (Rsource) to run R in batch mode within Stata Everything works fine except for the fact that I cannot export the graphics that I obtain with my computations written in my R source file I believe this is related to the global Rterm_options `--vanilla' that I need to precise to Rsource (otherwise it does not work) ... What kind of options should I precise instead in order to be able to use the R line : png('mygraph.png') dev.off() ? At the moment the file obtained (mygraph.png) is void ... but strangely enough the pictures are exported in a pdf file... which is not what I want anyway Any help ? Apologies if I'm being silly, but: You do know that the graphics commands need to go _between_ png() and dev.off()? Otherwise, perhaps the png device didn't start. There should be an error message in the output file in that case. -- Peter Dalgaard, Professor Center for Statistics, Copenhagen Business School Solbjerg Plads 3, 2000 Frederiksberg, Denmark Phone: (+45)38153501 Email: pd@cbs.dk Priv: pda...@gmail.com [[alternative HTML version deleted]] __ R-help@r-project.org 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] Correlograms: using boxes and different variables on rows and columns
I'm trying to make correlograms using corrgram. See below for a simple example. library(corrgram) data(baseball) vars1 - c(Assists,Atbat,Errors,Hits,Homer,logSal) vars2 - c(Putouts,RBI,Runs,Walks,Years) corrgram(baseball[,vars2],lower.panel=panel.shade, upper.panel=panel.pie) I am having two problems: 1) I want to change the visual to bars (see Figure 1 on p. 3: http://www.datavis.ca/papers/corrgram.pdf). I tried changing the code for the upper panel to include bars, but it doesn't appear correctly: corrgram(baseball[,vars2],lower.panel=panel.shade, upper.panel=panel.bars) 2) I want to display one set of variables in the columns (vars1) and another set of variables in the rows (vars2). The reason I want to keep one set of variables in the columns and another set of variables in the rows is because I have many variables and am only interested in the correlations of vars1 with vars2 (and not of the intercorrelations of variables among vars1 or among vars2). Thus, the correlogram with separate variables in the rows and columns would be more condensed and easier to examine visually. Can I address these issues in corrgram, or is there another package that will allow me to do that? Thanks in advance. -- View this message in context: http://r.789695.n4.nabble.com/Correlograms-using-boxes-and-different-variables-on-rows-and-columns-tp4631309.html Sent from the R help mailing list archive at Nabble.com. __ R-help@r-project.org 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] problem with installing rms package
Hi I am trying to install rms package but while installing it shows following error package 'survival' 2.36-2 is loaded, but = 2.36.3 is required by 'rms' what to do? i am using linux OS I have tried by updated r-base-core but it didnt work regards GRR [[alternative HTML version deleted]] __ R-help@r-project.org 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] Hash Table - Select and Change Data iniside Matrix
Hi, Here i have been a matrix like this, *NAMEAGE PALCETRUE/FALSE* ABC 20 INDIA XYZ 30 FRANCE PQR40 USA MNO 30KENIYA DEF25AUSTRALIA Here,* TRUE/FALSE* Column containing empty values. So my requirement what is , need to change all the *TRUE/FALSE *column value into *TRUE* where *AGE = 30*. Note :- i *dont want* to use* any loop *and do. Main intension is avoid loop,bcz there is a bulk of data. Final Matrix should be like this *NAMEAGE PALCETRUE/FALSE* ABC 20 INDIA XYZ 30 FRANCE TRUE PQR40 USA MNO 30KENIYA TRUE DEF25AUSTRALIA Immediate Help Requied. Your, Antony. -- View this message in context: http://r.789695.n4.nabble.com/Hash-Table-Select-and-Change-Data-iniside-Matrix-tp4631312.html Sent from the R help mailing list archive at Nabble.com. __ R-help@r-project.org 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] plotting sorted factors
Hello, The problem is that the factors are not orderd by the row number. If you want to check their order, use str(sortdata) and you'll see Santa-Rosa was attributed factor level 4 (in the output, first variable, the 3rd and 4th). Try the following. sortdata - read.table(text= county yearx1x2x3x4x5 x6 x7 rank 141 Escambia 2002 6.50 5.95 13.70 20.64 20.49 65.86 100.651 142 Escambia 1999 7.31 5.33 15.67 18.94 20.99 73.22 100.531 539 Santa-Rosa 2006 10.70 5.99 11.33 15.34 18.69 57.72 76.032 540 Santa-Rosa 2007 13.31 5.86 16.15 13.74 29.02 66.80 80.682 441 Okaloosa 2004 10.45 6.12 12.02 22.42 22.36 63.38 95.303 442 Okaloosa 2005 8.23 8.53 17.83 12.53 25.44 67.19 83.253 443 Okaloosa 2006 9.17 4.77 17.88 15.53 20.44 71.56 86.983 444 Okaloosa 2003 8.83 6.29 9.79 21.43 34.14 65.44 84.883 621 Walton 1999 3.64 11.84 5.21 22.87 23.70 43.46 71.264 622 Walton 2000 0.00 5.91 2.47 4.97 7.05 46.11 75.414 623 Walton 2001 5.89 6.18 4.61 13.75 20.19 49.38 46.444 271 Holmes 2001 12.62 5.18 14.89 15.28 9.10 66.61 74.575 272 Holmes 2002 0.00 3.88 5.03 14.53 23.90 64.91 122.855 636 Washington 2004 0.00 6.53 16.70 7.78 17.23 48.77 53.226 , header=TRUE, stringsAsFactors=FALSE) str(sortdata) # county is character sortdata$county - with(sortdata, factor(county, levels=unique(county))) str(sortdata) # county is factor, Santa-Rosa is 2 # it now works plot(sortdata$county,sortdata$x1,col=(c(rainbow(70 # preferable? I think it's more intuitive. boxplot(x1~county, data=sortdata, col=rainbow(70)) Hope this helps, Rui Barradas Em 22-05-2012; 23:17, Peterso escreveu: The county is a factor and I want to plot county vs variable x1 in the order that the counties are listed now, which is in the order of the rank variable. But when plotting, county is sorted in alphabetical order again. How can I plot the graph with the county in the rank order? the following command plots county in alphabetical order even though the data frame sortdata is sorted by rank. plot(sortdata$county,sortdata$x1,col=(c(rainbow(70 below is part of sortdata county yearx1x2x3x4x5 x6 x7 rank 141 Escambia 2002 6.50 5.95 13.70 20.64 20.49 65.86 100.651 142 Escambia 1999 7.31 5.33 15.67 18.94 20.99 73.22 100.531 539 Santa-Rosa 2006 10.70 5.99 11.33 15.34 18.69 57.72 76.032 540 Santa-Rosa 2007 13.31 5.86 16.15 13.74 29.02 66.80 80.682 441 Okaloosa 2004 10.45 6.12 12.02 22.42 22.36 63.38 95.303 442 Okaloosa 2005 8.23 8.53 17.83 12.53 25.44 67.19 83.253 443 Okaloosa 2006 9.17 4.77 17.88 15.53 20.44 71.56 86.983 444 Okaloosa 2003 8.83 6.29 9.79 21.43 34.14 65.44 84.883 621 Walton 1999 3.64 11.84 5.21 22.87 23.70 43.46 71.264 622 Walton 2000 0.00 5.91 2.47 4.97 7.05 46.11 75.414 623 Walton 2001 5.89 6.18 4.61 13.75 20.19 49.38 46.444 271 Holmes 2001 12.62 5.18 14.89 15.28 9.10 66.61 74.575 272 Holmes 2002 0.00 3.88 5.03 14.53 23.90 64.91 122.855 636 Washington 2004 0.00 6.53 16.70 7.78 17.23 48.77 53.226 Thanks, Johnny Liseth Graduate Student in Statistics University of West Florida __ R-help@r-project.org 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] Filling NA with cumprod?
Hello Petr, Yes, I was hoping to avoid using loops. If nothing else works, I will take approach as the last resort. Thank you, Igor. On May 25, 2012 2:26 AM, Petr Savicky savi...@cs.cas.cz wrote: On Thu, May 24, 2012 at 08:24:38PM -0700, igorre25 wrote: Hello, I need to build certain interpolation logic using R. Unfortunately, I just started using R, and I'm not familiar with lots of advanced or just convenient features of the language to make this simpler. So I struggled for few days and pretty much reduced the whole exercise to the following problem, which I cannot resolve: Assume we have a vector of some values with NA: a - c(1, 2, 3, NA, NA, 6, 7, NA, NA, 10) and some coefficients as a vector of the same length: f - c(0.9, 1.1, 0.9, 1.1, 0.9, 1.1, 0.9, 1.1, 0.9, 1.1) I need to come up with function to get the following output o[1] = a[1] o[2] = a[2] o[3] = a[3] o[4] = o[3]*[f3] # Because a[3] is NA o[5] = o[4]*[f4] # Because a[4] is NA; This looks like recursive calculations; If the rest of the elements we NA, I would use a * c(rep(1, 3), cumprod(f[3:9])), but that's not the case o[6] = a[6] # Not NA anymore o[7] = a[7] o[8] = o[7]*f[7] # Again a[8] is NA o[9] = o[8]*f[8] o[10] = a[10] # Not NA Even though my explanation may seems complex, in reality the requirement is pretty simple and in Excel is achieved with a very short formula. The need to use R is to demonstrate capabilities of the language and then to expand to more complex problems. Hello: How is the output defined, if a[1] is NA? I think, you are not asking for a loop solution. However, in this case, it can be a reasonable option. For example a - c(1, 2, 3, NA, NA, 6, 7, NA, NA, 10) f - c(0.9, 1.1, 0.9, 1.1, 0.9, 1.1, 0.9, 1.1, 0.9, 1.1) n - length(a) o - rep(NA, times=n) prev - 1 for (i in 1:n) { if (is.na(a[i])) { o[i] - f[i]*prev } else { o[i] - a[i] } prev - o[i] } A more straightforward translation of the Excel formulas is getCell - function(i) { if (i == 0) return(1) if (is.na(a[i])) { return(f[i]*getCell(i-1)) } else { return(a[i]) } } x - rep(NA, times=n) for (i in 1:n) { x[i] - getCell(i) } identical(o, x) # [1] TRUE Petr Savicky. __ R-help@r-project.org 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. [[alternative HTML version deleted]] __ R-help@r-project.org 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] problem with installing rms package
On May 25, 2012, at 8:51 AM, ramakanth reddy wrote: Hi I am trying to install rms package but while installing it shows following error package 'survival' 2.36-2 is loaded, but = 2.36.3 is required by 'rms' what to do? i am using linux OS I have tried by updated r-base-core but it didnt work regards GRR The latest version of survival on CRAN is 2.36-14. When you install rms, be sure to use: install.packages(rms, dependencies = TRUE) to be sure that package dependencies are satisfied during the installation. Regards, Marc Schwartz __ R-help@r-project.org 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] Collecting results of a test with array
?abind ## in R package abind. Very handy for this sort of thing Something like: do.call(abind, yourlist) You can also do it by hand along the lines Michael described: e.g. something like array(unlist(yourlist), dim = c(2,3, 12) ) -- Bert On Fri, May 25, 2012 at 6:16 AM, R. Michael Weylandt michael.weyla...@gmail.com wrote: My first thought is to unlist them and stick them in a vector and then to form that vector into an array of the desired shape. Something like this: x - vector(list,12) for(i in 6*(1:12)){x[[i/6]] - matrix(i:(i+5), ncol = 2) } print(x) x.out - array(unlist(x), dim = c(2,3,12)) print(x.out) which I believe is what you want. [If not, I think it will at least get you started] Hope this helps, Michael On Fri, May 25, 2012 at 5:21 AM, Francesca francesca.panco...@gmail.com wrote: Dear contributors I have tried this experiment: x-c() for (i in 1:12){ x[i]-list(cbind(x1[i],x2[i])) #this is a list of 12 couples of time series I am using to perform a test } # that compares them 2 by 2 # # #trace statistic test-data.frame() cval-array( , dim=c(2,3,12)) for (i in 2:12){ for (k in 1:2){ for (j in 1:3){ result[k,j,i]- ((ca.jo(data.frame(x[i]),ecdet=none,type=trace, spec=longrun,K=2))@cval[k,j]) }}} I have a problem in collecting the results of a test. The function ca.jo creates an object with various attributes, one of which is the cval that i can access through @cval. The attribute cval is an object of dimension 2X3. I am running recursively the test with ca.jo for 12 couples of time series, so I have an output of 12 matrices of 2X3 elements and I would like to create an object like an array of dimension (2,3,12) which contains each matrix @cval produced by ca.jo for the 12 subjects that i tested. Can anyone help me with that? I hope my explanation of the problem is clear. Thanks in advance for any help. -- Francesca -- Francesca Pancotto, PhD Università di Modena e Reggio Emilia Viale A. Allegri, 9 40121 Reggio Emilia Office: +39 0522 523264 Web: http://www2.dse.unibo.it/francesca.pancotto/ -- [[alternative HTML version deleted]] __ R-help@r-project.org 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@r-project.org 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. -- Bert Gunter Genentech Nonclinical Biostatistics Internal Contact Info: Phone: 467-7374 Website: http://pharmadevelopment.roche.com/index/pdb/pdb-functional-groups/pdb-biostatistics/pdb-ncb-home.htm __ R-help@r-project.org 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] Hash Table - Select and Change Data iniside Matrix
There aren't empty values in R. nor is it likely you have a matrix of this form, but perhaps a data frame. Perhaps this works for you, If dat is the name of your data.frame, dat[dat$AGE == 30,TRUE/FALSE] - TRUE Next time do use dput() to give a reproducible example of your data -- if it's very large, just limit it to the first 30 rows or so with dput(head(dats, 30)) Michael On Fri, May 25, 2012 at 9:43 AM, Rantony antony.akk...@ge.com wrote: Hi, Here i have been a matrix like this, *NAME AGE PALCE TRUE/FALSE* ABC 20 INDIA XYZ 30 FRANCE PQR 40 USA MNO 30 KENIYA DEF 25 AUSTRALIA Here,* TRUE/FALSE* Column containing empty values. So my requirement what is , need to change all the *TRUE/FALSE *column value into *TRUE* where *AGE = 30*. Note :- i *dont want* to use* any loop *and do. Main intension is avoid loop,bcz there is a bulk of data. Final Matrix should be like this *NAME AGE PALCE TRUE/FALSE* ABC 20 INDIA XYZ 30 FRANCE TRUE PQR 40 USA MNO 30 KENIYA TRUE DEF 25 AUSTRALIA Immediate Help Requied. Your, Antony. -- View this message in context: http://r.789695.n4.nabble.com/Hash-Table-Select-and-Change-Data-iniside-Matrix-tp4631312.html Sent from the R help mailing list archive at Nabble.com. __ R-help@r-project.org 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@r-project.org 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] Hash Table - Select and Change Data iniside Matrix
Read help for the ifelse function. Type ?ifelse at the command line. --- Jeff NewmillerThe . . Go Live... DCN:jdnew...@dcn.davis.ca.usBasics: ##.#. ##.#. Live Go... Live: OO#.. Dead: OO#.. Playing Research Engineer (Solar/BatteriesO.O#. #.O#. with /Software/Embedded Controllers) .OO#. .OO#. rocks...1k --- Sent from my phone. Please excuse my brevity. Rantony antony.akk...@ge.com wrote: Hi, Here i have been a matrix like this, *NAMEAGE PALCETRUE/FALSE* ABC 20 INDIA XYZ 30 FRANCE PQR40 USA MNO 30KENIYA DEF25AUSTRALIA Here,* TRUE/FALSE* Column containing empty values. So my requirement what is , need to change all the *TRUE/FALSE *column value into *TRUE* where *AGE = 30*. Note :- i *dont want* to use* any loop *and do. Main intension is avoid loop,bcz there is a bulk of data. Final Matrix should be like this *NAMEAGE PALCETRUE/FALSE* ABC 20 INDIA XYZ 30 FRANCE TRUE PQR40 USA MNO 30KENIYA TRUE DEF25AUSTRALIA Immediate Help Requied. Your, Antony. -- View this message in context: http://r.789695.n4.nabble.com/Hash-Table-Select-and-Change-Data-iniside-Matrix-tp4631312.html Sent from the R help mailing list archive at Nabble.com. __ R-help@r-project.org 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@r-project.org 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] applying cbind (or any function) across all components in a list
This should give you what you want and it is simpler than the earlier version: a1- array(1:6, dim=c(2,3)) a2- array(7:12, dim=c(2,3)) l1- list(a1,a2) a3- array(1:4, dim=c(2,2)) a4- array(5:8, dim=c(2,2)) l2- list(a3,a4) pattern - cbind(c(1, 2, 2, 3), c(1, 1, 2, 2)) lnew - lapply(1:length(l1), function(i) (l1[[i]][,pattern[,1]]+l2[[i]][,pattern[,2]])/2) lnew If all the information from your several posts had been included in the original request, we could have responded more quickly. -- David L Carlson Associate Professor of Anthropology Texas AM University College Station, TX 77843-4352 -Original Message- From: r-help-boun...@r-project.org [mailto:r-help-bounces@r- project.org] On Behalf Of Hans Thompson Sent: Thursday, May 24, 2012 5:19 PM To: r-help@r-project.org Subject: Re: [R] applying cbind (or any function) across all components in a list Yes. This gives me: [,1] [,2] [,3] [,4] [1,]1234 [2,]2345 [,1] [,2] [,3] [,4] [1,]6789 [2,]789 10 BUT, how can I have it still within components like [[1]] [,1] [,2] [,3] [,4] [1,]1234 [2,]2345 [[2]] [,1] [,2] [,3] [,4] [1,]6789 [2,]789 10 How should I have phrased my question to be specific to this result? Thanks. -- View this message in context: http://r.789695.n4.nabble.com/applying- cbind-or-any-function-across-all-components-in-a-list- tp4631128p4631258.html Sent from the R help mailing list archive at Nabble.com. __ R-help@r-project.org 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@r-project.org 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] Multiple cbind according to filename
Matthew Ouellette mouellette89 at gmail.com writes: Hi all, I'm just a beginner with R but I have not been able to search for any relevant answer to my problem. I apologize if it has in fact been asked before. Recently I've realized that I need to combine hundreds of pairs of data frames. The filenames of the frames I need to combine have unique strings. This is my best guess as to the approach to take: filenames-list.files() filenames [1] a1.csv a2.csv b1.csv b2.csv c1.csv c2.csv alldata-lapply(filenames, read.csv, header=TRUE) names(alldata)-filenames summary(alldata) Length Class Mode a1.csv 27 data.frame list a2.csv 27 data.frame list b1.csv 27 data.frame list b2.csv 27 data.frame list c1.csv 27 data.frame list c2.csv 27 data.frame list My next step would be to cbind files that share a common string at the beginning, such as: cbind(alldata[[1]],alldata[[2]]) cbind(alldata[[3]],alldata[[4]]) cbind(alldata[[5]],alldata[[6]]) ... but file list is hundreds of files long (but is sorted alphanumerically such as in this example - not sure if this is relevant). If I had to guess, I'd do something like this: which(names(alldata)==...), to identify which elements to combine based on unique filename OR x-seq(1,length(alldata), 2) y=x+1 z-cbind(x,y) z x y [1,] 1 2 [2,] 3 4 [3,] 5 6 to use the frame created in z to combine based on rows, then use a looped cbind function (or *apply function with nested cbind function?) using the previously returned indexes to create my new combined data frames, including a step to write the frames to a new unique filename (not sure how to do that step in this context). These last steps I've tried a lot of code but nothing worth mentioning as it has all failed miserably. I appreciate the help, M [[alternative HTML version deleted]] Hi Matthew, You could try using substr() if the cbind is based on a common string in the file name just makes sure that the strings in filenames is in the same order as the files are in list.files: a1 - data.frame(col1 = seq(1,10, 1)) a2 - data.frame(col2 = seq(11,20, 1)) b1 - data.frame(col3 = seq(21,30, 1)) b2 - data.frame(col4 = seq(31,40, 1)) filenames - c(a1, a2, b1, b2) list.files - list(a1, a2, b1, b2) first.letter - substr(filenames, 1,1) unique.first.letter - unique(first.letter) l.files - list() for(i in 1:length(unique.first.letter)){ l.files[[i]] = as.data.frame(list.files[first.letter == unique.first.letter[i]]) } HTH, Ken __ R-help@r-project.org 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] Filling NA with cumprod?
This will loop only as many times as the largest number of consecutive NA's but uses vectorization within the loop. As currently defined, it will loop forever if the first value is NA. a - c(1, 2, 3, NA, NA, 6, 7, NA, NA, 10) f - c(0.9, 1.1, 0.9, 1.1, 0.9, 1.1, 0.9, 1.1, 0.9, 1.1) a1 - a alag - c(NA, a1[1:length(a1)-1]) # change NA to the value to use if the first value in a is NA while (sum(is.na(a1)) 0) { a1 - ifelse(is.na(a1), f*alag, a1) alag - c(NA, a1[1:length(a1)-1]) } -- David L Carlson Associate Professor of Anthropology Texas AM University College Station, TX 77843-4352 -Original Message- From: r-help-boun...@r-project.org [mailto:r-help-bounces@r- project.org] On Behalf Of Igor Reznikovsky Sent: Friday, May 25, 2012 9:08 AM To: Petr Savicky Cc: r-help@r-project.org Subject: Re: [R] Filling NA with cumprod? Hello Petr, Yes, I was hoping to avoid using loops. If nothing else works, I will take approach as the last resort. Thank you, Igor. On May 25, 2012 2:26 AM, Petr Savicky savi...@cs.cas.cz wrote: On Thu, May 24, 2012 at 08:24:38PM -0700, igorre25 wrote: Hello, I need to build certain interpolation logic using R. Unfortunately, I just started using R, and I'm not familiar with lots of advanced or just convenient features of the language to make this simpler. So I struggled for few days and pretty much reduced the whole exercise to the following problem, which I cannot resolve: Assume we have a vector of some values with NA: a - c(1, 2, 3, NA, NA, 6, 7, NA, NA, 10) and some coefficients as a vector of the same length: f - c(0.9, 1.1, 0.9, 1.1, 0.9, 1.1, 0.9, 1.1, 0.9, 1.1) I need to come up with function to get the following output o[1] = a[1] o[2] = a[2] o[3] = a[3] o[4] = o[3]*[f3] # Because a[3] is NA o[5] = o[4]*[f4] # Because a[4] is NA; This looks like recursive calculations; If the rest of the elements we NA, I would use a * c(rep(1, 3), cumprod(f[3:9])), but that's not the case o[6] = a[6] # Not NA anymore o[7] = a[7] o[8] = o[7]*f[7] # Again a[8] is NA o[9] = o[8]*f[8] o[10] = a[10] # Not NA Even though my explanation may seems complex, in reality the requirement is pretty simple and in Excel is achieved with a very short formula. The need to use R is to demonstrate capabilities of the language and then to expand to more complex problems. Hello: How is the output defined, if a[1] is NA? I think, you are not asking for a loop solution. However, in this case, it can be a reasonable option. For example a - c(1, 2, 3, NA, NA, 6, 7, NA, NA, 10) f - c(0.9, 1.1, 0.9, 1.1, 0.9, 1.1, 0.9, 1.1, 0.9, 1.1) n - length(a) o - rep(NA, times=n) prev - 1 for (i in 1:n) { if (is.na(a[i])) { o[i] - f[i]*prev } else { o[i] - a[i] } prev - o[i] } A more straightforward translation of the Excel formulas is getCell - function(i) { if (i == 0) return(1) if (is.na(a[i])) { return(f[i]*getCell(i-1)) } else { return(a[i]) } } x - rep(NA, times=n) for (i in 1:n) { x[i] - getCell(i) } identical(o, x) # [1] TRUE Petr Savicky. __ R-help@r-project.org 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. [[alternative HTML version deleted]] __ R-help@r-project.org 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@r-project.org 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] problem with installing rms package
Hi, First, please be sure to reply-all when following up so that the thread stays on the public list. The messages suggest that you might not have 'root' access when installing the packages, so the installation of the packages to the default location fails. You need to 'su' to root via the command line before running R and then installing the packages. If your account does not have su permissions, you can either get a SysAdmin who does or specify a path for the 'lib' argument in install.packages() so that the packages are installed to a local folder where you have permissions. See ?install.packages for more information. Marc On May 25, 2012, at 9:54 AM, ramakanth reddy wrote: Hi i tried as u said but still library could not be loaded. it shows 18 warnings Warning messages: 1: In install.packages(rms, dependencies = TRUE) : installation of package 'RODBC' had non-zero exit status 2: In install.packages(rms, dependencies = TRUE) : installation of package 'diptest' had non-zero exit status 3: In install.packages(rms, dependencies = TRUE) : installation of package 'rgl' had non-zero exit status 4: In install.packages(rms, dependencies = TRUE) : installation of package 'lme4' had non-zero exit status 5: In install.packages(rms, dependencies = TRUE) : installation of package 'rms' had non-zero exit status 6: In install.packages(rms, dependencies = TRUE) : installation of package 'caTools' had non-zero exit status 7: In install.packages(rms, dependencies = TRUE) : installation of package 'testthat' had non-zero exit status 8: In install.packages(rms, dependencies = TRUE) : installation of package 'mlmRev' had non-zero exit status 9: In install.packages(rms, dependencies = TRUE) : installation of package 'MEMSS' had non-zero exit status 10: In install.packages(rms, dependencies = TRUE) : installation of package 'BayesX' had non-zero exit status 11: In install.packages(rms, dependencies = TRUE) : installation of package 'coxme' had non-zero exit status 12: In install.packages(rms, dependencies = TRUE) : installation of package 'gplots' had non-zero exit status 13: In install.packages(rms, dependencies = TRUE) : installation of package 'scales' had non-zero exit status 14: In install.packages(rms, dependencies = TRUE) : installation of package 'systemfit' had non-zero exit status 15: In install.packages(rms, dependencies = TRUE) : installation of package 'ROCR' had non-zero exit status 16: In install.packages(rms, dependencies = TRUE) : installation of package 'sampleSelection' had non-zero exit status 17: In install.packages(rms, dependencies = TRUE) : installation of package 'AER' had non-zero exit status 18: In install.packages(rms, dependencies = TRUE) : installation of package 'dynlm' had non-zero exit status what can be done? Regards GRR On 25 May 2012 10:09, Marc Schwartz marc_schwa...@me.com wrote: On May 25, 2012, at 8:51 AM, ramakanth reddy wrote: Hi I am trying to install rms package but while installing it shows following error package 'survival' 2.36-2 is loaded, but = 2.36.3 is required by 'rms' what to do? i am using linux OS I have tried by updated r-base-core but it didnt work regards GRR The latest version of survival on CRAN is 2.36-14. When you install rms, be sure to use: install.packages(rms, dependencies = TRUE) to be sure that package dependencies are satisfied during the installation. Regards, Marc Schwartz -- Herzlichen Gruß, Ramakanth Reddy Guntuka --- Life Sc. Informatics Programme Bonn-Aachen International Center for Information Technology University of Bonn, Germany Mob: +49-015141366412 [[alternative HTML version deleted]] __ R-help@r-project.org 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] Breakpoint in logistic GLM with 'segmented' package - error: replacement length zero
dear Peter, Your code appears correct, so it is difficult to reply without the data.. If you are interested in further details, please contact me off-list vito Il 25/05/2012 15.34, Peter Hoitinga ha scritto: Hello all, I've been having trouble with assessing a breakpoint in a logistic GLM with two explanatory variables. For this analysis I've been using the 'segmented' package version 0.2-9.1. But I keep getting an error and I don't see where I would be going awry. The situation is the following: Two explanatory variables: bedekking - a variable with possible values between 0 and 1 - mine runs from 0.05 to 0.5, increasing with steps of 0.05 s.size - a count variable - increases from 3 to 25 with steps of 1, and from 25 to 60 with steps of 5 Each combination of s.size and bedekking has 100 repeats so the resulting dataframe 'dat.al2' consists of 3 observations of 3 variables. Because the response variable has values between 0 and 1, I used a logistic GLM: gmodel- glm(R.AUC ~ bedekking + s.size, data=dat.al2, family = quasibinomial(link=logit)) R.AUC increases with increasing s.size and decreasing bedekking, looking at the graph shows that the association reaches a plateau at a s.size of 10 and a bedekking of 0.45. So these are the values I use in 'psi' argument in the 'segmented' function psi.mod- list(0.45, 10) names(psi.mod)- c(bedekking, s.size) Then I attempt to run the 'segmented' function: seg.gm- segmented(obj = gmodel, seg.Z= ~bedekking + s.size, psi = psi.mod) When I run this, after half a minute I get the following error: Error in ifelse(is.list(o0), o0$dev.no.gap, 10^12) : replacement has length zero Does anybody know what might be causing this error, and could somebody point out where I might go wrong? Thanks in advance, Peter __ R-help@r-project.org 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. -- Vito M.R. Muggeo Dip.to Sc Statist e Matem `Vianelli' Università di Palermo viale delle Scienze, edificio 13 90128 Palermo - ITALY tel: 091 23895240 fax: 091 485726 http://dssm.unipa.it/vmuggeo __ R-help@r-project.org 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] R does not recognise columns and rows as they are supposed to be
Is the file format documented? If not you can search for a possible format if you know the values at the start of the file. For one of your files, show the results of the following: file - your filename here for(what in c(double, integer)) { for(size in c(4, 8)) { for(endian in c(little, big)) { cat(sep=, what, /, size, /, endian, :\n ); print(readBin(file, what=what, size=size, endian=endian, n=6)) } } } Do any of them look ok? If not you may want to loop over possible offsets in the file by opening a connection, reading from 1 to 7 one-byte integers, and then reading the data of interest. Bill Dunlap Spotfire, TIBCO Software wdunlap tibco.com -Original Message- From: r-help-boun...@r-project.org [mailto:r-help-boun...@r-project.org] On Behalf Of Jonsson Sent: Thursday, May 24, 2012 11:41 PM To: r-help@r-project.org Subject: Re: [R] R does not recognise columns and rows as they are supposed to be Yes I exactly followed what you all suggested: X-(82:92) ; Y-(364:369) # for sellected region extract - double(365) setwd(C:\\Users\\aalyaari\\Desktop\\New folder (10)\\) listfile-dir() for (i in 1:365) { + conne - file(listfile[i], rb) + file1- readBin(conne, double(), n=360*720) + file2-matrix(data=file1,ncol=720,nrow=360) + extract[i]-mean(file2[X,Y],na.rm=TRUE) + close(conne) } write.table(extract,C:\\Users\\aalyaari\\Desktop\\New folder (10)\\samregion1.txt) But I am still getting(negative values) all values like: -3.75E+306 -1.30E+54 -1.22E+58 and the right ones should be like: 22.25 22.76 33.25 -- View this message in context: http://r.789695.n4.nabble.com/R-does-not-recognise- columns-and-rows-as-they-are-supposed-to-be-tp4631217p4631279.html Sent from the R help mailing list archive at Nabble.com. __ R-help@r-project.org 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@r-project.org 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] Multiple rms summary plots in a single device
I would like to incorporate multiple summary plots from the rms package into a single device and to control the titles, and also to open a new device when I reach a specified number of plots. Currently I am only getting a single plot(summary( graph in the upper left- hand corner of each successive device. However, in the rms documention I see instances of a loop being used with par(mfrow( for multiple plots in a single device(e.g. residuals.lrm), and these examples work on my system. Please advise regarding options that must be specified to plot(summary(, or in the construction of my loop. Below are sample code and my sessionInfo(). Please note that I am using data.table to facilitate my real analysis, but I can replicate the issue with tData as a data.frame (using seg - subset(tData, groups == segment) logic), but I included the data.table logic in case it may be having some influence. Thank you! Mike tData - data.frame(groups=as.factor(1:8), low=as.factor(1:4) ,high=as.factor(seq(100, 400, 100)), rand=runif(400)) tData - data.table(tData) setkeyv(tData, 'groups') dd - datadist(tData) options(datadist = 'dd') doSumPlot - function(segment){ seg - tData[groups == segment,] plot(summary(rand ~ + low + high ,data = seg ), main=paste('Group:', segment)) } for(i in 1:length(levels(tData$groups))){ cat('Group: ', i, '\n') if(i == 1 ){ dev.new() par(mfrow=c(2,2)) } if(i/5 == round(i/5, 0)){ dev.new() par(mfrow=c(2,2)) } # dev.new() doSumPlot(levels(tData$groups)[i]) } sessionInfo() R version 2.15.0 (2012-03-30) Platform: i386-pc-mingw32/i386 (32-bit) locale: [1] LC_COLLATE=English_United States.1252 [2] LC_CTYPE=English_United States.1252 [3] LC_MONETARY=English_United States.1252 [4] LC_NUMERIC=C [5] LC_TIME=English_United States.1252 attached base packages: [1] splines stats graphics grDevices utils datasets methods [8] base other attached packages: [1] rms_3.5-0Hmisc_3.9-3 survival_2.36-14 data.table_1.8.0 loaded via a namespace (and not attached): [1] cluster_1.14.2 grid_2.15.0lattice_0.20-6 tools_2.15.0 __ R-help@r-project.org 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] [snowFT] Problems with passing arguments to performParallel
Hi all, I am trying to use performParallel from the snowFT package. But I have a really hard time to be able to pass arguments to the function that I want to run in parallel. Since I could not pass the arguments I create a XML file to read the information from there, the problem is that I can also not use some self-made functions that I have defined in another R file and that I source in order to use it. I tried to do: res-performParallel(clusters, 1:clusters, fun=MainFunction, initfun=initFunction) where MainFunction and initFunction are functions that I created. The problem I have it is that inside the MainFunction I used some other functions that I have defined in a R file. So inside the initFunction I do a source of the R file containing the definitions. But when I run the command above I get an error saying that the function could not be found. The error is the following: Error in checkForRemoteErrors(val) : 2 nodes produced errors; first error: Error in fun(x, ...) : could not find function ReadXMLConfig In addition: Warning messages: 1: closing unused connection 4 (-earth:10187) 2: closing unused connection 3 (-earth:10187) Could someone help me with this? Thanks a lot!! Marta [[alternative HTML version deleted]] __ R-help@r-project.org 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] Problem sourcing file
Hi all, I created a file to define some functions. When I try to source this file, sometimes it works but sometimes I get the following error: Source(File.R) Error in srcfilecopy(filename, lines, file.info(filename)[1, mtime]) : unused argument(s) (file.info(filename)[1, mtime]) It works when I just started the R session, but after using some libraries when I do the source of the file again, I get this error. I can not really follow what steps aret he ones that bring me to the error, I only know that sometimes it appears. Does someone know the possible cause? Thanks! Marta [[alternative HTML version deleted]] __ R-help@r-project.org 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] Hash Table - Select and Change Data iniside Matrix
Thank you Michael. You are awesomeâ¦. It works, what I mean. Thank you very much. - Antony. From: Michael Weylandt [via R] [mailto:ml-node+s789695n4631319...@n4.nabble.com] Sent: Friday, May 25, 2012 7:48 PM To: Akkara, Antony (GE Energy, Non-GE) Subject: Re: Hash Table - Select and Change Data iniside Matrix There aren't empty values in R. nor is it likely you have a matrix of this form, but perhaps a data frame. Perhaps this works for you, If dat is the name of your data.frame, dat[dat$AGE == 30,TRUE/FALSE] - TRUE Next time do use dput() to give a reproducible example of your data -- if it's very large, just limit it to the first 30 rows or so with dput(head(dats, 30)) Michael On Fri, May 25, 2012 at 9:43 AM, Rantony [hidden email] wrote: Hi, Here i have been a matrix like this, *NAMEAGE PALCETRUE/FALSE* ABC 20 INDIA XYZ 30 FRANCE PQR40 USA MNO 30KENIYA DEF25AUSTRALIA Here,* TRUE/FALSE* Column containing empty values. So my requirement what is , need to change all the *TRUE/FALSE *column value into *TRUE* where *AGE = 30*. Note :- i *dont want* to use* any loop *and do. Main intension is avoid loop,bcz there is a bulk of data. Final Matrix should be like this *NAMEAGE PALCETRUE/FALSE* ABC 20 INDIA XYZ 30 FRANCE TRUE PQR40 USA MNO 30KENIYA TRUE DEF25AUSTRALIA Immediate Help Requied. Your, Antony. -- View this message in context: http://r.789695.n4.nabble.com/Hash-Table-Select-and-Change-Data-iniside-Matrix-tp4631312.html Sent from the R help mailing list archive at Nabble.com. __ [hidden email] 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. __ [hidden email] 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. If you reply to this email, your message will be added to the discussion below: http://r.789695.n4.nabble.com/Hash-Table-Select-and-Change-Data-iniside-Matrix-tp4631312p4631319.html To unsubscribe from Hash Table - Select and Change Data iniside Matrix, click here http://r.789695.n4.nabble.com/template/NamlServlet.jtp?macro=unsubscribe_by_codenode=4631312code=YW50b255LmFra2FyYUBnZS5jb218NDYzMTMxMnwxNTUxOTQzMDI5 . NAML http://r.789695.n4.nabble.com/template/NamlServlet.jtp?macro=macro_viewerid=instant_html%21nabble%3Aemail.namlbase=nabble.naml.namespaces.BasicNamespace-nabble.view.web.template.NabbleNamespace-nabble.view.web.template.NodeNamespacebreadcrumbs=notify_subscribers%21nabble%3Aemail.naml-instant_emails%21nabble%3Aemail.naml-send_instant_email%21nabble%3Aemail.naml -- View this message in context: http://r.789695.n4.nabble.com/Hash-Table-Select-and-Change-Data-iniside-Matrix-tp4631312p4631320.html Sent from the R help mailing list archive at Nabble.com. [[alternative HTML version deleted]] __ R-help@r-project.org 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] Basic help
Hello, First of all, 'c' is a bad name for a variable, it's also the name of an R function. Think a, b, k, d, ... Now, try y - m %o% x + k Hope this helps, Rui Barradas Em 24-05-2012, 2:07, Abhay Joshi http://r.789695.n4.nabble.com/template/NamlServlet.jtp?macro=user_nodesuser=368600 escreveu: Hi All, I am very new to R, in Y=mX+c I have 10 values for X (X=1,2,3,4,5,6,7,8,9,10) m is a distribution with mean 10 and sd 2 (m - rnorm(n=100, m=10, sd=2)) and c is a distibution with mean 200 and sd 20 (c - rnorm(n=100, m=200, sd=20)) How can I randomaly choose one number from m and c both 1000 times and find the 1000 values for Y for my 10 values of X. Thanks for help. Abhay http://r.789695.n4.nabble.com/template/NamlServlet.jtp?macro=user_nodesuser=368600 [[alternative HTML version deleted]] __ R-help@r-project.org 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] qnorm to a list
dear jim, thakyou very much for your help. i would really appreciate if you give me one more favor. i want to apply qnorm to the whole coulmn so that i would have on the x-axis the quantile of the lognormal distribution (qnorm()) with zero-mean and unit-variance, corresponding to excedence probabilities F=i/(365+1) with i=1...365. thanks in advance bye On Fri, 25 May 2012 18:15:45 +1000 Jim Lemon j...@bitwrit.com.au wrote: On 05/25/2012 02:45 AM, QAMAR MUHAMMAD UZAIR wrote: ... I want to reshape it in the following FORMAT 196719681969197019711972 19731974 10.870.870.870.870.71 20.870.870.870.870.72 OBVIOUSLY, I HAVE A LARGE AMOUNT OF DATA TO WORK WITH.i would also like to take into account the effect of leap year. For example if 1969 in a leap year then the column under it, has to have 1 extra reading. Hi Qamar, You can do something like this, assuming that your data frame is named qmu and the two columns are named V1 and V2: # extract years from the dates qmu$year-as.numeric(sapply(strsplit(as.character(qmu$V1),[.]),[,3)) # get a vector of the unique years uyears-unique(qmu$year) # make an empty list newqmu-list() # populate the list year by year for(i in 1:length(uyears)) newqmu[[i]]-qmu$V2[qmu$year==uyears[i]] This will give you a list with the same characteristics as you described. You can't have a data frame with different column lengths, so you would have to pad the shorter columns with NA values if you want a data frame. Jim __ R-help@r-project.org 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@r-project.org 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] R memory allocation
On 05/25/2012 06:29 AM, swaraj basu wrote: Dear All, I am running R in a system with the following configuration *Processor: Intel(R) Xeon(R) CPU X5650 @ 2.67GHz OS: Ubuntu X86_64 10.10 RAM: 24 GB* The R session info is * R version 2.14.1 (2011-12-22) Platform: x86_64-pc-linux-gnu (64-bit) locale: [1] LC_CTYPE=en_US.UTF-8 LC_NUMERIC=C [3] LC_TIME=en_US.UTF-8LC_COLLATE=en_US.UTF-8 [5] LC_MONETARY=en_US.UTF-8LC_MESSAGES=en_US.UTF-8 [7] LC_PAPER=C LC_NAME=C [9] LC_ADDRESS=C LC_TELEPHONE=C [11] LC_MEASUREMENT=en_US.UTF-8 LC_IDENTIFICATION=C * I have a matrix of dimensions 12 rows X 29318 columns. The matrix contains numeric as well as NA values. I am using the* rcorr *function from the * Hmisc* package to get correlation information from the matrix (* rcorr(matrix)*). During the calculation I get the error *cannot allocate vector of size 6.7 GB*. When I check the memory allocation of my R session I get the following information Perhaps you are trying to calculate correlations between the 12 rows, so want to transpose the matrix? If not and if this is a gene expression study then common practice is to reduce the number of probe sets to those that are most variable across all samples, as these are the ones that will provide statistical signal. Martin *gc() used (Mb) gc trigger (Mb) limit (Mb) max used (Mb) Ncells 249638 13.4 467875 25.0 NA 407500 21.8 Vcells 1499217 11.52335949 17.9 7000 1970005 15.1 *Can someone please help me in finding a workaround to the problem. -Regards -- Computational Biology Fred Hutchinson Cancer Research Center 1100 Fairview Ave. N. PO Box 19024 Seattle, WA 98109 Location: M1-B861 Telephone: 206 667-2793 __ R-help@r-project.org 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] Rolling Sample VAR
hi guys, I am using trivariate VAR model to get 10 step ahead orthogonalized impulse response functions. I want to use rolling sample analysis on the coefficients of the irf but I have no idea how to do that. I looked through the forums but I can't seem to find any solutions. Any suggestions would be helpful. B -- View this message in context: http://r.789695.n4.nabble.com/Rolling-Sample-VAR-tp4631328.html Sent from the R help mailing list archive at Nabble.com. __ R-help@r-project.org 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] count number of groups
Hello, Simple question that I am stuck on and can't seem to find an answer in the help files currently. I have a list which contains repeated ID's. I would like to have R count the number of ID's. For example: ID=c(1,1,1,1,2,2,2,2,3,3,3,3) as.data.frame(ID) Clearly, there are 3 groups. How would I have R give me the summary: ID 3 Many thanks, Charles [[alternative HTML version deleted]] __ R-help@r-project.org 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] Problem sourcing file
Is the file just definitions of functions, or do you have some statements that are being executed? Could the error be coming from them? Just defining functions should work just fine. On Fri, May 25, 2012 at 10:08 AM, Marta Tolós marta.to...@gtd.es wrote: Hi all, I created a file to define some functions. When I try to source this file, sometimes it works but sometimes I get the following error: Source(‘File.R’) Error in srcfilecopy(filename, lines, file.info(filename)[1, mtime]) : unused argument(s) (file.info(filename)[1, mtime]) It works when I just started the R session, but after using some libraries when I do the source of the file again, I get this error. I can not really follow what steps aret he ones that bring me to the error, I only know that sometimes it appears. Does someone know the possible cause? Thanks! Marta [[alternative HTML version deleted]] __ R-help@r-project.org 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. -- Jim Holtman Data Munger Guru What is the problem that you are trying to solve? Tell me what you want to do, not how you want to do it. __ R-help@r-project.org 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] Problem with Autocorrelation and GLS Regression
Hi, I have a problem with a regression I try to run. I did an estimation of the market model with daily data. You can see to output below: / summary(regression_resn) Time series regression with ts data: Start = -150, End = -26 Call: dynlm(formula = ror_resn ~ ror_spi_resn) Residuals: Min 1Q Median 3QMax -0.0255690 -0.0030378 0.0002787 0.0039887 0.0257857 Coefficients: Estimate Std. Error t value Pr(|t|) (Intercept) -0.0003084 0.0007220 -0.4270.670 ror_spi_resn 0.0363940 0.0706150 0.5150.607 Residual standard error: 0.008016 on 123 degrees of freedom Multiple R-squared: 0.002155, Adjusted R-squared: -0.005958 F-statistic: 0.2656 on 1 and 123 DF, p-value: 0.6072 / I did several tests for assessing the quality of the estimation (like breusch-pagan, breusch-godfrey, chow-breakpoint, arch lm tests). The model has now clearly a problem with autocorrelation as you can see in de images below: http://r.789695.n4.nabble.com/file/n4631336/resid_resn.png http://r.789695.n4.nabble.com/file/n4631336/pacf_resid_resn.png To take into account the problem of autocorrelation, I did a gls estimation with an AR(1) process and get the following output: / summary(gls(ror_resn~ror_spi_resn, correlation=corARMA(p=1), method=ML)) Generalized least squares fit by maximum likelihood Model: ror_resn ~ ror_spi_resn Data: NULL AIC BIC logLik -859.0308 -847.7176 433.5154 Correlation Structure: AR(1) Formula: ~1 Parameter estimate(s): Phi -0.3182399 Coefficients: Value Std.Errort-value p-value (Intercept) -0.00034277 0.00052344 -0.6548430 0.5138 ror_spi_resn 0.04337265 0.06741179 0.6433986 0.5212 Correlation: (Intr) ror_spi_resn -0.159 Standardized residuals: Min Q1 Med Q3 Max -3.21202187 -0.38283220 0.03863226 0.50313857 3.24224614 Residual standard error: 0.007953852 Degrees of freedom: 125 total; 123 residual/ I plot acf and pacf again to assess the changes in autocorrelation. But interestingly, there is no change in the plots, they are equal to the images above... Can anyone give advice on how to handle this problem? There is the possibility that I am clearly on the wrong path. I am still a beginner in using R. Furthermore, I did the same procedure with EVIEWS (also implementing AR(1) process) and the model gives different results for the coefficients and error terms. Regards Andi /Output EVIEWS: Dependent Variable: ROR_RESN Method: Least Squares Date: 05/25/12 Time: 17:17 Sample (adjusted): 2 125 Included observations: 124 after adjustments Convergence achieved after 7 iterations VariableCoefficient Std. Error t-Statistic Prob. C -0.000409 0.000525-0.779074 0.4375 ROR_SPI_RESN0.0529960.0677940.7817160.4359 AR(1) -0.314260 0.085592-3.671586 0.0004 R-squared 0.104144Mean dependent var -0.000365 Adjusted R-squared 0.089337S.D. dependent var 0.007945 S.E. of regression 0.007581Akaike info criterion -6.902354 Sum squared resid 0.006955Schwarz criterion -6.834122 Log likelihood 430.9460Hannan-Quinn criter. -6.874637 F-statistic 7.033211Durbin-Watson stat 2.070520 Prob(F-statistic) 0.001289 Inverted AR Roots-.31 / -- View this message in context: http://r.789695.n4.nabble.com/Problem-with-Autocorrelation-and-GLS-Regression-tp4631336.html Sent from the R help mailing list archive at Nabble.com. __ R-help@r-project.org 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] Breaking up a vector
Hi all, My problem is as follows: I want to run a loop which calculates two values and stores them in vectors r and rv, respectively. They're calculated from some vector x with length a multiple of 7. x - c(1:2058) I need to difference the values but it would be incorrect to difference it all in x, it has to be broken up first. I've tried the following: r - c(1:294)*0 rv - c(1:294)*0 #RUN A LOOP WHERE YOU INPUT THE lx[(i-1)*7:i*7] INTO Z for (i in 1:294){ #CREATE A NEW VECTOR OF LENGTH 7 z - NULL length(z)=7 dz - NULL dz2 - NULL #STORE THE VALUES IN z z - lx[1+(i-1)*7:(i)*7] #THEN DIFFERENCE THOSE #THIS IS r_t,i,m dz=diff(z) #SUM THIS UP AND STORE IT IN r, THIS IS r_t r[i] - sum(dz) #SUM UP THE SQUARES AND STORE IT IN rv, THIS IS RV_t dz2 - dz^2 rv[i] - sum(dz2) #END THE LOOP } However, the window seems to expand for some reason, so z ends up being a much longer vector than it should be and full of NAs. Any help or advice is much appreciated. Aodhán -- View this message in context: http://r.789695.n4.nabble.com/Breaking-up-a-vector-tp4631329.html Sent from the R help mailing list archive at Nabble.com. __ R-help@r-project.org 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] Problem sourcing file
Hi, Try source(File.R) A.K. - Original Message - From: Marta Tolós marta.to...@gtd.es To: r-help@r-project.org Cc: Sent: Friday, May 25, 2012 10:08 AM Subject: [R] Problem sourcing file Hi all, I created a file to define some functions. When I try to source this file, sometimes it works but sometimes I get the following error: Source(‘File.R’) Error in srcfilecopy(filename, lines, file.info(filename)[1, mtime]) : unused argument(s) (file.info(filename)[1, mtime]) It works when I just started the R session, but after using some libraries when I do the source of the file again, I get this error. I can not really follow what steps aret he ones that bring me to the error, I only know that sometimes it appears. Does someone know the possible cause? Thanks! Marta [[alternative HTML version deleted]] __ R-help@r-project.org 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@r-project.org 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] Rolling Sample VAR
Hi. rollapply function for zoo package could be a useful here. library(zoo) ?rollapply Andrija On Fri, May 25, 2012 at 5:22 PM, bantex bantexmutat...@hotmail.com wrote: hi guys, I am using trivariate VAR model to get 10 step ahead orthogonalized impulse response functions. I want to use rolling sample analysis on the coefficients of the irf but I have no idea how to do that. I looked through the forums but I can't seem to find any solutions. Any suggestions would be helpful. B -- View this message in context: http://r.789695.n4.nabble.com/Rolling-Sample-VAR-tp4631328.html Sent from the R help mailing list archive at Nabble.com. __ R-help@r-project.org 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. [[alternative HTML version deleted]] __ R-help@r-project.org 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] count number of groups
length(unique(ID)) Michael On Fri, May 25, 2012 at 11:38 AM, Charles Determan Jr deter...@umn.edu wrote: Hello, Simple question that I am stuck on and can't seem to find an answer in the help files currently. I have a list which contains repeated ID's. I would like to have R count the number of ID's. For example: ID=c(1,1,1,1,2,2,2,2,3,3,3,3) as.data.frame(ID) Clearly, there are 3 groups. How would I have R give me the summary: ID 3 Many thanks, Charles [[alternative HTML version deleted]] __ R-help@r-project.org 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@r-project.org 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] count number of groups
Hi. try using table function: ID=c(1,1,1,1,2,2,2,2,3,3,3,3) table(IF) ID 1 2 3 4 4 4 Also check ?tapply function Andrija On Fri, May 25, 2012 at 5:38 PM, Charles Determan Jr deter...@umn.eduwrote: Hello, Simple question that I am stuck on and can't seem to find an answer in the help files currently. I have a list which contains repeated ID's. I would like to have R count the number of ID's. For example: ID=c(1,1,1,1,2,2,2,2,3,3,3,3) as.data.frame(ID) Clearly, there are 3 groups. How would I have R give me the summary: ID 3 Many thanks, Charles [[alternative HTML version deleted]] __ R-help@r-project.org 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. [[alternative HTML version deleted]] __ R-help@r-project.org 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] R does not recognise columns and rows as they are supposed to be
Yes I did so. Yes the first values are the right ones: - -. so this meant that I should consider my data as: double/4/little Is it so? file - C:\\Users\\aalyaari\\Documents\\INRA\\WFD_reprocessed\\dialyswco\\2001\\SWdown_200101_01.img for(what in c(double, integer)) { + for(size in c(4, 8)) { + for(endian in c(little, big)) { + cat(sep=, what, /, size, /, endian, :\n ); + print(readBin(file, what=what, size=size, endian=endian, n=6)) + } + } + } double/4/little: [1] - - - - - - double/4/big: [1] 5.520452e-39 5.520452e-39 5.520452e-39 5.520452e-39 5.520452e-39 5.520452e-39 double/8/little: [1] -5.592396e+29 -5.592396e+29 -5.592396e+29 -5.592396e+29 -5.592396e+29 -5.592396e+29 double/8/big: [1] 1.563804e-307 1.563804e-307 1.563804e-307 1.563804e-307 1.563804e-307 1.563804e-307 integer/4/little: [1] -971228160 -971228160 -971228160 -971228160 -971228160 -971228160 integer/4/big: [1] 3939526 3939526 3939526 3939526 3939526 3939526 integer/8/little: [1] -971228160 -971228160 -971228160 -971228160 -971228160 -971228160 integer/8/big: [1] 3939526 3939526 3939526 3939526 3939526 3939526 -- View this message in context: http://r.789695.n4.nabble.com/R-does-not-recognise-columns-and-rows-as-they-are-supposed-to-be-tp4631217p4631344.html Sent from the R help mailing list archive at Nabble.com. __ R-help@r-project.org 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] Correlograms: using boxes and different variables on rows and columns
In general, when you have a question about a package, it is best to contact the package author directly. (In this case, me). 1. Easy. You just have to define your own panel function. I just modified panel.shade to create panel.bar panel.bar - function(x, y, corr=NULL, ...){ usr - par()$usr minx - usr[1]; maxx - usr[2] miny - usr[3]; maxy - usr[4] if (is.null(corr)) corr - cor(x, y, use = pair) ncol - 14 pal - col.corrgram(ncol) col.ind - as.numeric(cut(corr, breaks = seq(from = -1, to = 1, length = ncol + 1), include.lowest = TRUE)) col.bar - pal[col.ind] if(corr 0) { maxy - miny + (maxy-miny) * abs(corr) rect(minx, miny, maxx, maxy, col = pal[col.ind], border = lightgray) } else if (corr 0){ miny - maxy - (maxy-miny)*corr rect(minx, miny, maxx, maxy, col = pal[col.ind], border = lightgray) } } corrgram(auto, order=TRUE, main=Auto data (PC order), upper.panel=panel.bar) 2. Harder. You need to create your own copy of the corrgram function and change it. Look for the call to par() and change the number of rows and columns. Then change the loops over i and j to include only the row and column numbers that you want instead of all rows and columns. Kevin On Fri, May 25, 2012 at 8:38 AM, dadrivr dadr...@gmail.com wrote: I'm trying to make correlograms using corrgram. See below for a simple example. library(corrgram) data(baseball) vars1 - c(Assists,Atbat,Errors,Hits,Homer,logSal) vars2 - c(Putouts,RBI,Runs,Walks,Years) corrgram(baseball[,vars2],lower.panel=panel.shade, upper.panel=panel.pie) I am having two problems: 1) I want to change the visual to bars (see Figure 1 on p. 3: http://www.datavis.ca/papers/corrgram.pdf). I tried changing the code for the upper panel to include bars, but it doesn't appear correctly: corrgram(baseball[,vars2],lower.panel=panel.shade, upper.panel=panel.bars) 2) I want to display one set of variables in the columns (vars1) and another set of variables in the rows (vars2). The reason I want to keep one set of variables in the columns and another set of variables in the rows is because I have many variables and am only interested in the correlations of vars1 with vars2 (and not of the intercorrelations of variables among vars1 or among vars2). Thus, the correlogram with separate variables in the rows and columns would be more condensed and easier to examine visually. Can I address these issues in corrgram, or is there another package that will allow me to do that? Thanks in advance. -- View this message in context: http://r.789695.n4.nabble.com/Correlograms-using-boxes-and-different-variables-on-rows-and-columns-tp4631309.html Sent from the R help mailing list archive at Nabble.com. __ R-help@r-project.org 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. -- Kevin Wright __ R-help@r-project.org 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] Breaking up a vector
Learn how to put parentheses in expression when you do not know what the operator precedence is: z - lx[(1+(i-1)*7):((i)*7)] On Fri, May 25, 2012 at 11:29 AM, AOLeary aodha...@gmail.com wrote: Hi all, My problem is as follows: I want to run a loop which calculates two values and stores them in vectors r and rv, respectively. They're calculated from some vector x with length a multiple of 7. x - c(1:2058) I need to difference the values but it would be incorrect to difference it all in x, it has to be broken up first. I've tried the following: r - c(1:294)*0 rv - c(1:294)*0 #RUN A LOOP WHERE YOU INPUT THE lx[(i-1)*7:i*7] INTO Z for (i in 1:294){ #CREATE A NEW VECTOR OF LENGTH 7 z - NULL length(z)=7 dz - NULL dz2 - NULL #STORE THE VALUES IN z z - lx[1+(i-1)*7:(i)*7] #THEN DIFFERENCE THOSE #THIS IS r_t,i,m dz=diff(z) #SUM THIS UP AND STORE IT IN r, THIS IS r_t r[i] - sum(dz) #SUM UP THE SQUARES AND STORE IT IN rv, THIS IS RV_t dz2 - dz^2 rv[i] - sum(dz2) #END THE LOOP } However, the window seems to expand for some reason, so z ends up being a much longer vector than it should be and full of NAs. Any help or advice is much appreciated. Aodhán -- View this message in context: http://r.789695.n4.nabble.com/Breaking-up-a-vector-tp4631329.html Sent from the R help mailing list archive at Nabble.com. __ R-help@r-project.org 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. -- Jim Holtman Data Munger Guru What is the problem that you are trying to solve? Tell me what you want to do, not how you want to do it. __ R-help@r-project.org 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] Filling NA with cumprod?
This calls for a trick I have seen before on this list. Once you understand it, you will be able to apply it to many similar problems. The key is the ave function, which applies a function to various groups of values in a vector. a - c(1, 2, 3, NA, NA, 6, 7, NA, NA, 10) f - c(0.9, 1.1, 0.9, 1.1, 0.9, 1.1, 0.9, 1.1, 0.9, 1.1) at - ifelse( is.na(a), f, a ) lt - cumsum( !is.na( a ) ) cbind( lt, at ) # see the pattern of levels that will control ave ave( at, lt, FUN=cumprod ) or in one statement ave( ifelse( is.na(a), f, a ), cumsum( !is.na( a ) ), FUN=cumprod ) When learning, the trickiest step is defining the vector of levels. Usually a cumsum of booleans that mark transitions is involved. Sometimes rev(test(rev(data can be useful. On Fri, 25 May 2012, David L Carlson wrote: This will loop only as many times as the largest number of consecutive NA's but uses vectorization within the loop. As currently defined, it will loop forever if the first value is NA. a - c(1, 2, 3, NA, NA, 6, 7, NA, NA, 10) f - c(0.9, 1.1, 0.9, 1.1, 0.9, 1.1, 0.9, 1.1, 0.9, 1.1) a1 - a alag - c(NA, a1[1:length(a1)-1]) # change NA to the value to use if the first value in a is NA while (sum(is.na(a1)) 0) { a1 - ifelse(is.na(a1), f*alag, a1) alag - c(NA, a1[1:length(a1)-1]) } -- David L Carlson Associate Professor of Anthropology Texas AM University College Station, TX 77843-4352 -Original Message- From: r-help-boun...@r-project.org [mailto:r-help-bounces@r- project.org] On Behalf Of Igor Reznikovsky Sent: Friday, May 25, 2012 9:08 AM To: Petr Savicky Cc: r-help@r-project.org Subject: Re: [R] Filling NA with cumprod? Hello Petr, Yes, I was hoping to avoid using loops. If nothing else works, I will take approach as the last resort. Thank you, Igor. On May 25, 2012 2:26 AM, Petr Savicky savi...@cs.cas.cz wrote: On Thu, May 24, 2012 at 08:24:38PM -0700, igorre25 wrote: Hello, I need to build certain interpolation logic using R. Unfortunately, I just started using R, and I'm not familiar with lots of advanced or just convenient features of the language to make this simpler. So I struggled for few days and pretty much reduced the whole exercise to the following problem, which I cannot resolve: Assume we have a vector of some values with NA: a - c(1, 2, 3, NA, NA, 6, 7, NA, NA, 10) and some coefficients as a vector of the same length: f - c(0.9, 1.1, 0.9, 1.1, 0.9, 1.1, 0.9, 1.1, 0.9, 1.1) I need to come up with function to get the following output o[1] = a[1] o[2] = a[2] o[3] = a[3] o[4] = o[3]*[f3] # Because a[3] is NA o[5] = o[4]*[f4] # Because a[4] is NA; This looks like recursive calculations; If the rest of the elements we NA, I would use a * c(rep(1, 3), cumprod(f[3:9])), but that's not the case o[6] = a[6] # Not NA anymore o[7] = a[7] o[8] = o[7]*f[7] # Again a[8] is NA o[9] = o[8]*f[8] o[10] = a[10] # Not NA Even though my explanation may seems complex, in reality the requirement is pretty simple and in Excel is achieved with a very short formula. The need to use R is to demonstrate capabilities of the language and then to expand to more complex problems. Hello: How is the output defined, if a[1] is NA? I think, you are not asking for a loop solution. However, in this case, it can be a reasonable option. For example a - c(1, 2, 3, NA, NA, 6, 7, NA, NA, 10) f - c(0.9, 1.1, 0.9, 1.1, 0.9, 1.1, 0.9, 1.1, 0.9, 1.1) n - length(a) o - rep(NA, times=n) prev - 1 for (i in 1:n) { if (is.na(a[i])) { o[i] - f[i]*prev } else { o[i] - a[i] } prev - o[i] } A more straightforward translation of the Excel formulas is getCell - function(i) { if (i == 0) return(1) if (is.na(a[i])) { return(f[i]*getCell(i-1)) } else { return(a[i]) } } x - rep(NA, times=n) for (i in 1:n) { x[i] - getCell(i) } identical(o, x) # [1] TRUE Petr Savicky. __ R-help@r-project.org 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. [[alternative HTML version deleted]] __ R-help@r-project.org 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@r-project.org 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. --- Jeff NewmillerThe . . Go Live...
Re: [R] Problem with Autocorrelation and GLS Regression
Hi: I don't have time to look at it carefully but, at a glance, you're not getting a significant ror_spi_resn coeffficent so worrying about residuals being auto-correlated is jumping the gun because you're not really filtering anything in the first place. when you say, market model, I don't know if you're referring to CAPM but, generally speaking, CAPM wouldn't be run using daily data ( too noisy ). Eric has a nice example of building a CAPM model in his S+Finmetrics book. Mark P.S: I wouldn't worry about the EVIEW differences. They're close enough for government work ! and these estimation algorithms can vary in their details. On Fri, May 25, 2012 at 11:42 AM, and_mue and_muel...@bluewin.ch wrote: Hi, I have a problem with a regression I try to run. I did an estimation of the market model with daily data. You can see to output below: / summary(regression_resn) Time series regression with ts data: Start = -150, End = -26 Call: dynlm(formula = ror_resn ~ ror_spi_resn) Residuals: Min 1Q Median 3QMax -0.0255690 -0.0030378 0.0002787 0.0039887 0.0257857 Coefficients: Estimate Std. Error t value Pr(|t|) (Intercept) -0.0003084 0.0007220 -0.4270.670 ror_spi_resn 0.0363940 0.0706150 0.5150.607 Residual standard error: 0.008016 on 123 degrees of freedom Multiple R-squared: 0.002155, Adjusted R-squared: -0.005958 F-statistic: 0.2656 on 1 and 123 DF, p-value: 0.6072 / I did several tests for assessing the quality of the estimation (like breusch-pagan, breusch-godfrey, chow-breakpoint, arch lm tests). The model has now clearly a problem with autocorrelation as you can see in de images below: http://r.789695.n4.nabble.com/file/n4631336/resid_resn.png http://r.789695.n4.nabble.com/file/n4631336/pacf_resid_resn.png To take into account the problem of autocorrelation, I did a gls estimation with an AR(1) process and get the following output: / summary(gls(ror_resn~ror_spi_resn, correlation=corARMA(p=1), method=ML)) Generalized least squares fit by maximum likelihood Model: ror_resn ~ ror_spi_resn Data: NULL AIC BIC logLik -859.0308 -847.7176 433.5154 Correlation Structure: AR(1) Formula: ~1 Parameter estimate(s): Phi -0.3182399 Coefficients: Value Std.Errort-value p-value (Intercept) -0.00034277 0.00052344 -0.6548430 0.5138 ror_spi_resn 0.04337265 0.06741179 0.6433986 0.5212 Correlation: (Intr) ror_spi_resn -0.159 Standardized residuals: Min Q1 Med Q3 Max -3.21202187 -0.38283220 0.03863226 0.50313857 3.24224614 Residual standard error: 0.007953852 Degrees of freedom: 125 total; 123 residual/ I plot acf and pacf again to assess the changes in autocorrelation. But interestingly, there is no change in the plots, they are equal to the images above... Can anyone give advice on how to handle this problem? There is the possibility that I am clearly on the wrong path. I am still a beginner in using R. Furthermore, I did the same procedure with EVIEWS (also implementing AR(1) process) and the model gives different results for the coefficients and error terms. Regards Andi /Output EVIEWS: Dependent Variable: ROR_RESN Method: Least Squares Date: 05/25/12 Time: 17:17 Sample (adjusted): 2 125 Included observations: 124 after adjustments Convergence achieved after 7 iterations VariableCoefficient Std. Error t-Statistic Prob. C -0.000409 0.000525-0.779074 0.4375 ROR_SPI_RESN0.0529960.0677940.7817160.4359 AR(1) -0.314260 0.085592-3.671586 0.0004 R-squared 0.104144Mean dependent var -0.000365 Adjusted R-squared 0.089337S.D. dependent var 0.007945 S.E. of regression 0.007581Akaike info criterion -6.902354 Sum squared resid 0.006955Schwarz criterion -6.834122 Log likelihood 430.9460Hannan-Quinn criter. -6.874637 F-statistic 7.033211Durbin-Watson stat 2.070520 Prob(F-statistic) 0.001289 Inverted AR Roots-.31 / -- View this message in context: http://r.789695.n4.nabble.com/Problem-with-Autocorrelation-and-GLS-Regression-tp4631336.html Sent from the R help mailing list archive at Nabble.com. __ R-help@r-project.org 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. [[alternative HTML version deleted]] __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide
Re: [R] R does not recognise columns and rows as they are supposed to be
In the absence of documentation for the file format, what=double,size=4,endian=little would be a good guess. Many problems people report on this list are due to errors in reading data into R. Converting data from one format to another is always error-prone and you need to check that the conversion was done correctly. Don't try to analyze the imported data until you have checked the import process. E.g., you think your files should contain 360*720 4-byte values, so look at the number of bytes in the file with file.info(file)$size and see if it matches the expected 360*720*4. After you read the data into the matrix, x, look at the quartiles with quantile(x). Do those -'s represent missing values? If so, make them NA's with is.na(x) - x==- and look at the quartiles again, with quantile(x,na.rm=TRUE). Take a look at the pattern of the data with image(x) or image(array(rank(x), dim=dim(x))) (or plot(x[,10]) or plot(x[20,]), etc.). If any these things look odd, fix the import procedure before doing the real analysis of the data. Bill Dunlap Spotfire, TIBCO Software wdunlap tibco.com -Original Message- From: r-help-boun...@r-project.org [mailto:r-help-boun...@r-project.org] On Behalf Of Jonsson Sent: Friday, May 25, 2012 8:58 AM To: r-help@r-project.org Subject: Re: [R] R does not recognise columns and rows as they are supposed to be Yes I did so. Yes the first values are the right ones: - -. so this meant that I should consider my data as: double/4/little Is it so? file - C:\\Users\\aalyaari\\Documents\\INRA\\WFD_reprocessed\\dialyswco\\2001\\SWdow n_200101_01.img for(what in c(double, integer)) { + for(size in c(4, 8)) { + for(endian in c(little, big)) { + cat(sep=, what, /, size, /, endian, :\n ); + print(readBin(file, what=what, size=size, endian=endian, n=6)) + } + } + } double/4/little: [1] - - - - - - double/4/big: [1] 5.520452e-39 5.520452e-39 5.520452e-39 5.520452e-39 5.520452e-39 5.520452e-39 double/8/little: [1] -5.592396e+29 -5.592396e+29 -5.592396e+29 -5.592396e+29 -5.592396e+29 -5.592396e+29 double/8/big: [1] 1.563804e-307 1.563804e-307 1.563804e-307 1.563804e-307 1.563804e-307 1.563804e-307 integer/4/little: [1] -971228160 -971228160 -971228160 -971228160 -971228160 -971228160 integer/4/big: [1] 3939526 3939526 3939526 3939526 3939526 3939526 integer/8/little: [1] -971228160 -971228160 -971228160 -971228160 -971228160 -971228160 integer/8/big: [1] 3939526 3939526 3939526 3939526 3939526 3939526 -- View this message in context: http://r.789695.n4.nabble.com/R-does-not-recognise- columns-and-rows-as-they-are-supposed-to-be-tp4631217p4631344.html Sent from the R help mailing list archive at Nabble.com. __ R-help@r-project.org 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@r-project.org 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] R does not recognise columns and rows as they are supposed to be
The trick may be behind not reading the files properly is that all my 365 files donot have the same name. for example: files from number 1 to number9 are named for the first month: SWdown_200101_01.img SWdown_200101_09.img files from number 10 to number30 are named: SWdown_200101_10.img SWdown_200101_30.img And so on for the second month: files from number 1 to number9 are named: SWdown_200102_01.img SWdown_200102_09.img files from number 10 to number30 are named: SWdown_200102_10.img SWdown_200102_30.img and in my code I just set the dierctory: dir1- list.files(C:\\Users\\aalyaari\\Desktop\\New folder (11)\\, *.img, full.names = TRUE). assuming that R would read files in order.But I do not really know if this right or I shall specify the names. X-(82:85) ; Y-(364:367) # for sellected region extract - double() dir1- list.files(C:\\Users\\aalyaari\\Desktop\\New folder (11)\\, *.bin, full.names = TRUE) for (i in 1:365) { conne - file(dir1[i], rb) file1- readBin(conne, numeric(),size=4, n=360*720, endian=little) file2-matrix(data=file1,ncol=720,nrow=360) extract[i]-mean(file2[X,Y],na.rm=TRUE) close(conne) } write.table(as.double(extract),C:\\Users\\aalyaari\\Desktop\\New folder (10)\\new6.txt) -- View this message in context: http://r.789695.n4.nabble.com/R-does-not-recognise-columns-and-rows-as-they-are-supposed-to-be-tp4631217p4631352.html Sent from the R help mailing list archive at Nabble.com. __ R-help@r-project.org 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] count number of groups
Thank you Michael, However, this only provides the number of groups without a column label. Is there a way to have it give the count with the 'ID' label? Regards, Charles On Fri, May 25, 2012 at 10:52 AM, R. Michael Weylandt michael.weyla...@gmail.com wrote: length(unique(ID)) Michael On Fri, May 25, 2012 at 11:38 AM, Charles Determan Jr deter...@umn.edu wrote: Hello, Simple question that I am stuck on and can't seem to find an answer in the help files currently. I have a list which contains repeated ID's. I would like to have R count the number of ID's. For example: ID=c(1,1,1,1,2,2,2,2,3,3,3,3) as.data.frame(ID) Clearly, there are 3 groups. How would I have R give me the summary: ID 3 Many thanks, Charles [[alternative HTML version deleted]] __ R-help@r-project.org 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. [[alternative HTML version deleted]] __ R-help@r-project.org 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] Problem with Autocorrelation and GLS Regression
For the analysis I follow the approach of Keown Pinkerton ( http://e-m-h.org/KePi81.pdf http://e-m-h.org/KePi81.pdf ). They do also use daily data to compute alphas and betas of the market model. These estimated coefficients are then used to estimate abnormal returns for a given period. market model would be: Rjt=ajt+bjt*Rmt+ejt Rjt is the return of company j on day t Rmt is the return of the market on day t (Index) ejt is the unsystematic component of firm j's return after estimation I want to estimate abnormal returns: êjt=Rjt-(âj+bj*Rmt) aj and bj are the estimatet coefficients from the equation above. -- View this message in context: http://r.789695.n4.nabble.com/Problem-with-Autocorrelation-and-GLS-Regression-tp4631336p4631355.html Sent from the R help mailing list archive at Nabble.com. __ R-help@r-project.org 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] count number of groups
That works if I want a count of each group but I needed a count of the number of groups. Michael answered that question with length(unique(ID)) However, this doesn't supply a title, it is just a number. I need it to still have the identifier 'ID'. Regards, Charles On Fri, May 25, 2012 at 11:50 AM, Steve Friedman skfgla...@gmail.comwrote: ?table On May 25, 2012 11:46 AM, Charles Determan Jr deter...@umn.edu wrote: Hello, Simple question that I am stuck on and can't seem to find an answer in the help files currently. I have a list which contains repeated ID's. I would like to have R count the number of ID's. For example: ID=c(1,1,1,1,2,2,2,2,3,3,3,3) as.data.frame(ID) Clearly, there are 3 groups. How would I have R give me the summary: ID 3 Many thanks, Charles [[alternative HTML version deleted]] __ R-help@r-project.org 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. [[alternative HTML version deleted]] __ R-help@r-project.org 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] count number of groups
You'll have to be a little trickier if you want it to be smart and pick up the name: [or I'm missing something obvious] yourFunc - function(x){ dsx - deparse(substitute(x)) x - length(unique(x)) names(x) - dsx x } yourFunc(ID) yourFunc(ID^2) yourFunc(ID[ID==2]) etc. Hope this helps, M On Fri, May 25, 2012 at 12:42 PM, Charles Determan Jr deter...@umn.edu wrote: Thank you Michael, However, this only provides the number of groups without a column label. Is there a way to have it give the count with the 'ID' label? Regards, Charles On Fri, May 25, 2012 at 10:52 AM, R. Michael Weylandt michael.weyla...@gmail.com wrote: length(unique(ID)) Michael On Fri, May 25, 2012 at 11:38 AM, Charles Determan Jr deter...@umn.edu wrote: Hello, Simple question that I am stuck on and can't seem to find an answer in the help files currently. I have a list which contains repeated ID's. I would like to have R count the number of ID's. For example: ID=c(1,1,1,1,2,2,2,2,3,3,3,3) as.data.frame(ID) Clearly, there are 3 groups. How would I have R give me the summary: ID 3 Many thanks, Charles [[alternative HTML version deleted]] __ R-help@r-project.org 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@r-project.org 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] Problem sourcing file
It does not have anything to do with the sourcing. Rather, it lies in the code that is in your File.R, which is not given here. --- Jeff NewmillerThe . . Go Live... DCN:jdnew...@dcn.davis.ca.usBasics: ##.#. ##.#. Live Go... Live: OO#.. Dead: OO#.. Playing Research Engineer (Solar/BatteriesO.O#. #.O#. with /Software/Embedded Controllers) .OO#. .OO#. rocks...1k --- Sent from my phone. Please excuse my brevity. arun smartpink...@yahoo.com wrote: Hi, Try source(File.R) A.K. - Original Message - From: Marta Tolós marta.to...@gtd.es To: r-help@r-project.org Cc: Sent: Friday, May 25, 2012 10:08 AM Subject: [R] Problem sourcing file Hi all, I created a file to define some functions. When I try to source this file, sometimes it works but sometimes I get the following error: Source(‘File.R’) Error in srcfilecopy(filename, lines, file.info(filename)[1, mtime]) : unused argument(s) (file.info(filename)[1, mtime]) It works when I just started the R session, but after using some libraries when I do the source of the file again, I get this error. I can not really follow what steps aret he ones that bring me to the error, I only know that sometimes it appears. Does someone know the possible cause? Thanks! Marta [[alternative HTML version deleted]] __ R-help@r-project.org 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@r-project.org 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@r-project.org 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] count number of groups
You did: ID=c(1,1,1,1,2,2,2,2,3,3,3,3) as.data.frame(ID) and I infer that you want the number of groups in each column of the data.frame. First, make an example of your data.frame D - data.frame(ID, Name=rep(state.name[1:7],len=length(ID))) (note I use data.frame, not as.data.frame, so it gets the column names that I want). Now use sapply() (or the related vapply()): sapply(D, function(column)length(unique(column))) ID Name 37 Bill Dunlap Spotfire, TIBCO Software wdunlap tibco.com -Original Message- From: r-help-boun...@r-project.org [mailto:r-help-boun...@r-project.org] On Behalf Of Charles Determan Jr Sent: Friday, May 25, 2012 9:55 AM To: Steve Friedman Cc: r-help@r-project.org Subject: Re: [R] count number of groups That works if I want a count of each group but I needed a count of the number of groups. Michael answered that question with length(unique(ID)) However, this doesn't supply a title, it is just a number. I need it to still have the identifier 'ID'. Regards, Charles On Fri, May 25, 2012 at 11:50 AM, Steve Friedman skfgla...@gmail.comwrote: ?table On May 25, 2012 11:46 AM, Charles Determan Jr deter...@umn.edu wrote: Hello, Simple question that I am stuck on and can't seem to find an answer in the help files currently. I have a list which contains repeated ID's. I would like to have R count the number of ID's. For example: ID=c(1,1,1,1,2,2,2,2,3,3,3,3) as.data.frame(ID) Clearly, there are 3 groups. How would I have R give me the summary: ID 3 Many thanks, Charles [[alternative HTML version deleted]] __ R-help@r-project.org 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. [[alternative HTML version deleted]] __ R-help@r-project.org 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@r-project.org 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] Query about creating time sequences
Hi All, I have a query about time based sequences. I know such questions have been asked a lot on forums, but I couldnt find the exact thing that I was looking for. I want to create a time-based sequence which will mimic the trading window AND would span multiple days. Something like below: 2011-01-03 09:15:00 IST 2011-01-03 09:15:01 IST 2011-01-03 15:29:59 IST 2011-01-03 15:30:00 IST 2011-01-04 09:15:00 IST 2011-01-04 09:15:01 IST 2011-01-04 15:29:59 IST 2011-01-04 15:30:00 IST Kindly notice the change of date in the sequence. The Indian Equity markets open at 09:15:00 and close at 15:30:00. I have equity data that spans 124 days, and I need to create a corresponding sequence which I will later use to regularize the irregular dataset to make a regular time-series. I was able to accomplish this task for a single day (i.e. creating a sequence then merging my dataset with it and use na.locf to make my dataset regular) but am unable to create a sequence for 'n' number of days. Can anyone help me with this? If it is of any help, I have a file which contains all the dates for which I need the sequence. The dput of the file is placed at the end of the email. One option is to create sequences for the entire days and then later remove all these records after merging. Although I havent checked the feasibility of this method, it would be complex and more so it will increase the data four folds (I already have 2 million records in the dataframe which I have to make regular). Another approach that I could think of was to make a timebased sequence based on the date from the file and then use a loop to append one sequence after another. But am not having much success there either. Any kind of help would be greatly appreciated. Thanks and regards, Shivam structure(list(20110103, 20110104, 20110105, 20110106, 20110107, 20110110, 20110111, 20110112, 20110113, 20110114, 20110117, 20110118, 20110119, 20110120, 20110121, 20110124, 20110125, 20110127, 20110128, 20110131, 20110201, 20110202, 20110203, 20110204, 20110207, 20110208, 20110209, 20110210, 20110211, 20110214, 20110215, 20110216, 20110217, 20110218, 20110221, 20110222, 20110223, 20110224, 20110225, 20110228, 20110301, 20110303, 20110304, 20110307, 20110308, 20110309, 20110310, 20110311, 20110314, 20110315, 20110316, 20110317, 20110318, 20110321, 20110322, 20110323, 20110324, 20110325, 20110328, 20110329, 20110330, 20110331, 20110401, 20110404, 20110405, 20110406, 20110407, 20110408, 20110411, 20110413, 20110415, 20110418, 20110419, 20110420, 20110421, 20110425, 20110426, 20110427, 20110428, 20110429, 20110502, 20110503, 20110504, 20110505, 20110506, 20110509, 20110510, 20110511, 20110512, 20110513, 20110516, 20110517, 20110518, 20110519, 20110520, 20110523, 20110524, 20110525, 20110526, 20110527, 20110530, 20110531, 20110601, 20110602, 20110603, 20110606, 20110607, 20110608, 20110609, 20110610, 20110613, 20110614, 20110615, 20110616, 20110617, 20110620, 20110621, 20110622, 20110623, 20110624, 20110627, 20110628, 20110629, 20110630), .Dim = c(124L, 1L), .Dimnames = list(c(X1, X2, X3, X4, X5, X6, X7, X8, X9, X10, X11, X12, X13, X14, X15, X16, X17, X18, X19, X20, X21, X22, X23, X24, X25, X26, X27, X28, X29, X30, X31, X32, X33, X34, X35, X36, X37, X38, X39, X40, X41, X42, X43, X44, X45, X46, X47, X48, X49, X50, X51, X52, X53, X54, X55, X56, X57, X58, X59, X60, X61, X62, X63, X64, X65, X66, X67, X68, X69, X70, X71, X72, X73, X74, X75, X76, X77, X78, X79, X80, X81, X82, X83, X84, X85, X86, X87, X88, X89, X90, X91, X92, X93, X94, X95, X96, X97, X98, X99, X100, X101, X102, X103, X104, X105, X106, X107, X108, X109, X110, X111, X112, X113, X114, X115, X116, X117, X118, X119, X120, X121, X122, X123, X124), NULL)) [[alternative HTML version deleted]] __ R-help@r-project.org 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] Problem sourcing file
On 25/05/2012 10:08 AM, Marta Tolós wrote: Hi all, I created a file to define some functions. When I try to source this file, sometimes it works but sometimes I get the following error: Source(‘File.R’) Those aren't proper quotes, and source() shouldn't be capitalized, and you didn't tell us what version of R you are using. Duncan Murdoch Error in srcfilecopy(filename, lines, file.info(filename)[1, mtime]) : unused argument(s) (file.info(filename)[1, mtime]) It works when I just started the R session, but after using some libraries when I do the source of the file again, I get this error. I can not really follow what steps aret he ones that bring me to the error, I only know that sometimes it appears. Does someone know the possible cause? Thanks! Marta [[alternative HTML version deleted]] __ R-help@r-project.org 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@r-project.org 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] Problem with Autocorrelation and GLS Regression
Hi: Thanks for the correction and reference. Eric uses monthly returns in the example in his book and I would think that using daily data would result in very unstable betas but I've been wrong before. Hopefully others can comment. Mark On Fri, May 25, 2012 at 12:44 PM, and_mue and_muel...@bluewin.ch wrote: For the analysis I follow the approach of Keown Pinkerton ( http://e-m-h.org/KePi81.pdf http://e-m-h.org/KePi81.pdf ). They do also use daily data to compute alphas and betas of the market model. These estimated coefficients are then used to estimate abnormal returns for a given period. market model would be: Rjt=ajt+bjt*Rmt+ejt Rjt is the return of company j on day t Rmt is the return of the market on day t (Index) ejt is the unsystematic component of firm j's return after estimation I want to estimate abnormal returns: êjt=Rjt-(âj+bj*Rmt) aj and bj are the estimatet coefficients from the equation above. -- View this message in context: http://r.789695.n4.nabble.com/Problem-with-Autocorrelation-and-GLS-Regression-tp4631336p4631355.html Sent from the R help mailing list archive at Nabble.com. __ R-help@r-project.org 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. [[alternative HTML version deleted]] __ R-help@r-project.org 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] count number of groups
That works perfectly, thank you very much Michael, Sincere regards, Charles On Fri, May 25, 2012 at 11:59 AM, R. Michael Weylandt michael.weyla...@gmail.com wrote: You'll have to be a little trickier if you want it to be smart and pick up the name: [or I'm missing something obvious] yourFunc - function(x){ dsx - deparse(substitute(x)) x - length(unique(x)) names(x) - dsx x } yourFunc(ID) yourFunc(ID^2) yourFunc(ID[ID==2]) etc. Hope this helps, M On Fri, May 25, 2012 at 12:42 PM, Charles Determan Jr deter...@umn.edu wrote: Thank you Michael, However, this only provides the number of groups without a column label. Is there a way to have it give the count with the 'ID' label? Regards, Charles On Fri, May 25, 2012 at 10:52 AM, R. Michael Weylandt michael.weyla...@gmail.com wrote: length(unique(ID)) Michael On Fri, May 25, 2012 at 11:38 AM, Charles Determan Jr deter...@umn.edu wrote: Hello, Simple question that I am stuck on and can't seem to find an answer in the help files currently. I have a list which contains repeated ID's. I would like to have R count the number of ID's. For example: ID=c(1,1,1,1,2,2,2,2,3,3,3,3) as.data.frame(ID) Clearly, there are 3 groups. How would I have R give me the summary: ID 3 Many thanks, Charles [[alternative HTML version deleted]] __ R-help@r-project.org 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. [[alternative HTML version deleted]] __ R-help@r-project.org 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] R does not recognise columns and rows as they are supposed to be
I tried to read only one file and get some information but this is what I got: sam=file(C:\\Users\\2001\\SWdown_200101_01.img, rb) file1- readBin(sam, double(),size=4, n=360*720) file.info(file1)$size Error in file.info(file1) : invalid filename argument dim(file1) NULL -- View this message in context: http://r.789695.n4.nabble.com/R-does-not-recognise-columns-and-rows-as-they-are-supposed-to-be-tp4631217p4631366.html Sent from the R help mailing list archive at Nabble.com. __ R-help@r-project.org 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] Filling NA with cumprod?
This is a nice trick, Jeff, thank you. I think this is what I was looking for. Thank you all. On May 25, 2012 12:18 PM, Jeff Newmiller jdnew...@dcn.davis.ca.us wrote: This calls for a trick I have seen before on this list. Once you understand it, you will be able to apply it to many similar problems. The key is the ave function, which applies a function to various groups of values in a vector. a - c(1, 2, 3, NA, NA, 6, 7, NA, NA, 10) f - c(0.9, 1.1, 0.9, 1.1, 0.9, 1.1, 0.9, 1.1, 0.9, 1.1) at - ifelse( is.na(a), f, a ) lt - cumsum( !is.na( a ) ) cbind( lt, at ) # see the pattern of levels that will control ave ave( at, lt, FUN=cumprod ) or in one statement ave( ifelse( is.na(a), f, a ), cumsum( !is.na( a ) ), FUN=cumprod ) When learning, the trickiest step is defining the vector of levels. Usually a cumsum of booleans that mark transitions is involved. Sometimes rev(test(rev(data can be useful. On Fri, 25 May 2012, David L Carlson wrote: This will loop only as many times as the largest number of consecutive NA's but uses vectorization within the loop. As currently defined, it will loop forever if the first value is NA. a - c(1, 2, 3, NA, NA, 6, 7, NA, NA, 10) f - c(0.9, 1.1, 0.9, 1.1, 0.9, 1.1, 0.9, 1.1, 0.9, 1.1) a1 - a alag - c(NA, a1[1:length(a1)-1]) # change NA to the value to use if the first value in a is NA while (sum(is.na(a1)) 0) { a1 - ifelse(is.na(a1), f*alag, a1) alag - c(NA, a1[1:length(a1)-1]) } --** David L Carlson Associate Professor of Anthropology Texas AM University College Station, TX 77843-4352 -Original Message- From: r-help-boun...@r-project.org [mailto:r-help-bounces@r- project.org] On Behalf Of Igor Reznikovsky Sent: Friday, May 25, 2012 9:08 AM To: Petr Savicky Cc: r-help@r-project.org Subject: Re: [R] Filling NA with cumprod? Hello Petr, Yes, I was hoping to avoid using loops. If nothing else works, I will take approach as the last resort. Thank you, Igor. On May 25, 2012 2:26 AM, Petr Savicky savi...@cs.cas.cz wrote: On Thu, May 24, 2012 at 08:24:38PM -0700, igorre25 wrote: Hello, I need to build certain interpolation logic using R. Unfortunately, I just started using R, and I'm not familiar with lots of advanced or just convenient features of the language to make this simpler. So I struggled for few days and pretty much reduced the whole exercise to the following problem, which I cannot resolve: Assume we have a vector of some values with NA: a - c(1, 2, 3, NA, NA, 6, 7, NA, NA, 10) and some coefficients as a vector of the same length: f - c(0.9, 1.1, 0.9, 1.1, 0.9, 1.1, 0.9, 1.1, 0.9, 1.1) I need to come up with function to get the following output o[1] = a[1] o[2] = a[2] o[3] = a[3] o[4] = o[3]*[f3] # Because a[3] is NA o[5] = o[4]*[f4] # Because a[4] is NA; This looks like recursive calculations; If the rest of the elements we NA, I would use a * c(rep(1, 3), cumprod(f[3:9])), but that's not the case o[6] = a[6] # Not NA anymore o[7] = a[7] o[8] = o[7]*f[7] # Again a[8] is NA o[9] = o[8]*f[8] o[10] = a[10] # Not NA Even though my explanation may seems complex, in reality the requirement is pretty simple and in Excel is achieved with a very short formula. The need to use R is to demonstrate capabilities of the language and then to expand to more complex problems. Hello: How is the output defined, if a[1] is NA? I think, you are not asking for a loop solution. However, in this case, it can be a reasonable option. For example a - c(1, 2, 3, NA, NA, 6, 7, NA, NA, 10) f - c(0.9, 1.1, 0.9, 1.1, 0.9, 1.1, 0.9, 1.1, 0.9, 1.1) n - length(a) o - rep(NA, times=n) prev - 1 for (i in 1:n) { if (is.na(a[i])) { o[i] - f[i]*prev } else { o[i] - a[i] } prev - o[i] } A more straightforward translation of the Excel formulas is getCell - function(i) { if (i == 0) return(1) if (is.na(a[i])) { return(f[i]*getCell(i-1)) } else { return(a[i]) } } x - rep(NA, times=n) for (i in 1:n) { x[i] - getCell(i) } identical(o, x) # [1] TRUE Petr Savicky. __** R-help@r-project.org mailing list https://stat.ethz.ch/mailman/**listinfo/r-helphttps://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/**posting-guide.htmlhttp://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. [[alternative HTML version deleted]] __** R-help@r-project.org mailing list https://stat.ethz.ch/mailman/**listinfo/r-helphttps://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/**posting-http://www.R-project.org/posting- guide.html and provide commented, minimal,
Re: [R] Problem sourcing file
What isn't proper about single quotes? --- Jeff NewmillerThe . . Go Live... DCN:jdnew...@dcn.davis.ca.usBasics: ##.#. ##.#. Live Go... Live: OO#.. Dead: OO#.. Playing Research Engineer (Solar/BatteriesO.O#. #.O#. with /Software/Embedded Controllers) .OO#. .OO#. rocks...1k --- Sent from my phone. Please excuse my brevity. Duncan Murdoch murdoch.dun...@gmail.com wrote: On 25/05/2012 10:08 AM, Marta Tolós wrote: Hi all, I created a file to define some functions. When I try to source this file, sometimes it works but sometimes I get the following error: Source(‘File.R’) Those aren't proper quotes, and source() shouldn't be capitalized, and you didn't tell us what version of R you are using. Duncan Murdoch Error in srcfilecopy(filename, lines, file.info(filename)[1, mtime]) : unused argument(s) (file.info(filename)[1, mtime]) It works when I just started the R session, but after using some libraries when I do the source of the file again, I get this error. I can not really follow what steps aret he ones that bring me to the error, I only know that sometimes it appears. Does someone know the possible cause? Thanks! Marta [[alternative HTML version deleted]] __ R-help@r-project.org 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@r-project.org 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@r-project.org 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] Problem sourcing file
On 25/05/2012 2:17 PM, Jeff Newmiller wrote: What isn't proper about single quotes? They look like directional quotes to me. Might just be the mailer... Duncan Murdoch --- Jeff NewmillerThe . . Go Live... DCN:jdnew...@dcn.davis.ca.us Basics: ##.#. ##.#. Live Go... Live: OO#.. Dead: OO#.. Playing Research Engineer (Solar/BatteriesO.O#. #.O#. with /Software/Embedded Controllers) .OO#. .OO#. rocks...1k --- Sent from my phone. Please excuse my brevity. Duncan Murdochmurdoch.dun...@gmail.com wrote: On 25/05/2012 10:08 AM, Marta Tolós wrote: Hi all, I created a file to define some functions. When I try to source this file, sometimes it works but sometimes I get the following error: Source(‘File.R’) Those aren't proper quotes, and source() shouldn't be capitalized, and you didn't tell us what version of R you are using. Duncan Murdoch Error in srcfilecopy(filename, lines, file.info(filename)[1, mtime]) : unused argument(s) (file.info(filename)[1, mtime]) It works when I just started the R session, but after using some libraries when I do the source of the file again, I get this error. I can not really follow what steps aret he ones that bring me to the error, I only know that sometimes it appears. Does someone know the possible cause? Thanks! Marta [[alternative HTML version deleted]] __ R-help@r-project.org 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@r-project.org 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@r-project.org 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] Problem sourcing file
On 25.05.2012 20:17, Jeff Newmiller wrote: What isn't proper about single quotes? Those were *directed* quotes. Uwe Ligges --- Jeff NewmillerThe . . Go Live... DCN:jdnew...@dcn.davis.ca.us Basics: ##.#. ##.#. Live Go... Live: OO#.. Dead: OO#.. Playing Research Engineer (Solar/BatteriesO.O#. #.O#. with /Software/Embedded Controllers) .OO#. .OO#. rocks...1k --- Sent from my phone. Please excuse my brevity. Duncan Murdochmurdoch.dun...@gmail.com wrote: On 25/05/2012 10:08 AM, Marta Tolós wrote: Hi all, I created a file to define some functions. When I try to source this file, sometimes it works but sometimes I get the following error: Source(‘File.R’) Those aren't proper quotes, and source() shouldn't be capitalized, and you didn't tell us what version of R you are using. Duncan Murdoch Error in srcfilecopy(filename, lines, file.info(filename)[1, mtime]) : unused argument(s) (file.info(filename)[1, mtime]) It works when I just started the R session, but after using some libraries when I do the source of the file again, I get this error. I can not really follow what steps aret he ones that bring me to the error, I only know that sometimes it appears. Does someone know the possible cause? Thanks! Marta [[alternative HTML version deleted]] __ R-help@r-project.org 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@r-project.org 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@r-project.org 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@r-project.org 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] Issues while using “lift.chart” and “adjProbScore” function from ”BCA” library
Please talk to the maintainer of the BCA *package* in order to report bugs. Uwe Ligges On 24.05.2012 06:31, aajit75 wrote: Dear List, Couple of issues while using functions from “BCA” library: 1. I am trying to use “lift.chart” function from “BCA” library, but facing issues while using model where model formula is passed as formula object in glm. When model formula is written as text, then it works fine. In my case input variables and target variables are going to change dynamically, so have to used formula as formula object as derived. Below is the sample code, taken from the package document to illustrate the issues library(BCA) data(CCS) CCS$Sample- create.samples(CCS, est=0.4, val=0.4) CCSEst- CCS[CCS$Sample == Estimation,] #Fit glm model with formula written as text CCS.glm- glm(MonthGive ~ DonPerYear + LastDonAmt + Region + YearsGive, family=binomial(logit), data=CCSEst) CCSVal- CCS[CCS$Sample == Validation,] lift.chart(c(CCS.glm), data=CCSVal, targLevel=Yes, trueResp=0.01, type=incremental, sub=Validation) #Fit glm model with formula passed as formula object fm- as.formula(MonthGive ~ DonPerYear + LastDonAmt + Region + YearsGive) CCS.glm12- glm(fm,family=binomial(logit), data=CCSEst) lift.chart(c(CCS.glm12), data=CCSVal, targLevel=Yes, trueResp=0.01, type=incremental, sub=Validation) Following error occurs, Error in if (any(yvar1 != yvar1[1])) { : missing value where TRUE/FALSE needed Is there any way out to use formula object in the model and using “lift.chart” function 2. Issue using “adjProbScore” function from the “BCA” library. (adjProbScore(model=CCS.glm, data=CCSVal1, targLevel=Yes, trueResp=0.01)) Error in parse(text = paste(as.character(, ActiveDataSet(), $, yvar, : text:1:16: unexpected '$' 1: as.character( $ ^ Above error is thrown, am I doing anything wrong? Please correct. Also, as in the case-1 above, can we use model fitted with formula object in “adjProbScore” function. Thanks in advance! Ajit -- View this message in context: http://r.789695.n4.nabble.com/Issues-while-using-lift-chart-and-adjProbScore-function-from-BCA-library-tp4631158.html Sent from the R help mailing list archive at Nabble.com. __ R-help@r-project.org 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@r-project.org 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] Multiple cbind according to filename
Matthew Ouellette mouellette89 at gmail.com writes: Hi all, I'm just a beginner with R but I have not been able to search for any relevant answer to my problem. I apologize if it has in fact been asked before. Recently I've realized that I need to combine hundreds of pairs of data frames. The filenames of the frames I need to combine have unique strings. This is my best guess as to the approach to take: filenames-list.files() filenames [1] a1.csv a2.csv b1.csv b2.csv c1.csv c2.csv alldata-lapply(filenames, read.csv, header=TRUE) names(alldata)-filenames summary(alldata) Length Class Mode a1.csv 27 data.frame list a2.csv 27 data.frame list b1.csv 27 data.frame list b2.csv 27 data.frame list c1.csv 27 data.frame list c2.csv 27 data.frame list My next step would be to cbind files that share a common string at the beginning, such as: cbind(alldata[[1]],alldata[[2]]) cbind(alldata[[3]],alldata[[4]]) cbind(alldata[[5]],alldata[[6]]) ... but file list is hundreds of files long (but is sorted alphanumerically such as in this example - not sure if this is relevant). If I had to guess, I'd do something like this: which(names(alldata)==...), to identify which elements to combine based on unique filename OR x-seq(1,length(alldata), 2) y=x+1 z-cbind(x,y) z x y [1,] 1 2 [2,] 3 4 [3,] 5 6 to use the frame created in z to combine based on rows, then use a looped cbind function (or *apply function with nested cbind function?) using the previously returned indexes to create my new combined data frames, including a step to write the frames to a new unique filename (not sure how to do that step in this context). These last steps I've tried a lot of code but nothing worth mentioning as it has all failed miserably. I appreciate the help, M [[alternative HTML version deleted]] Hi Matthew, You could try using substr() if the cbind is based on a common string in the file name just makes sure that the strings in filenames is in the same order as the files are in list.files: a1 - data.frame(col1 = seq(1,10, 1)) a2 - data.frame(col2 = seq(11,20, 1)) b1 - data.frame(col3 = seq(21,30, 1)) b2 - data.frame(col4 = seq(31,40, 1)) filenames - c(a1, a2, b1, b2) list.files - list(a1, a2, b1, b2) first.letter - substr(filenames, 1,1) unique.first.letter - unique(first.letter) l.files - list() for(i in 1:length(unique.first.letter)){ l.files[[i]] = as.data.frame(list.files[first.letter == unique.first.letter[i]]) } HTH, Ken __ R-help@r-project.org 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] Breaking up a vector
Hello, Tip: see the difference between the following two. for(i in 1:7) cat(i, :, (i-1)*7:(i)*7, \n) for(i in 1:7) cat(i, :, ((i-1)*7):(i*7), \n) (operator ':' has high precedence...) Hope this helps, Rui Barradas AOLeary wrote Hi all, My problem is as follows: I want to run a loop which calculates two values and stores them in vectors r and rv, respectively. They're calculated from some vector x with length a multiple of 7. x - c(1:2058) I need to difference the values but it would be incorrect to difference it all in x, it has to be broken up first. I've tried the following: r - c(1:294)*0 rv - c(1:294)*0 #RUN A LOOP WHERE YOU INPUT THE lx[(i-1)*7:i*7] INTO Z for (i in 1:294){ #CREATE A NEW VECTOR OF LENGTH 7 z - NULL length(z)=7 dz - NULL dz2 - NULL #STORE THE VALUES IN z z - lx[1+(i-1)*7:(i)*7] #THEN DIFFERENCE THOSE #THIS IS r_t,i,m dz=diff(z) #SUM THIS UP AND STORE IT IN r, THIS IS r_t r[i] - sum(dz) #SUM UP THE SQUARES AND STORE IT IN rv, THIS IS RV_t dz2 - dz^2 rv[i] - sum(dz2) #END THE LOOP } However, the window seems to expand for some reason, so z ends up being a much longer vector than it should be and full of NAs. Any help or advice is much appreciated. Aodhán -- View this message in context: http://r.789695.n4.nabble.com/Breaking-up-a-vector-tp4631329p4631342.html Sent from the R help mailing list archive at Nabble.com. __ R-help@r-project.org 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] subset columns from list with variable substitution
Hi there, I would like to use a list variable to select columns in a subset from a parent table: I have a data frame table with column headers a,b,c,d,e,x,y,z and list variables list1=c(a,b,c,d) list2=c(a,b,x,y,z) namelist=c(peter,paul,mary,jane) group1=c(peter,paul) group2=c(mary,jane) I would like to subset table based on the list variable in a for loop: for (i %in% namelist){ if (i %in% group1){table2-subset(table, select=list1)} else {{table2-subset(table, select=list2)} } the select=list1 syntax does not work. What would be the correct way to do this? Many Thanks Jon -- View this message in context: http://r.789695.n4.nabble.com/subset-columns-from-list-with-variable-substitution-tp4631374.html Sent from the R help mailing list archive at Nabble.com. __ R-help@r-project.org 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] Multiple cbind according to filename
Hello, You can split the filenames vector according to a pattern, filenames - c(a1.csv, a2.csv, b1.csv, b2.csv, c1.csv, c2.csv) fnpattern - gsub([[:digit:]], , filenames) df.groups - split(filenames, fnpattern) and then use this list to process each of the groups of data.frames in 'alldata', possibly using lapply. Hpe this helps, Rui Barradas BustedAvi wrote Hi all, I'm just a beginner with R but I have not been able to search for any relevant answer to my problem. I apologize if it has in fact been asked before. Recently I've realized that I need to combine hundreds of pairs of data frames. The filenames of the frames I need to combine have unique strings. This is my best guess as to the approach to take: filenames-list.files() filenames [1] a1.csv a2.csv b1.csv b2.csv c1.csv c2.csv alldata-lapply(filenames, read.csv, header=TRUE) names(alldata)-filenames summary(alldata) Length Class Mode a1.csv 27 data.frame list a2.csv 27 data.frame list b1.csv 27 data.frame list b2.csv 27 data.frame list c1.csv 27 data.frame list c2.csv 27 data.frame list My next step would be to cbind files that share a common string at the beginning, such as: cbind(alldata[[1]],alldata[[2]]) cbind(alldata[[3]],alldata[[4]]) cbind(alldata[[5]],alldata[[6]]) ... but file list is hundreds of files long (but is sorted alphanumerically such as in this example - not sure if this is relevant). If I had to guess, I'd do something like this: which(names(alldata)==...), to identify which elements to combine based on unique filename OR x-seq(1,length(alldata), 2) y=x+1 z-cbind(x,y) z x y [1,] 1 2 [2,] 3 4 [3,] 5 6 to use the frame created in z to combine based on rows, then use a looped cbind function (or *apply function with nested cbind function?) using the previously returned indexes to create my new combined data frames, including a step to write the frames to a new unique filename (not sure how to do that step in this context). These last steps I've tried a lot of code but nothing worth mentioning as it has all failed miserably. I appreciate the help, M [[alternative HTML version deleted]] __ R-help@ 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. -- View this message in context: http://r.789695.n4.nabble.com/Multiple-cbind-according-to-filename-tp4631298p4631346.html Sent from the R help mailing list archive at Nabble.com. __ R-help@r-project.org 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] Problem sourcing file
Ah, my default font makes that distinction too subtle. Action item for me, then, to change fonts. --- Jeff NewmillerThe . . Go Live... DCN:jdnew...@dcn.davis.ca.usBasics: ##.#. ##.#. Live Go... Live: OO#.. Dead: OO#.. Playing Research Engineer (Solar/BatteriesO.O#. #.O#. with /Software/Embedded Controllers) .OO#. .OO#. rocks...1k --- Sent from my phone. Please excuse my brevity. Duncan Murdoch murdoch.dun...@gmail.com wrote: On 25/05/2012 2:17 PM, Jeff Newmiller wrote: What isn't proper about single quotes? They look like directional quotes to me. Might just be the mailer... Duncan Murdoch --- Jeff NewmillerThe . . Go Live... DCN:jdnew...@dcn.davis.ca.us Basics: ##.#. ##.#. Live Go... Live: OO#.. Dead: OO#.. Playing Research Engineer (Solar/BatteriesO.O#. #.O#. with /Software/Embedded Controllers) .OO#. .OO#. rocks...1k --- Sent from my phone. Please excuse my brevity. Duncan Murdochmurdoch.dun...@gmail.com wrote: On 25/05/2012 10:08 AM, Marta Tolós wrote: Hi all, I created a file to define some functions. When I try to source this file, sometimes it works but sometimes I get the following error: Source(‘File.R’) Those aren't proper quotes, and source() shouldn't be capitalized, and you didn't tell us what version of R you are using. Duncan Murdoch Error in srcfilecopy(filename, lines, file.info(filename)[1, mtime]) : unused argument(s) (file.info(filename)[1, mtime]) It works when I just started the R session, but after using some libraries when I do the source of the file again, I get this error. I can not really follow what steps aret he ones that bring me to the error, I only know that sometimes it appears. Does someone know the possible cause? Thanks! Marta [[alternative HTML version deleted]] __ R-help@r-project.org 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@r-project.org 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@r-project.org 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] applying cbind (or any function) across all components in a list
Hello, Let me give it a try. This last post made it clear, I hope. I have two interpretations of your problem. 1. 'l1' only has three columns, corresponding to clusters (genotypes) XX, XY and YY, and 'l2' has one less column, corresponding to the midpoints between their closest genotype cluster. 2. 'l1' can have any number of columns and 'l2' is the same as above, i.e., has one less column. In any case, the result is not the pairwise products of all possible combinations of columns of 'l1' and 'l2' matrices, but only those at a certain distance. In this case, fun2 below is more general. fun1 - function(x, y){ cbind((x[, 1] + y[, 1])/2, (x[, 2] + y[, 1])/2, (x[, 2] + y[, 2])/2, (x[, 3] + y[, 2])/2) } fun2 - function(x, y){ midpoint - function(i, j) (x[, i] + y[, j])/2 colx - ncol(x) res - matrix(nrow = nrow(x), ncol = 2*colx - 2) k - 1 res[, k] - midpoint(1, 1) for(cx in seq_len(colx)[-c(1, colx)]) for(dist in 1:0) res[, k - k + 1] - midpoint(cx, cx - dist) res[, k + 1] - midpoint(colx, colx - 1) res } lapply(seq_len(length(l1)), function(i) fun1(l1[[i]], l2[[i]])) lapply(seq_len(length(l1)), function(i) fun2(l1[[i]], l2[[i]])) If I'm wrong, sorry for the mess. Rui Barradas Em 25-05-2012 11:00, r-help-requ...@r-project.org escreveu: Date: Thu, 24 May 2012 15:37:51 -0700 (PDT) From: Hans Thompsonhans.thomps...@gmail.com To:r-help@r-project.org Subject: Re: [R] applying cbind (or any function) across all components in a list Message-ID:1337899071674-4631260.p...@n4.nabble.com Content-Type: text/plain; charset=us-ascii The function I am giving for context is cbind. Are you asking how I would like to apply the answer to my question? I am trying to take the results of a Fluidigm SNP microarray, organized by assay into a list (each component is the results of one assay), find coordinate midpoints ([1,] and [2,] of my XX, XY, and YY clusters (these are genotypes) and is represented by l1. l2 is the midpoint between XX/XY and XY/YY although I did not give this in my example for simplicity, and I am now trying to find the midpoint between these new midpoints and their closest genotype clusters. This is represented as cbind((l1[[1]][,1]+l2[[1]][,1])/2, (l1[[1]][,2]+l2[[1]][,1])/2, (l1[[1]][,2]+l2[[1]][,2])/2, (l1[[1]][,3]+l2[[1]][,2])/2) but only works for one assay in the list of 96. I want to apply this to the entire list. My entire code so far is: ## OPEN .CSV and ORGANIZE BY ASSAY file= { rawdata- read.csv(file, skip = 15) OrgAssay- split(rawdata, rawdata$Assay) ## RETURN MIDPOINTS FOR EACH CLUSTER WITHOUT NO CALLS #for loop ClustMidPts-list() for(locus in 1:length(names(OrgAssay))){ ClustMidPts[[locus]]-t(cbind(tapply(OrgAssay[[locus]][,Allele.X.1], OrgAssay[[locus]][,Final], mean,na.rm=T), tapply(OrgAssay[[locus]][,Allele.Y.1], OrgAssay[[locus]][,Final], mean,na.rm=T)))} names(ClustMidPts)=names(OrgAssay) ## CREATE CLUSTER-CLUSTER MIDPOINT #for loop ClustClustMidPts- list() for(locus in 1:length(names(ClustMidPts))){ ClustClustMidPts[[locus]]- cbind(XXYX=(ClustMidPts[[locus]][,XX]+ClustMidPts[[locus]][,YX])/2, YXYY=(ClustMidPts[[locus]][,YX]+ClustMidPts[[locus]][,YY])/2) } names(ClustClustMidPts)=names(ClustMidPts) Please also let me know how I messed up the formatting because it shows up fine in gmail even when I post on Nabble. How did I assume you were using Nabble? Is this topic included in the posting guide? -- View this message in context:http://r.789695.n4.nabble.com/applying-cbind-or-any-function-across-all-components-in-a-list-tp4631128p4631260.html Sent from the R help mailing list archive at Nabble.com. __ R-help@r-project.org 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] Java problem - XLConnect/xlsx package
Hi Rainer, Looking at your sessionInfo() it looks like you are using 32-bit R on 64-bit Windows 7. My guess is that the installed JVM is 64-bit. This leads to an architecture clash between R and Java. It is important to make sure that the architectures of R and the JVM match, i.e. either both are 32-bit or both are 64-bit. Can you verify if this is the case? Run java -version on the command line to see whether you are using a 32-bit or 64-bit JVM. Regards, Martin -- View this message in context: http://r.789695.n4.nabble.com/Java-problem-XLConnect-xlsx-package-tp4631304p4631365.html Sent from the R help mailing list archive at Nabble.com. __ R-help@r-project.org 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] Reading a bunch of csv files into R
Dear R users I am struggling from a data importing issue: I have some hundreds of csv files needed to be read into R for futher analysis. All those csv files are named in one of the three formats: (1) strings: e.g. London_Oxford street (2) Integer: e.g. 1234_5678 (3) combined: e.g. London_1234 I intend to use read.csv(_xxx.csv) but I only dealt with sigle documents before and if there are only no more than 20 files, I do not bother to search a more efficient way. Is there any claver way that I do not have to type in all these hundreds names by hand, maybe using a R package or write some code in some other languages if it is not too difficult to learn. Any thoughts/hints please?? Many thanks in advance! HJ [[alternative HTML version deleted]] __ R-help@r-project.org 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] Breaking up a vector
Thank you very much, I will be more careful in future. -- View this message in context: http://r.789695.n4.nabble.com/Breaking-up-a-vector-tp4631329p4631369.html Sent from the R help mailing list archive at Nabble.com. __ R-help@r-project.org 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] How to change width of bar when there are very few bars?
http://r.789695.n4.nabble.com/file/n4631371/Bar_Chart.png How to control width of bar chart when there are very few bars in plot? Regards -- View this message in context: http://r.789695.n4.nabble.com/How-to-change-width-of-bar-when-there-are-very-few-bars-tp4631371.html Sent from the R help mailing list archive at Nabble.com. __ R-help@r-project.org 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] Reading a bunch of csv files into R
See ?dir Assign the value to a vector and loop over the elements of the vector. Kevin On Fri, May 25, 2012 at 12:16 PM, HJ YAN yhj...@googlemail.com wrote: Dear R users I am struggling from a data importing issue: I have some hundreds of csv files needed to be read into R for futher analysis. All those csv files are named in one of the three formats: (1) strings: e.g. London_Oxford street (2) Integer: e.g. 1234_5678 (3) combined: e.g. London_1234 I intend to use read.csv(_xxx.csv) but I only dealt with sigle documents before and if there are only no more than 20 files, I do not bother to search a more efficient way. Is there any claver way that I do not have to type in all these hundreds names by hand, maybe using a R package or write some code in some other languages if it is not too difficult to learn. Any thoughts/hints please?? Many thanks in advance! HJ [[alternative HTML version deleted]] __ R-help@r-project.org 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. -- Kevin Wright __ R-help@r-project.org 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] Hash Table - Select and Change Data iniside Matrix
Hi Antony, Try this, da-read.table(text=NAME AGE PLACE ABC 20 INDIA XYZ 30 FRANCE PQR 40 USA MNO 30 KENYA DEF 25 AUSTRALIA, header=TRUE,stringsAsFactors=FALSE) da2-function(x){ if(x==30) TRUE else FALSE } da3-sapply(da$AGE,da2) TRUE_FALSE-da3 da1-data.frame(da,TRUE_FALSE) da1 NAME AGE PLACE TRUE_FALSE 1 ABC 20 INDIA FALSE 2 XYZ 30 FRANCE TRUE 3 PQR 40 USA FALSE 4 MNO 30 KENYA TRUE 5 DEF 25 AUSTRALIA FALSE A.K. - Original Message - From: Jeff Newmiller jdnew...@dcn.davis.ca.us To: Rantony antony.akk...@ge.com; r-help@r-project.org Cc: Sent: Friday, May 25, 2012 10:25 AM Subject: Re: [R] Hash Table - Select and Change Data iniside Matrix Read help for the ifelse function. Type ?ifelse at the command line. --- Jeff Newmiller The . . Go Live... DCN:jdnew...@dcn.davis.ca.us Basics: ##.#. ##.#. Live Go... Live: OO#.. Dead: OO#.. Playing Research Engineer (Solar/Batteries O.O#. #.O#. with /Software/Embedded Controllers) .OO#. .OO#. rocks...1k --- Sent from my phone. Please excuse my brevity. Rantony antony.akk...@ge.com wrote: Hi, Here i have been a matrix like this, *NAME AGE PALCE TRUE/FALSE* ABC 20 INDIA XYZ 30 FRANCE PQR 40 USA MNO 30 KENIYA DEF 25 AUSTRALIA Here,* TRUE/FALSE* Column containing empty values. So my requirement what is , need to change all the *TRUE/FALSE *column value into *TRUE* where *AGE = 30*. Note :- i *dont want* to use* any loop *and do. Main intension is avoid loop,bcz there is a bulk of data. Final Matrix should be like this *NAME AGE PALCE TRUE/FALSE* ABC 20 INDIA XYZ 30 FRANCE TRUE PQR 40 USA MNO 30 KENIYA TRUE DEF 25 AUSTRALIA Immediate Help Requied. Your, Antony. -- View this message in context: http://r.789695.n4.nabble.com/Hash-Table-Select-and-Change-Data-iniside-Matrix-tp4631312.html Sent from the R help mailing list archive at Nabble.com. __ R-help@r-project.org 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@r-project.org 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@r-project.org 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] difference between qnorm and qqnorm
On 25/05/2012 12:41 PM, QAMAR MUHAMMAD UZAIR wrote: dear all, it will just take you a minute to tell me the difference between qnorm and qqnorm. are they same or is there any difference between them?? They are very different, qqnorm draws a plot, qnorm does a calculation of some of the values you might use in that plot. See ?qnorm and ?qqnorm. Duncan Murdoch __ R-help@r-project.org 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] question about TryCatch and lapply
Folks: I've replaced an outer for-loop with lapply and it works great. But, I can't seem to do the following type of exception handling: tryCatch(dlmMLE(x)$value==Inf,error = function(e) NULL) which basically says if the likelihood is Inf, throw an error. But what I want it to do is just go to the next index in the list. When I was using a for-loop I used: if(tryCatch(dlmMLE(x)$value==Inf,error = function(e) 1)==1) {next} else which worked fine. Is there a way to do the same thing in lapply? Thanks for your time. (I've checked Gmane for this type of problem and I wasn't sure if this problem was answered or not...) John [[alternative HTML version deleted]] __ R-help@r-project.org 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] subset columns from list with variable substitution
Instead of subset(table, select=list1) try table[, list1] However, I suspect you have other problems. Particularly, i is not defined when you use i %in% namelist. You may have wanted i in namelist -Don -- Don MacQueen Lawrence Livermore National Laboratory 7000 East Ave., L-627 Livermore, CA 94550 925-423-1062 On 5/25/12 11:09 AM, jween jw...@rockwoodclinic.com wrote: Hi there, I would like to use a list variable to select columns in a subset from a parent table: I have a data frame table with column headers a,b,c,d,e,x,y,z and list variables list1=c(a,b,c,d) list2=c(a,b,x,y,z) namelist=c(peter,paul,mary,jane) group1=c(peter,paul) group2=c(mary,jane) I would like to subset table based on the list variable in a for loop: for (i %in% namelist){ if (i %in% group1){table2-subset(table, select=list1)} else {{table2-subset(table, select=list2)} } the select=list1 syntax does not work. What would be the correct way to do this? Many Thanks Jon -- View this message in context: http://r.789695.n4.nabble.com/subset-columns-from-list-with-variable-subst itution-tp4631374.html Sent from the R help mailing list archive at Nabble.com. __ R-help@r-project.org 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@r-project.org 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] Breaking up a vector
Just to throw out another approach to the underlying problem. Since the original vector length is an integer multiple of 7, taking the 'whole object' approach that is intrinsic to R, one can convert the vector to a 7 column matrix and then use apply() to run the entire process on each 7 element row in the matrix using the proverbial single line of R code. x - 1:2058 # or seq(2058) x.mat - matrix(x, ncol = 7, byrow = TRUE) str(x.mat) int [1:294, 1:7] 1 8 15 22 29 36 43 50 57 64 ... head(x.mat) [,1] [,2] [,3] [,4] [,5] [,6] [,7] [1,]1234567 [2,]89 10 11 12 13 14 [3,] 15 16 17 18 19 20 21 [4,] 22 23 24 25 26 27 28 [5,] 29 30 31 32 33 34 35 [6,] 36 37 38 39 40 41 42 Res - t(apply(x.mat, 1, function(x) {dz - diff(x); c(r = sum(dz), rv = sum(dz^2))})) str(Res) num [1:294, 1:2] 6 6 6 6 6 6 6 6 6 6 ... - attr(*, dimnames)=List of 2 ..$ : NULL ..$ : chr [1:2] r rv head(Res) r rv [1,] 6 6 [2,] 6 6 [3,] 6 6 [4,] 6 6 [5,] 6 6 [6,] 6 6 So you end up with a two column matrix containing the r and rv values in each row, for each 7 element segment of the original x. Regards, Marc Schwartz On May 25, 2012, at 10:56 AM, Rui Barradas wrote: Hello, Tip: see the difference between the following two. for(i in 1:7) cat(i, :, (i-1)*7:(i)*7, \n) for(i in 1:7) cat(i, :, ((i-1)*7):(i*7), \n) (operator ':' has high precedence...) Hope this helps, Rui Barradas AOLeary wrote Hi all, My problem is as follows: I want to run a loop which calculates two values and stores them in vectors r and rv, respectively. They're calculated from some vector x with length a multiple of 7. x - c(1:2058) I need to difference the values but it would be incorrect to difference it all in x, it has to be broken up first. I've tried the following: r - c(1:294)*0 rv - c(1:294)*0 #RUN A LOOP WHERE YOU INPUT THE lx[(i-1)*7:i*7] INTO Z for (i in 1:294){ #CREATE A NEW VECTOR OF LENGTH 7 z - NULL length(z)=7 dz - NULL dz2 - NULL #STORE THE VALUES IN z z - lx[1+(i-1)*7:(i)*7] #THEN DIFFERENCE THOSE #THIS IS r_t,i,m dz=diff(z) #SUM THIS UP AND STORE IT IN r, THIS IS r_t r[i] - sum(dz) #SUM UP THE SQUARES AND STORE IT IN rv, THIS IS RV_t dz2 - dz^2 rv[i] - sum(dz2) #END THE LOOP } However, the window seems to expand for some reason, so z ends up being a much longer vector than it should be and full of NAs. Any help or advice is much appreciated. Aodhán __ R-help@r-project.org 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] Reading a bunch of csv files into R
HJ, try something like this: files - list.files(pattern = \\.(csv|CSV)$) for (i in 1:length(files)) { temp - read.csv(files[i], header = FALSE) ... do whatever you want with the contents of temp... } Bryan *** Bryan Hanson Professor of Chemistry Biochemistry DePauw University On May 25, 2012, at 1:16 PM, HJ YAN wrote: Dear R users I am struggling from a data importing issue: I have some hundreds of csv files needed to be read into R for futher analysis. All those csv files are named in one of the three formats: (1) strings: e.g. London_Oxford street (2) Integer: e.g. 1234_5678 (3) combined: e.g. London_1234 I intend to use read.csv(_xxx.csv) but I only dealt with sigle documents before and if there are only no more than 20 files, I do not bother to search a more efficient way. Is there any claver way that I do not have to type in all these hundreds names by hand, maybe using a R package or write some code in some other languages if it is not too difficult to learn. Any thoughts/hints please?? Many thanks in advance! HJ [[alternative HTML version deleted]] __ R-help@r-project.org 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@r-project.org 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] Reading a bunch of csv files into R
For example: myDir - some file path filenames - list.files(myDir) filenames - filenames[grep([.]csv, filenames)] data_names - gsub([.]csv, , filenames) for(i in 1:length(filenames)) assign(data_names[i], read.csv(file.path(myDir, filenames[i]))) Benjamin Nutter | Biostatistician | Quantitative Health Sciences Cleveland Clinic | 9500 Euclid Ave. | Cleveland, OH 44195 | (216) 445-1365 -Original Message- From: r-help-boun...@r-project.org [mailto:r-help-boun...@r-project.org] On Behalf Of Kevin Wright Sent: Friday, May 25, 2012 2:55 PM To: HJ YAN Cc: r-help@r-project.org Subject: Re: [R] Reading a bunch of csv files into R See ?dir Assign the value to a vector and loop over the elements of the vector. Kevin On Fri, May 25, 2012 at 12:16 PM, HJ YAN yhj...@googlemail.com wrote: Dear R users I am struggling from a data importing issue: I have some hundreds of csv files needed to be read into R for futher analysis. All those csv files are named in one of the three formats: (1) strings: e.g. London_Oxford street (2) Integer: e.g. 1234_5678 (3) combined: e.g. London_1234 I intend to use read.csv(_xxx.csv) but I only dealt with sigle documents before and if there are only no more than 20 files, I do not bother to search a more efficient way. Is there any claver way that I do not have to type in all these hundreds names by hand, maybe using a R package or write some code in some other languages if it is not too difficult to learn. Any thoughts/hints please?? Many thanks in advance! HJ [[alternative HTML version deleted]] __ R-help@r-project.org 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. -- Kevin Wright __ R-help@r-project.org 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. === Please consider the environment before printing this e-mail Cleveland Clinic is ranked one of the top hospitals in America by U.S.News World Report (2010). Visit us online at http://www.clevelandclinic.org for a complete listing of our services, staff and locations. Confidentiality Note: This message is intended for use\...{{dropped:13}} __ R-help@r-project.org 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] question about TryCatch and lapply
Please show us the 'lapply' statement you are using. Here is a simple case of catching an error in an lapply and continuing: lapply(c(1,2,-3, 4), function(x){ + a - try(stopifnot(x 0)) # force an error + if (inherits(a, 'try-error')) return(NULL) + x + }) Error : x 0 is not TRUE [[1]] [1] 1 [[2]] [1] 2 [[3]] NULL [[4]] [1] 4 On Fri, May 25, 2012 at 2:51 PM, John Kerpel john.ker...@gmail.com wrote: Folks: I've replaced an outer for-loop with lapply and it works great. But, I can't seem to do the following type of exception handling: tryCatch(dlmMLE(x)$value==Inf,error = function(e) NULL) which basically says if the likelihood is Inf, throw an error. But what I want it to do is just go to the next index in the list. When I was using a for-loop I used: if(tryCatch(dlmMLE(x)$value==Inf,error = function(e) 1)==1) {next} else which worked fine. Is there a way to do the same thing in lapply? Thanks for your time. (I've checked Gmane for this type of problem and I wasn't sure if this problem was answered or not...) John [[alternative HTML version deleted]] __ R-help@r-project.org 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. -- Jim Holtman Data Munger Guru What is the problem that you are trying to solve? Tell me what you want to do, not how you want to do it. __ R-help@r-project.org 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] knitr customization
I am trying to transition from Sweave to knitr, but there are a few things about customization of the appearence of R input and output that I did not get yet. Maybe somebody on the list can help me. In my Sweave presentations I used a slanted font for the R input and a normal font for the output, both in a small font. I also indented everything by an extra 2em. All this was achieved by the following instructions in the .Rnw file: \DefineVerbatimEnvironment{Sinput}{Verbatim}{xleftmargin=2em, fontsize=\footnotesize, fontshape=sl} \DefineVerbatimEnvironment{Soutput}{Verbatim}{xleftmargin=2em, fontsize=\footnotesize} In order to get a similar result (with a tiny size instead of a footnote size, but that is not the point) with knitr I included in the .Rnw file the lines \ifdefined\knitrout \renewenvironment{knitrout}{\begin{tiny}\slshape}{\end{tiny}} \else \fi What I get is something like this: http://definetti.uark.edu/~gpetris/knitr-output.pdf The problem is that the prompt sign '' did not change either size or shape. So I am probably not using the correct approach. How should I be doing? Also, what do I have customize, and how, in order to get the extra left margin? Final question: how can I get the continuation sign '+'? (This is for an introductory presentation in which I want to show people exactly what they are going to see on their screen.) Oops, one more... How can I change the spacing between regular text and R code (input/output)? With Sweave I would do \fvset{listparameters={\setlength{\topsep}{0pt}}} \renewenvironment{Schunk}{\vspace{\topsep}}{\vspace{\topsep}} Sorry for the many questions and thank you in advance for any help and insight you can give me. Best, Giovanni -- Giovanni Petris gpet...@uark.edu Associate Professor Department of Mathematical Sciences University of Arkansas - Fayetteville, AR 72701 Ph: (479) 575-6324, 575-8630 (fax) http://definetti.uark.edu/~gpetris/ __ R-help@r-project.org 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] Reading a bunch of csv files into R
Hello, Or maybe put the data frames in a list df.list - lapply(seq_len(filenames), read.csv, ...) # '...other...' are options you might want to pass, (like headers=TRUE) names(df.list) - data_names Now access the data frames by number in the list or by name in data_names. Hope this helps, Rui Barradas Em 25-05-2012 20:08, Nutter, Benjamin escreveu: For example: myDir- some file path filenames- list.files(myDir) filenames- filenames[grep([.]csv, filenames)] data_names- gsub([.]csv, , filenames) for(i in 1:length(filenames)) assign(data_names[i], read.csv(file.path(myDir, filenames[i]))) Benjamin Nutter | Biostatistician | Quantitative Health Sciences Cleveland Clinic| 9500 Euclid Ave. | Cleveland, OH 44195 | (216) 445-1365 -Original Message- From: r-help-boun...@r-project.org [mailto:r-help-boun...@r-project.org] On Behalf Of Kevin Wright Sent: Friday, May 25, 2012 2:55 PM To: HJ YAN Cc: r-help@r-project.org Subject: Re: [R] Reading a bunch of csv files into R See ?dir Assign the value to a vector and loop over the elements of the vector. Kevin On Fri, May 25, 2012 at 12:16 PM, HJ YANyhj...@googlemail.com wrote: Dear R users I am struggling from a data importing issue: I have some hundreds of csv files needed to be read into R for futher analysis. All those csv files are named in one of the three formats: (1) strings: e.g. London_Oxford street (2) Integer: e.g. 1234_5678 (3) combined: e.g. London_1234 I intend to use read.csv(_xxx.csv) but I only dealt with sigle documents before and if there are only no more than 20 files, I do not bother to search a more efficient way. Is there any claver way that I do not have to type in all these hundreds names by hand, maybe using a R package or write some code in some other languages if it is not too difficult to learn. Any thoughts/hints please?? Many thanks in advance! HJ [[alternative HTML version deleted]] __ R-help@r-project.org 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. -- Kevin Wright __ R-help@r-project.org 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. === Please consider the environment before printing this e-mail Cleveland Clinic is ranked one of the top hospitals in America by U.S.News World Report (2010). Visit us online at http://www.clevelandclinic.org for a complete listing of our services, staff and locations. Confidentiality Note: This message is intended for use\...{{dropped:13}} __ R-help@r-project.org 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@r-project.org 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] sweave tables as images?
grid.table() works well, but using it in sweave creates graphics with very wide margins. I'm sure this has something to do with grid, and not just grid.table. Any idea how I can clip the graphic to the edges of the table graphic? I've looked into viewports, etc, but I can't seem to find anything that will clip a graphic to its edges, perhaps with some defined margin. any help greatly appreciated! thanks, allie On 5/21/2012 3:33 PM, R. Michael Weylandt wrote: Take a look at addtable2plot in plotrix or grid.table / tableGrob in gridExtras. Michael On Mon, May 21, 2012 at 4:29 PM, Alexander Shenkin ashen...@ufl.edu wrote: Hello folks, I've been on a journey trying to figure out how to manage documents that are amenable to sharing and editing, but that contain dynamic content generated by R. I've come to the following solution: I use Sweave to generate labeled png pdf figures, and I Insert Link those figures as Pictures in a Word 2010 doc. Thus, when data or code changes, I regenerate the figures with Sweave, open the Word doc and hit F9, and all the figures are automatically updated. I can send the file around, folks can comment and edit, track changes, etc. Now, however, I'm trying to do the same for tables that I did for figures, and it seems a bit more difficult. I can spit out tex tables into separate files using the split=TRUE chunk option, and I can even make those tables into html with xtable(type=html). Word, however, doesn't have the Insert Link option for external text files (which makes it such that, if the external file isn't found, Word uses a copy stored in the doc). So, I think it will be better if I can somehow generate the tables as images. Is there any way to generate tables as images in separate files in Sweave? Or, is there another tree up which I should be barking? Thanks, Allie __ R-help@r-project.org 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@r-project.org 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] subset columns from list with variable substitution
Thanks Don but table[,list1] did not work either: Error in `[.data.frame`(table, , list1) : undefined columns selected. I'm guessing my list (list1) is not structured right? Displaying it has no commas, so the whole list may be taken as a single variable rather than a sequence of variables? I've tried various ways of reformatting (c(), as.list(), etc), but no go. also i in namelist does not work while i %in% namelist does. I don't really reference i in any function, only using it in the conditional. Any other suggestions? Thanks Jon -- View this message in context: http://r.789695.n4.nabble.com/subset-columns-from-list-with-variable-substitution-tp4631374p4631394.html Sent from the R help mailing list archive at Nabble.com. __ R-help@r-project.org 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.