Re: [R] Can strptime handle milliseconds or AM/PM?
Readers, Responding to an old post (http://tolstoy.newcastle.edu.au/R/e2/help/07/06/18850.html), and using the example in the manual: monthextract-strptime(20/2/06 11:16:16.683, %m) monthextract [1] NA Why is the result 'NA' and not '2'? -- r2151 __ 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] Can strptime handle milliseconds or AM/PM?
On 17/01/2013 07:59, e-letter wrote: Readers, Responding to an old post (http://tolstoy.newcastle.edu.au/R/e2/help/07/06/18850.html), and using the example in the manual: monthextract-strptime(20/2/06 11:16:16.683, %m) monthextract [1] NA Why is the result 'NA' and not '2'? Because you have not specified a complete date-time, only month = 20 (which is invalid). The help page actually has z - strptime(20/2/06 11:16:16.683, %d/%m/%y %H:%M:%OS) I guess you were looking for strftime(z, %m) which gives 02 on my system (it may be platform-specific) or z$mon + 1 -- r2151 __ 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. -- Brian D. Ripley, rip...@stats.ox.ac.uk Professor of Applied Statistics, http://www.stats.ox.ac.uk/~ripley/ University of Oxford, Tel: +44 1865 272861 (self) 1 South Parks Road, +44 1865 272866 (PA) Oxford OX1 3TG, UKFax: +44 1865 272595 __ 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] Aligning labels to bars in barplot
On 01/17/2013 04:51 AM, David Arnold wrote: Nice, worked very well. But because of the realignment, I now need to lower by xlab a bit. Any suggestions? Hi David, This should give you an idea of how to do it: par(mar=c(6,4,4,2)) plot(1:10,xlab=) mtext(Index,side=1,line=4) 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] path matrix
Hi everyone, I have got an adjacency matrix here which gives my graph in R. But is there any way to write Breadth First Search algorithm to obtain path matrix? I'm really new to R, can anybody please help? I know the idea but just don't know how to write it, basically I am trying to look at only upper triangle in the matrix, and I hope to be able to look at every entry and therefore obtain path matrix which gives me the path length for every vertex from all other vertices. Thanks a lot, please give me a hand. -- View this message in context: http://r.789695.n4.nabble.com/path-matrix-tp4655805.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] Mean calculation by two variables
HI, May be this helps: Example$Wi-unlist(aggregate(Weight~ID,data=Example,function(x) round(x/sum(x),2))[,2]) res-do.call(rbind,lapply(split(Example,Example$Specie),function(x) with(x, {aggregate(Wi,list(Food.item),function(y) sum(y)/length(unique(x[,1])))}))) names(res)-names(Solution)[2:3] res1-data.frame(Specie=gsub([.0-9],,row.names(res)),res) row.names(res1)-1:nrow(res1) res1 # Specie Food.item MWi #1 Acestrorhynchus lacustris Alga 0.0075000 #2 Acestrorhynchus lacustris Fish 0.500 #3 Acestrorhynchus lacustris MNI 0.235 #4 Acestrorhynchus lacustris Sediment 0.0075000 #5 Acestrorhynchus lacustris Vegetal 0.250 #6 Schizodon intermedius Alga 0.141 #7 Schizodon intermedius MNI 0.184 #8 Schizodon intermedius Sediment 0.141 #9 Schizodon intermedius Vegetal 0.532 Solution # Specie Food.item MWi #1 Acestrorhynchus lacustris Peixe 0.5 #2 Acestrorhynchus lacustris Vegetal 0.25 #3 Acestrorhynchus lacustris Alga 0.0075 # Acestrorhynchus lacustris MNI 0.235 #5 Acestrorhynchus lacustris Sedimento 0.0075 #6 Schizodon intermedius Alga 0.14111 #7 Schizodon intermedius MNI 0.18444 #8 Schizodon intermedius Vegetal 0.53222 #9 Schizodon intermedius Sedimento 0.14111 A.K. - Original Message - From: Raoni Rodrigues caciquesamu...@gmail.com To: Rui Barradas ruipbarra...@sapo.pt Cc: r-help@r-project.org Sent: Wednesday, January 16, 2013 11:23 PM Subject: Re: [R] Mean calculation by two variables Hello Rui! Thanks a lot for your help! Sorry for make mistake with the factor's name, was inattention during data preparation for the asking mail. Unfortunately, it not simple mean calculation, because same individual could have more than one row, if it eat more than a food item. In example data, Acestrorhynchus lacustris are represent by six rows and just four individuals (ID 1717 repeats three times). Because that I tried use lenght (unique(ID)). After calculate the proportion for each individual (step1), I have to sum same food item and divide by four for Acestrorhynchus and by nine for Schizodon (that have 14 row of data). Because that is not simply calculate the mean. Could you please give me some idea? I'm sending again exemple and solution data, now with correct factor's name. Thanks again for your attention and time, Raoni *Example:* structure(list(ID = c(779L, 782L, 1717L, 1717L, 1717L, 1803L, 2650L, 2650L, 2700L, 2700L, 3611L, 3613L, 3647L, 3654L, 3654L, 3683L, 3683L, 3683L, 3685L, 3997L), Site = c(Três Marias, Três Marias, Nova Ponte, Nova Ponte, Nova Ponte, Três Marias, São Simão, São Simão, São Simão, São Simão, São Simão, São Simão, São Simão, São Simão, São Simão, São Simão, São Simão, São Simão, São Simão, São Simão), Specie = c(Acestrorhynchus lacustris, Acestrorhynchus lacustris, Acestrorhynchus lacustris, Acestrorhynchus lacustris, Acestrorhynchus lacustris, Acestrorhynchus lacustris, Schizodon intermedius, Schizodon intermedius, Schizodon intermedius, Schizodon intermedius, Schizodon intermedius, Schizodon intermedius, Schizodon intermedius, Schizodon intermedius, Schizodon intermedius, Schizodon intermedius, Schizodon intermedius, Schizodon intermedius, Schizodon intermedius, Schizodon intermedius), Weight = c(0.06, 0.01, 0.01, 0.33, 0.01, 3.5, 0.01, 0.04, 0.01, 0.01, 0.38, 0.29, 0.04, 0.03, 0.11, 0.04, 0.04, 0.03, 0.01, 0.01), Food.item = c(Fish, Vegetal, Alga, MNI, Sediment, Fish, Alga, MNI, Alga, MNI, Vegetal, Vegetal, Vegetal, Alga, Vegetal, Alga, MNI, Sediment, Sediment, Vegetal)), .Names = c(ID, Site, Specie, Weight, Food.item), row.names = c(1869113L, 2290407L, 56668L, 1485394L, 2126489L, 368143L, 57601L, 1486327L, 57651L, 1486377L, 2348187L, 2348189L, 2293272L, 58605L, 2293279L, 40317L, 1487360L, 2128455L, 2128457L, 2293622L), class = data.frame) *Solution:* structure(list(Specie = c(Acestrorhynchus lacustris, Acestrorhynchus lacustris, Acestrorhynchus lacustris, Acestrorhynchus lacustris, Acestrorhynchus lacustris, Schizodon intermedius, Schizodon intermedius, Schizodon intermedius, Schizodon intermedius), Food.item = c(Peixe, Vegetal, Alga, MNI, Sedimento, Alga, MNI, Vegetal, Sedimento), MWi = c(0.5, 0.25, 0.0075, 0.235, 0.0075, 0.14111, 0.18444, 0.53222, 0.14111)), .Names = c(Specie, Food.item, MWi), row.names = c(NA, -9L), class = data.frame) 2013/1/16 Rui Barradas ruipbarra...@sapo.pt Hello, If you want to calculate the mean weight by Specie and Food.item, you can use ?aggregate. In what follows, I've named your EXAMPLE ex and your SOLUTION sol. Note that the result is different from sol. (No exemplo não há Peixe, é Fish, e os números são outros.) aggregate(Weight ~ Specie + Food.item, data = ex, FUN = mean) Hope this helps, Rui Barradas Em 16-01-2013 15:41, Raoni Rodrigues escreveu: Hello All, I have a data
Re: [R] How to plot this simple step function?
Thank you for your reply! When I copy and paste the code into the Console, I receive several errors! 1) Error in plot(x, y, type = n) : object 'x' not found segments(x[-length(x)],y[-length(x)],x[-1],y[-length(x)]) Error in segments(x[-length(x)], y[-length(x)], x[-1], y[-length(x)]) : object 'x' not found 2)Error in points(x[-length(x)], y[-length(x)], pch = 16) : object 'x' not found points(x[-1],y[-length(x)],pch=1) 3) Error in points(x[-1], y[-length(x)], pch = 1) : object 'x' not found. What am I doing wrong? :'( -- View this message in context: http://r.789695.n4.nabble.com/How-to-plot-this-simple-step-function-tp4655792p4655813.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] Issue while installing Hmisc package
Hi, Please find the snap shot attached for the error reported wile installing Hmisc Package. Is there any thing you can help me with. Currently using R i386 2.15.2 Version of R on windows 7 platform. Ragards Vaseem Shaikh attachment: Instalation_Issue_HMISC.png__ 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] How to plot this simple step function?
you forgot to define the x and y variables that you provided as examples. --- 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. Bornin1992 i...@mcparland.ca wrote: Thank you for your reply! When I copy and paste the code into the Console, I receive several errors! 1) Error in plot(x, y, type = n) : object 'x' not found segments(x[-length(x)],y[-length(x)],x[-1],y[-length(x)]) Error in segments(x[-length(x)], y[-length(x)], x[-1], y[-length(x)]) : object 'x' not found 2)Error in points(x[-length(x)], y[-length(x)], pch = 16) : object 'x' not found points(x[-1],y[-length(x)],pch=1) 3) Error in points(x[-1], y[-length(x)], pch = 1) : object 'x' not found. What am I doing wrong? :'( -- View this message in context: http://r.789695.n4.nabble.com/How-to-plot-this-simple-step-function-tp4655792p4655813.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] Issue while installing Hmisc package
Try a different CRAN mirror. MW On Jan 17, 2013, at 7:42 AM, vaseem shaikh vsma...@gmail.com wrote: Hi, Please find the snap shot attached for the error reported wile installing Hmisc Package. Is there any thing you can help me with. Currently using R i386 2.15.2 Version of R on windows 7 platform. Ragards Vaseem Shaikh Instalation_Issue_HMISC.png __ 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] read tab delimited file from a certain line
Hello thank you for the fast and helpful answer! Now the following works fine for me x - readLines(filename) i - grep(^year, x) dlf - read.table(textConnection(x[i:length(x)]), header = T, stringsAsFactors=F,sep=\t) Greetings Christof Am 16-01-2013 16:55, schrieb Rui Barradas: Hello, Read the file using readLines, then grep ^year. You can then use a textConnection to read.table: x - readLines(con = textConnection( informations (unknown count of lines) ... and at some point the table -- year month mday value 2013 1 16 0 )) # This is it i - grep(^year, x) read.table(textConnection(x[i:length(x)]), header = TRUE) Hope this helps, Rui Barradas Em 16-01-2013 14:17, Christof Kluß escreveu: Hi I would like to read table data from a text-files with extra informations in the header (of unknown line count). Example: informations (unknown count of lines) ... and at some point the table -- year month mday value 2013 1 16 0 ... If it was an excel file I could use something like read.xls(..., pattern=year) But it is a simple tab seperated text-file. Is there an easy way to read only the table? (Without dirty things ;)) Thx Christof __ 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] Log scale on y axis of parallel coordinate plot (lattice)
Hello all, Thanks a lot for you help! Just in case someone else will have that same problem in the future: Meanwhile I also found out that ggplot2 gives you the option to freely swap x- and y-axes and apply a log-scale to whichever one you need: library(ggplot2) library(reshape2) molten - melt(df_n, id = .row) p - ggplot(molten, aes(variable, value, group = .row)) p - p + geom_line() + scale_y_log10() p Cheers, Roland On 17/01/13 06:53, ilai wrote: On Wed, Jan 16, 2013 at 12:46 PM, ilai ke...@math.montana.edu mailto:ke...@math.montana.edu wrote: Oops... That's require(latticeExtra) c(parallelplot(~ df_n, horizontal.axis = FALSE, scales=list(x = list(log = TRUE))) , parallelplot(~ df_n, horizontal.axis = FALSE)) or you'll get the full printout of the two objects. Sorry HTH -- ~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~. ___Patrick Connolly {~._.~} Great minds discuss ideas _( Y )_ Average minds discuss events (:_~*~_:) Small minds discuss people (_)-(_) . Eleanor Roosevelt ~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~. __ R-help@r-project.org mailto: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] exporting simulated data
Rather unspecific. Basically you'd need a loop to create the sets, and a way to write them into a file. You did not specify the format of your data. You might be able to use write, write.table or write.csv and the like. You could also have a look at ?save which allows you to save any R object. You also did not specify how important that filename format is. For example: for(i in 1:5){ #create data someData - i #create filename filename-paste(data,i,.dat,sep=) #save data write(someData,filename) } This would make unique filenames but not quite what you wanted. greetings, Jessi On 17.01.2013, at 04:31, Ray Cheung wrote: Dear All, I wrote a function datagen to simulate a dataset. I would like to generate 1000 datasets and export them with file names from data0001.dat to data1000.dat. Would anybody please provide some useful codes on this? Thank you very much. Best Regards, Ray [[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] exporting simulated data
Hello, Em 17-01-2013 11:56, Jessica Streicher escreveu: Rather unspecific. Basically you'd need a loop to create the sets, and a way to write them into a file. You did not specify the format of your data. You might be able to use write, write.table or write.csv and the like. You could also have a look at ?save which allows you to save any R object. You also did not specify how important that filename format is. For example: for(i in 1:5){ #create data someData - i #create filename filename-paste(data,i,.dat,sep=) #save data write(someData,filename) } This would make unique filenames but not quite what you wanted. For this maybe filename - sprintf(data%04d.dat, i) Hope this helps, Rui Barradas greetings, Jessi On 17.01.2013, at 04:31, Ray Cheung wrote: Dear All, I wrote a function datagen to simulate a dataset. I would like to generate 1000 datasets and export them with file names from data0001.dat to data1000.dat. Would anybody please provide some useful codes on this? Thank you very much. Best Regards, Ray [[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] Colors in interaction plots
Hi, I am trying to plot an interaction.plot with different color for each level of a factor. It has an erratic behavior. For example, it works for the first interaction.plot below, with the example from the ALDA book, but not with the other plots, from the NPK dataset: # from http://www.ats.ucla.edu/stat/r/examples/alda/ch2.htm tolerance - read.csv(http://www.ats.ucla.edu/stat/r/examples/alda/data/tolerance1.txt;) tolerance.pp - read.csv(http://www.ats.ucla.edu/stat/r/examples/alda/data/tolerance1_pp.txt;) attach(tolerance.pp) # fitting the linear model by id fit - by(tolerance.pp, id, function(bydata) fitted.values(lm(tolerance ~ time, data=bydata))) fit - unlist(fit) # plotting the linear fit by id interaction.plot(age, id, fit, xlab=age, ylab=tolerance) # plots red for female and green for male interaction.plot(age, id, fit, xlab=age, ylab=tolerance, col=male+2) print(tolerance.pp[id==978|id==514|id==9|id==1105|id==1653,c(id,male)]) data(npk, package=MASS) fit - by(npk, npk$block, function(bydata) fitted.values(lm(yield ~ N, data=bydata))) fit - unlist(fit) interaction.plot(npk$N, npk$block, fit, xlab=N, ylab=yield) # fake factor, numeric fac - c(rep(1,12),rep(2,12)) # plots everything in black interaction.plot(npk$N, npk$block, fit, xlab=N, ylab=yield,col=fac) cbind(npk$block,fac) # plots everything transparent fac - as.factor(fac) interaction.plot(npk$N, npk$block, fit, xlab=N, ylab=yield,col=as.numeric(npk$fac)) __ 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] Colors in interaction plots
I was unable to run your code; 'fac' is missing and npk$fac in teh interaction.plot returns NA. data(npk, package=MASS) fit - by(npk, npk$block, function(bydata) fitted.values(lm(yield ~ N, data=bydata))) fit - unlist(fit) interaction.plot(npk$N, npk$block, fit, xlab=N, ylab=yield) # fake factor, numeric fac - c(rep(1,12),rep(2,12)) # plots everything in black interaction.plot(npk$N, npk$block, fit, xlab=N, ylab=yield,col=fac) cbind(npk$block,fac) # plots everything transparent fac - as.factor(fac) interaction.plot(npk$N, npk$block, fit, xlab=N, ylab=yield,col=as.numeric(npk$fac)) *** This email and any attachments are confidential. Any use...{{dropped:8}} __ 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] Making an aggregated factor variable from an existing one
Hi, This is quite simple data manipulation task and I need help for it. I want to make new factor variable that is an aggregation of an existing factor. This works as I intended: X[Y == original label] - new label How to make following work then (to make coding more convenient): original.labels - c(ol.1,ol.2,ol.3) X[Y == original.labels] - new label Cheers, Antti __ 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] Making an aggregated factor variable from an existing one
Hi, Antti, you should look at ?levels (and particular its Examples section) to find out how to use levels( X) - c( new1, ..., newk) to achieve what you want. Regards -- Gerrit On Thu, 17 Jan 2013, Antti Simola wrote: Hi, This is quite simple data manipulation task and I need help for it. I want to make new factor variable that is an aggregation of an existing factor. This works as I intended: X[Y == original label] - new label How to make following work then (to make coding more convenient): original.labels - c(ol.1,ol.2,ol.3) X[Y == original.labels] - new label Cheers, Antti __ 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] How to change R file in stats?
-Original Message- I have changed some code in R file inside the stats package (dendrogram.R). That was brave. Others have already commented on its wisdom... Now I wan to test and run the stats package with the new updated code, what should I do in detail? 1. Read and follow the instructions in 'Writing R extensions' to build an installable .tar.gz or (for windows) .zip binary of the stats package. 2. Back up your copy of R. 3. Install the newly built stats package in the normal way. 4. Test. 5. Revert to the backup. Safer still to create a different installation of R locally and apply the new package install to that. S *** This email and any attachments are confidential. Any use...{{dropped:8}} __ 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] How to change R file in stats?
On 13-01-17 8:31 AM, S Ellison wrote: -Original Message- I have changed some code in R file inside the stats package (dendrogram.R). That was brave. Others have already commented on its wisdom... Now I wan to test and run the stats package with the new updated code, what should I do in detail? 1. Read and follow the instructions in 'Writing R extensions' to build an installable .tar.gz or (for windows) .zip binary of the stats package. 2. Back up your copy of R. 3. Install the newly built stats package in the normal way. Stats is a base package, so that won't work. Base packages are built and installed differently from other packages. He could modify the sources and build a custom copy of R for himself, but that seems kind of extreme. A better way would be to copy the source for the function into his own package. If he intends to release it, he must retain copyright notices on it and release his own package with a GPL-compatible license. Duncan Murdoch 4. Test. 5. Revert to the backup. Safer still to create a different installation of R locally and apply the new package install to that. S *** This email and any attachments are confidential. Any use...{{dropped:8}} __ 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] How to change R file in stats?
Stats is a base package, so that won't work. Base packages are built and installed differently from other packages. Dang! Of course it is. Scratch previous response. The irony is that my first thought was indeed Read 'R Installation and configuration' with special attention to 'Building from source'. As you say, rather extreme ... and having recently done that myself I recalled the 'finish PhD thesis' bit of those instructions.) Agree entirely, though, that modifying base package source is not at all a good way for an ordinary user to get a bettter dendrogram. Really something one would only consider if intending to suggest a patch to R-core. S *** This email and any attachments are confidential. Any use...{{dropped:8}} __ 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] Issue while installing Hmisc package
On Thu, Jan 17, 2013 at 12:57 PM, vaseem shaikh vsma...@gmail.com wrote: Hello Michael, I have tried with different CRAN but still i am getting the same error. Most likely you've got something blocking your network. Can you download the source / binary from the CRAN pages (using your web-browser) and then install from the command line? Hmisc doesn't require any special tools to build so that shouldn't be too hard. But still, i am also trying to install the package by locally giving absolute path with repos= Null and type = Source, will CRAN have any role to play here??? You can't escape CRAN entirely in this case (unless you know where the source is, which I don't) -- it's the distribution network. MW BR- Vaseem Shaikh On Thu, Jan 17, 2013 at 3:03 PM, Michael Weylandt michael.weyla...@gmail.com wrote: Try a different CRAN mirror. MW On Jan 17, 2013, at 7:42 AM, vaseem shaikh vsma...@gmail.com wrote: Hi, Please find the snap shot attached for the error reported wile installing Hmisc Package. Is there any thing you can help me with. Currently using R i386 2.15.2 Version of R on windows 7 platform. Ragards Vaseem Shaikh Instalation_Issue_HMISC.png __ 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] how to use ...
Dear users, I'm trying to learn how to use the I have written a function (simplified here) that uses doBy::summaryBy(): # 'dat' is a data.frame from which the aggregation is computed # 'vec_cat' is a integer vector defining which columns of the data.frame should be use on the right side of the formula # 'stat_fun' is the function that will be run to aggregate stat.group - function(dat, vec_cat, stat_fun){ require(doBy) df - summaryBy(as.formula(paste0(.~,paste0(names(dat)[vec_cat],collapse=+))), data=dat, FUN=stat_fun) return(df) } Example, works fine: my_data - structure(list(cat = structure(c(1L, 1L, 1L, 1L, 1L, 2L, 2L, 2L, 2L, 2L), .Label = c(A, B), class = factor), varnum = c(-0.754816565434373, -1.94101630973709, -0.102461836059522, -0.519952759645808, -1.73772800855664, -1.13939178585609, 0.522356715260142, -0.701428514907824, 1.45197576541159, 0.0844567413828095)), .Names = c(cat, varnum), row.names = c(NA, -10L), class = data.frame) stat.group(dat=my_data, vec_cat=1, stat_fun=mean) Now summaryBy() has an ... argument and I would like to use it. For example, I would like to be able to add the trim argument to my call like this: stat.group(dat=my_data, vec_cat=1, stat_fun=mean, trim=0.2) I know I can do it using this ... but I have no idea how to do it. I've tried to search for it, but a search with ... doesn't yield interesting results! Thank you in advance for your help! Ivan -- Ivan CALANDRA Université de Bourgogne UMR CNRS/uB 6282 Biogéosciences 6 Boulevard Gabriel 21000 Dijon, FRANCE +33(0)3.80.39.63.06 ivan.calan...@u-bourgogne.fr http://biogeosciences.u-bourgogne.fr/calandra __ 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] coxph with smooth survival
Hello users, I would like to obtain a survival curve from a Cox model that is smooth and does not have zero differences due to no events for those particular days. I have: sum((diff(surv))==0) [1] 18 So you can see 18 days where the survival curve did not drop due to no events. Is there a way to ask survfit to fit a nice spline for the survival?? Note: I tried survreg and it did not work, but maybe I did not do it properly?? Thank you very much. Stephen B __ 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] how to use ...
On Thu, Jan 17, 2013 at 2:36 PM, Ivan Calandra ivan.calan...@u-bourgogne.fr wrote: Dear users, I'm trying to learn how to use the I have written a function (simplified here) that uses doBy::summaryBy(): # 'dat' is a data.frame from which the aggregation is computed # 'vec_cat' is a integer vector defining which columns of the data.frame should be use on the right side of the formula # 'stat_fun' is the function that will be run to aggregate stat.group - function(dat, vec_cat, stat_fun){ require(doBy) df - summaryBy(as.formula(paste0(.~,paste0(names(dat)[vec_cat],collapse=+))), data=dat, FUN=stat_fun) return(df) } [SNIP EXAMPLE -- THANK YOU FOR IT] Now summaryBy() has an ... argument and I would like to use it. For example, I would like to be able to add the trim argument to my call like this: stat.group(dat=my_data, vec_cat=1, stat_fun=mean, trim=0.2) Thanks for the great working examples! It's actually not too hard here -- just pass ... down as if it were an argument and let summaryBy() do the hard work of actually handling the dots: stat.group - function(dat, vec_cat, stat_fun, ...){ require(doBy) df - summaryBy(as.formula(paste0(.~,paste0(names(dat)[vec_cat],collapse=+))), data=dat, FUN=stat_fun, ...) return(df) } Also, note that as a matter of style, you can actually clean this up a little bit: R follows the trend of many functional languages in automatically returning the value of the last expression evaluated: stat.group - function(dat, vec_cat, stat_fun, ...){ require(doBy) summaryBy(as.formula(paste0(.~,paste0(names(dat)[vec_cat],collapse=+))), data=dat, FUN=stat_fun, ...) } Cheers, Michael __ 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] how to use ...
On 17-01-2013, at 15:36, Ivan Calandra ivan.calan...@u-bourgogne.fr wrote: Dear users, I'm trying to learn how to use the I have written a function (simplified here) that uses doBy::summaryBy(): # 'dat' is a data.frame from which the aggregation is computed # 'vec_cat' is a integer vector defining which columns of the data.frame should be use on the right side of the formula # 'stat_fun' is the function that will be run to aggregate stat.group - function(dat, vec_cat, stat_fun){ require(doBy) df - summaryBy(as.formula(paste0(.~,paste0(names(dat)[vec_cat],collapse=+))), data=dat, FUN=stat_fun) return(df) } Example, works fine: my_data - structure(list(cat = structure(c(1L, 1L, 1L, 1L, 1L, 2L, 2L, 2L, 2L, 2L), .Label = c(A, B), class = factor), varnum = c(-0.754816565434373, -1.94101630973709, -0.102461836059522, -0.519952759645808, -1.73772800855664, -1.13939178585609, 0.522356715260142, -0.701428514907824, 1.45197576541159, 0.0844567413828095)), .Names = c(cat, varnum), row.names = c(NA, -10L), class = data.frame) stat.group(dat=my_data, vec_cat=1, stat_fun=mean) Now summaryBy() has an ... argument and I would like to use it. For example, I would like to be able to add the trim argument to my call like this: stat.group(dat=my_data, vec_cat=1, stat_fun=mean, trim=0.2) I know I can do it using this ... but I have no idea how to do it. I've tried to search for it, but a search with ... doesn't yield interesting results! This seems to work: stat.group - function(dat, vec_cat, stat_fun,...){ require(doBy) df - summaryBy(as.formula(paste0(.~,paste0(names(dat)[vec_cat],collapse=+))), data=dat, FUN=stat_fun,...) return(df) } and stat.group(dat=my_data, vec_cat=1, stat_fun=mean, trim=0.2) as the example for sumfun in the help for summaryBy shows. Berend __ 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 and Windows 8
On Wed, Jan 16, 2013 at 12:39 PM, Gabor Grothendieck ggrothendi...@gmail.com wrote: On Wed, Jan 16, 2013 at 11:06 AM, Claire Oswald claire.j.osw...@gmail.com wrote: Hello: I'd like to know if R will run under Windows 8? I am running R on Windows 8 with no apparent problems. Actually I found one tiny problem. If you ask which Windows version you are using when running under Windows 8 it tells you that you are using Windows 7 : R.version.string [1] R version 2.15.2 Patched (2013-01-13 r61650) win.version() ## Should be Windows 8 [1] Windows 7 x64 (build 9200) -- 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.
Re: [R] coxph with smooth survival
I also tried fitting a spline to the resulting survival curve and the result was horrible. maybe spline won't work or knots need special handling. overall, I must have the final point of the smooth survival to be same as the final point of the raw Cox survival and no flat days, the drops should be spread around. Thanks again everybody. Stephen __ 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] equivalent code that doesn't return same results?
William Dunlap wrote eval(parse(text=paste(dataset,IVcat[k],sep=$)))-relevel(eval(parse(text=paste(dataset,IVcat[k],sep=$))),ref=online) This code returns the following error: Error in eval(parse(text = paste(dataset, IVcat[k], sep = $))) - relevel(eval(parse(text = paste(dataset, : target of assignment expands to non-language object Replace eval(parse(text=paste(dataset, IVcat[k], sep=$))) with dataset[[ IVcat[k] ]] everywhere. Thanks so much for the response, Bill - this was very helpful. I feel silly for not thinking of this myself - I had originally started with this approach, but abandoned it because for some inexplicable reason it seemed to call the wrong dataset column (which it did again when I substituted your code for mine). However, I figured out a modification that did work: apparently I needed to convert the output of IVcat[k] to a string, like this, and then the code ran fine: dataset[[ toString(IVcat[k]) ]] Thanks again! -- View this message in context: http://r.789695.n4.nabble.com/equivalent-code-that-doesn-t-return-same-results-tp4655788p4655852.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] importing a SAS syntax-files (value labels)
Hello everybody, I imported an SAS data-file into R. open.sas7bdat() did not work, so I had to convert it to csv first. Now I would like to recode the value values into factors. Unfortunately I only have a SAS syntax file, having this form: proc format; value $resstatus 'B'= 'Jahresaufenthalter' 'C' = 'Niedergelassene' 'I' = 'Dipl./int. Funkt. und Angehörige' ; run; Does anyone know if there is a possibility to change the numeric value labels into factor levels acording to the SAS syntax-file? I cannot do this manually as there are several hundred labels... Thank you! [[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] how to use ...
Ok, it is that simple... Actually I had tried it but messed up so that it didn't work. Do you know where I can find some documentation about it? Regarding return(), I know that it's not necessary, but when the function gets more complicated, I like to have it because it becomes clearer to me. Thanks all! Ivan -- Ivan CALANDRA Université de Bourgogne UMR CNRS/uB 6282 Biogéosciences 6 Boulevard Gabriel 21000 Dijon, FRANCE +33(0)3.80.39.63.06 ivan.calan...@u-bourgogne.fr http://biogeosciences.u-bourgogne.fr/calandra Le 17/01/13 15:55, R. Michael Weylandt a écrit : On Thu, Jan 17, 2013 at 2:36 PM, Ivan Calandra ivan.calan...@u-bourgogne.fr wrote: Dear users, I'm trying to learn how to use the I have written a function (simplified here) that uses doBy::summaryBy(): # 'dat' is a data.frame from which the aggregation is computed # 'vec_cat' is a integer vector defining which columns of the data.frame should be use on the right side of the formula # 'stat_fun' is the function that will be run to aggregate stat.group - function(dat, vec_cat, stat_fun){ require(doBy) df - summaryBy(as.formula(paste0(.~,paste0(names(dat)[vec_cat],collapse=+))), data=dat, FUN=stat_fun) return(df) } [SNIP EXAMPLE -- THANK YOU FOR IT] Now summaryBy() has an ... argument and I would like to use it. For example, I would like to be able to add the trim argument to my call like this: stat.group(dat=my_data, vec_cat=1, stat_fun=mean, trim=0.2) Thanks for the great working examples! It's actually not too hard here -- just pass ... down as if it were an argument and let summaryBy() do the hard work of actually handling the dots: stat.group - function(dat, vec_cat, stat_fun, ...){ require(doBy) df - summaryBy(as.formula(paste0(.~,paste0(names(dat)[vec_cat],collapse=+))), data=dat, FUN=stat_fun, ...) return(df) } Also, note that as a matter of style, you can actually clean this up a little bit: R follows the trend of many functional languages in automatically returning the value of the last expression evaluated: stat.group - function(dat, vec_cat, stat_fun, ...){ require(doBy) summaryBy(as.formula(paste0(.~,paste0(names(dat)[vec_cat],collapse=+))), data=dat, FUN=stat_fun, ...) } Cheers, Michael __ 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 and Windows 8
On 17/01/2013 9:59 AM, Gabor Grothendieck wrote: On Wed, Jan 16, 2013 at 12:39 PM, Gabor Grothendieck ggrothendi...@gmail.com wrote: On Wed, Jan 16, 2013 at 11:06 AM, Claire Oswald claire.j.osw...@gmail.com wrote: Hello: I'd like to know if R will run under Windows 8? I am running R on Windows 8 with no apparent problems. Actually I found one tiny problem. If you ask which Windows version you are using when running under Windows 8 it tells you that you are using Windows 7 : R.version.string [1] R version 2.15.2 Patched (2013-01-13 r61650) win.version() ## Should be Windows 8 [1] Windows 7 x64 (build 9200) I'll fix this if someone else doesn't get there first. 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.
Re: [R] how to use ...
Well.. On Thu, Jan 17, 2013 at 7:42 AM, Ivan Calandra ivan.calan...@u-bourgogne.fr wrote: Ok, it is that simple... Actually I had tried it but messed up so that it didn't work. Do you know where I can find some documentation about it? The R language definition manual would be the logical place to look, no? And sure enough, it's there! The Introduction to R tutorial also contains info in the writing functions section. A very good, though now dated, exposition can be found in VR's S Programming book. Although a little care is needed due to age, it's still my favorite. -- Bert Regarding return(), I know that it's not necessary, but when the function gets more complicated, I like to have it because it becomes clearer to me. Thanks all! Ivan -- Ivan CALANDRA Université de Bourgogne UMR CNRS/uB 6282 Biogéosciences 6 Boulevard Gabriel 21000 Dijon, FRANCE +33(0)3.80.39.63.06 ivan.calan...@u-bourgogne.fr http://biogeosciences.u-bourgogne.fr/calandra Le 17/01/13 15:55, R. Michael Weylandt a écrit : On Thu, Jan 17, 2013 at 2:36 PM, Ivan Calandra ivan.calan...@u-bourgogne.fr wrote: Dear users, I'm trying to learn how to use the I have written a function (simplified here) that uses doBy::summaryBy(): # 'dat' is a data.frame from which the aggregation is computed # 'vec_cat' is a integer vector defining which columns of the data.frame should be use on the right side of the formula # 'stat_fun' is the function that will be run to aggregate stat.group - function(dat, vec_cat, stat_fun){ require(doBy) df - summaryBy(as.formula(paste0(.~,paste0(names(dat)[vec_cat],collapse=+))), data=dat, FUN=stat_fun) return(df) } [SNIP EXAMPLE -- THANK YOU FOR IT] Now summaryBy() has an ... argument and I would like to use it. For example, I would like to be able to add the trim argument to my call like this: stat.group(dat=my_data, vec_cat=1, stat_fun=mean, trim=0.2) Thanks for the great working examples! It's actually not too hard here -- just pass ... down as if it were an argument and let summaryBy() do the hard work of actually handling the dots: stat.group - function(dat, vec_cat, stat_fun, ...){ require(doBy) df - summaryBy(as.formula(paste0(.~,paste0(names(dat)[vec_cat],collapse=+))), data=dat, FUN=stat_fun, ...) return(df) } Also, note that as a matter of style, you can actually clean this up a little bit: R follows the trend of many functional languages in automatically returning the value of the last expression evaluated: stat.group - function(dat, vec_cat, stat_fun, ...){ require(doBy) summaryBy(as.formula(paste0(.~,paste0(names(dat)[vec_cat],collapse=+))), data=dat, FUN=stat_fun, ...) } Cheers, Michael __ 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.
[R] help with error: DV converted to a factor
I've spent several days compiling the following code (I apologize in advance - this code is very inelegant, and I'm sure could be written much more efficiently, but I've stuck with whatever method I could get to work - sometimes the more efficient code I just couldn't get to work without an error, because of my R inexperience). My main motivation for writing the code is that I'd like to be able to assess interaction effects, and so I want to be able to rotate through the reference values so that I can assess different interaction effects than simply the default ones reported by the single set of reference values given in a single analysis. The code below generates a lot more than that, but since I am such an R newbie (and therefore struggling to learn so many different things at once) I thought that if I could just generate one bit matrix with all the pairwise comparisons, I could then pick out the stuff I actually want later (probably just manually at first, but later hopefully by automating my code to return a matrix with just the comparisons I want). Here is the code: DV-factors[,1] IV-factors[,2] int-factors[,3] IV-IV[!is.na(IV)] int-int[!is.na(int)] #Limit our modification of reference values to categorical variables only by redefining IV vector as IVcat IVcat-IV for(p in 1:length(IV)){ if((class(dataset[[toString(IV[p])]])==character)|(class(dataset[[toString(IV[p])]])==factor)){ IVcat[p]-IV[p] } else{IVcat[p]-} } IVcat-IVcat[!is.na(IVcat)] #Create vectors (IVvalslist[n] for nth factor) for each IVcat containing each possible value for that IV IVvalslist-vector('list', length(IVcat)) for(i in 1:length(IVcat)){ assign(paste(IVvalues,i,sep=),unique(dataset[[toString(IVcat[i])]])[!is.na(unique(dataset[[toString(IVcat[i])]]))]) IVvalslist[i]-list(get(paste(IVvalues,i,sep=))) } #Create a data frame (refM) with every combination of values for each IVcat refM-expand.grid(IVvalslist) #Loop through all possible reference values, and then run the model, #and then compile the model summary output into a single matrix #Go through each row of the matrix of possible reference value combinations for(j in 1:nrow(refM)){ #Go through each reference value for each factor in that row, and assign #that reference value for that factor for(k in 1:length(IVcat)){ dataset[[ toString(IVcat[k]) ]]-relevel(dataset[[ toString(IVcat[k]) ]],ref=toString(refM[j,k])) } #Run model with new reference values from row j model-paste(paste(DV[1],~1,sep=),paste(IV,collapse=+),paste(int,collapse=+),sep=+) modeloutput-glm(model,family=binomial(logit),data=dataset) #assigning all output from every possible combo of ref values to a single matrix named coeffM if(j==1){coeffM-coef(summary(modeloutput))} if(j1){coeffM-rbind(coeffM,coef(summary(modeloutput)))} } *I tested each step of the code individually, and each individual step runs fine. However, when I run the whole set of code at once, I get the following error message after the last line of R input above: Warning in model.matrix.default(mt, mf, contrasts) : variable 'retention' converted to a factor Error in weights * y : non-numeric argument to binary operator And if I ask for R to return coeffM or modeloutput, it tells me that no such objects exist. * The object factors is as follows: factors var1 var2 var3 1 retention method method*level 2 NA level NA 3 NAgpa NA And I can't give the actual dataset (named dataset above) here for human subject reasons, but here is a made-up sample of what it looks like: id instructor method success retention levelcareer 1 1001 NAME1 online 1 1 LL career 2 1002 NAME2 face-to-face 1 1 UL lib. arts STEM required ethnicity gender age finaid gpa 1 non-STEM electiveAsian or Pacific Islander M 28 1.97 2 non-STEM maj. req. Asian or Pacific Islander F 21 none3.01 experiencecreditsyrsenrolled course 1 no online exp. 22 1 NAME1_MAT100 2 no online exp. 33 2 NAME2_ENG100 If anyone can help me figure out what is going wrong here, I'd be incredibly grateful! I've tried searching repeatedly for this error, and the other instances that I've found
Re: [R] Colors in interaction plots
Iuri: Your code as emailed reads: ## data(npk, package=MASS) fit - by(npk, npk$block, function(bydata) fitted.values(lm(yield ~ N, data=bydata))) fit - unlist(fit) interaction.plot(npk$N, npk$block, fit, xlab=N, ylab=yield) # fake factor, numeric fac - c(rep(1,12),rep(2,12)) # plots everything in black interaction.plot(npk$N, npk$block, fit, xlab=N, ylab=yield,col=fac) cbind(npk$block,fac) # plots everything black as well fac - as.factor(fac) interaction.plot(npk$N, npk$block, fit, xlab=N, ylab=yield,col=as.numeric(fac)) # Close inspection shows that the definition of fac is buried in a comment on the fifth line of the code, so it was not running. Having disentangled that, did you inspect fac? fac is a length 24 vector with the first 12 values equal to 1 - corresponding to black. You are plotting only six lines all of which plot correctly as black when I run the code because the first 6 values in the colour vector you supply are all black. If you want to plot 6 different colour lines, try, for example, col=1:6. Hope that helps you clear things up! S Ellison *** This email and any attachments are confidential. Any use...{{dropped:8}} __ 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] importing a SAS syntax-files (value labels)
it is easy to parse through yourself. if you don't care about the labels and just want to import fixed-width file data, you can use the SAScii package. if you do, run this code to get 'em :) # load the stringr package to trim strings quickly library(stringr) # example proc format block-- # store the proc format text.. you can use ?readLines to import your file instead proc.format - proc format; value $resstatus 'B'= 'Jahresaufenthalter' 'C' = 'Niedergelassene' 'I' = 'Dipl./int. Funkt. und Angehörige' ; run; # separate all strings by return characters x - strsplit( proc.format , \n )[[1]] # then break the strings apart by the equals signs y - strsplit( x , = ) # throw out the lines you don't need by hand # only the third through fifth rows contain anything of value. z - y[ 3:5 ] # extract the first and second elements of the list `z` value - sapply( z , [[ , 1 ) label - sapply( z , [[ , 2 ) # trim outside whitespace value - str_trim( value ) label - str_trim( label ) # remove first and last ' character value - substr( value , 2 , nchar( value ) - 1 ) label - substr( label , 2 , nchar( label ) - 1 ) # print the results to the screen value label On Thu, Jan 17, 2013 at 10:39 AM, David Studer stude...@gmail.com wrote: Hello everybody, I imported an SAS data-file into R. open.sas7bdat() did not work, so I had to convert it to csv first. Now I would like to recode the value values into factors. Unfortunately I only have a SAS syntax file, having this form: proc format; value $resstatus 'B'= 'Jahresaufenthalter' 'C' = 'Niedergelassene' 'I' = 'Dipl./int. Funkt. und Angehörige' ; run; Does anyone know if there is a possibility to change the numeric value labels into factor levels acording to the SAS syntax-file? I cannot do this manually as there are several hundred labels... Thank you! [[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] create block diagonal with each rows
arun smartpink...@yahoo.com on Wed, 16 Jan 2013 19:20:46 -0800 writes: Hi, May be this helps: library(Matrix) res1-lapply(split(x,1:nrow(x)),function(y) sparseMatrix(i=rep(1:4,each=5),j=1:(4*5),x=y)) do.call(rbind,lapply(seq_along(res1),function(i) res1[[i]][i,])) # [,1] [,2] [,3] [,4] [,5] [,6] [,7] [,8] [,9] [,10] [,11] [,12] [,13] [,14] #[1,] 1 5 9 13 17 0 0 0 0 0 0 0 0 0 #[2,] 0 0 0 0 0 2 6 10 14 18 0 0 0 0 #[3,] 0 0 0 0 0 0 0 0 0 0 3 7 11 15 #[4,] 0 0 0 0 0 0 0 0 0 0 0 0 0 0 # [,15] [,16] [,17] [,18] [,19] [,20] #[1,] 0 0 0 0 0 0 #[2,] 0 0 0 0 0 0 #[3,] 19 0 0 0 0 0 #[4,] 0 4 8 12 16 20 Thank you for thinking of Matrix (the package, not the movie) here. If you do, x - matrix(1:20, 4,5) require(Matrix) the following is a tiny bit nicer, using the bdiag() function which has been written to create block diagonal matrices. t(bdiag(split(x,1:nrow(x 4 x 20 sparse Matrix of class dgCMatrix [1,] 1 5 9 13 17 . . . . . . . . . . . . . . . [2,] . . . . . 2 6 10 14 18 . . . . . . . . . . [3,] . . . . . . . . . . 3 7 11 15 19 . . . . . [4,] . . . . . . . . . . . . . . . 4 8 12 16 20 and if you don't want a sparse matrix for some reason, (and think twice: it may be more efficient to keep it !) you wrap the result with a as.matrix( result ) --- Martin Maechler, ETH Zurich - Original Message - From: Kathryn Lord kathryn.lord2...@gmail.com To: r-help r-help@r-project.org Cc: Sent: Wednesday, January 16, 2013 9:11 PM Subject: [R] create block diagonal with each rows Dear R users, I'd like to create a block diagonal matrix with each rows in a matrix. Here is a simple example. (In fact, the matrix is big) x - matrix(1:20, 4,5) x [,1] [,2] [,3] [,4] [,5] [1,] 1 5 9 13 17 [2,] 2 6 10 14 18 [3,] 3 7 11 15 19 [4,] 4 8 12 16 20 With each rows in matrix x, I'd like to make the matrix below. [,1] [,2] [,3] [,4] [,5] [,6] [,7] [,8] [,9][,10] [,11][,12][,13][,14][,15][,16][,17][,18][,19][,20] [1,] 1 5 9 13 17 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 [2,] 0 0 0 0 0 2 6 10 14 18 0 0 0 0 0 0 0 0 0 0 [3,] 0 0 0 0 0 0 0 0 0 0 3 7 11 15 19 0 0 0 0 0 [4,] 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 4 8 12 16 20 Any suggestion will be greatly appreciated. Best, Kathryn Lord [[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] How do I get Garamond font in R?
Folks, I run R on a early 2009 MacBook Pro running Mountain Lion. I have a bunch of fonts in my user Library one of which is Garamond. I have tried the ttf_import function to no avail. I played with this for a couple of hours at least and I have gotten nowhere. Here is a bit of one of my sessions (note that I used file.choose to get down to the Font level) require(extrafont) Loading required package: extrafont Registering fonts with R Warning messages: 1: In loadfonts(pdf, quiet = TRUE) : More than one version of regular/bold/italic found for Apple Braille. Skipping setup for this font. 2: In loadfonts(pdf, quiet = TRUE) : No regular (non-bold, non-italic) version of Brush Script MT. Skipping setup for this font. 3: In loadfonts(postscript, quiet = TRUE) : More than one version of regular/bold/italic found for Apple Braille. Skipping setup for this font. 4: In loadfonts(postscript, quiet = TRUE) : No regular (non-bold, non-italic) version of Brush Script MT. Skipping setup for this font. fonts() [1] .Keyboard Andale Mono Apple Braille AppleMyungjo [5] Arial Black Arial Arial Narrow Arial Rounded MT Bold [9] Arial Unicode MS BatangBrush Script MT Calibri [13] Cambria Candara Comic Sans MS Consolas [17] ConstantiaCorbelCourier New Georgia [21] Gulim Humor SansImpact Jazz [25] JazzCord JazzPerc JazzText JazzTextExtended [29] Khmer Sangam MN Krini Krinitsky Lao Sangam MN [33] Microsoft Sans Serif MS Gothic MS Mincho MS PGothic [37] MS PMinchoMusicalSymbolsMyanmar Sangam MN PMingLiU [41] SimSunSinfonia Tahoma Times New Roman [45] Trebuchet MS Verdana Webdings Wingdings [49] Wingdings 2 Wingdings 3 ttf_import(file.choose()) Scanning ttf files in /Users/kw/Library/Fonts/Garamond ... Extracting .afm files from .ttf files... Error in data.frame(fontfile = ttfiles, FontName = , stringsAsFactors = FALSE) : arguments imply differing number of rows: 0, 1 Here is what Font Book has to say about the font: Garamond Garamond PostScript name Garamond Full name Garamond Family Garamond Style Regular KindTrueType LanguageAfrikaans, Albanian, Basque, Cornish, Danish, Dutch, English, Faroese, French, Galician, German, Icelandic, Indonesian, Irish, Italian, Malay, Manx, Norwegian Bokmål, Norwegian Nynorsk, Oromo, Portuguese, Somali, Spanish, Swahili, Swedish, Swiss German, Zulu Script Latin Version Version 2.35 Location/Users/kw/Library/Fonts/Garamond Unique name Monotype - Garamond Regular ManufacturerMonotype Typography, Inc. DesignerClaude Garamond Copyright Digitized data copyright Monotype Typography, Ltd 1991-1995. All rights reserved. Monotype Garamond® is a trademark of Monotype Typography, Ltd which may be registered in certain jurisdictions. Trademark Monotype Garamond® is a trademark of Monotype Typography, Ltd which may be registered in certain jurisdictions. Description Monotype Drawing Office 1922. This typeface is based on roman types cut by Jean Jannon in 1615. Jannon followed the designs of Claude Garamond which had been cut in the previous century. Garamond's types were, in turn, based on those used by Aldus Manutius in 1495 and cut by Francesco Griffo. The italic is based on types cut in France circa 1557 by Robert Granjon. Garamond is a beautiful typeface with an air of informality which looks good in a wide range of applications. It works particularly well in books and lengthy text settings. License NOTIFICATION OF LICENSE AGREEMENT This typeface is the property of Monotype Typography and its use by you is covered under the terms of a license agreement. You have obtained this typeface software either directly from Monotype or together with software distributed by one of Monotypes licensees. This software is a valuable asset of Monotype. Unless you have entered into a specific license agreement granting you additional rights, your use of this software is limited to your workstation for your own publishing use. You may not copy or distribute this software. If you have any question concerning your rights you should review the license agreement you received with the software or contact Monotype for a copy of the license agreement. Monotype can be contacted at: USA 847-718-0400 UK 44(0)1737 765959 For license
[R] How to calculate monthly average from daily files in R?
I have 365 binary files: https://echange-fichiers.inra.fr/get?k=oy3CN1yV1Um7ouRWm2U ,I want to calculate the monthly average. So from the 365 files, I will get 12 files.I would like also to tell R not to take into account the no-data value (-32765).for example, for the first month, there are 31 records: 3 of these records has the value -32765,I want R to take the average of the rest records(28 records) and so on with all months. This code will take the average of every 30 files(any idea on how to make it according to number of days in a month?and not to take into account the no-data values) files- list.files(C:\\New folder (4)\\New folder, *.bin,full.names=TRUE) # assume that we want to take the average of every 30 files files.group- split(files , rep(seq_along(files), each = 30, length =length(files))) results- list() for (.files in files.group){ # read in the 30 files as a vector of numbers that you take the average of x- do.call(rbind,(lapply(.files, readBin , double() , size = 4 ,n =360 * 720 , signed =T))) ## take the means across the 30 files results[[length(results) + 1L]]- colMeans(x)} close(x) for (i in seq_along(results)){ fileName - sprintf(C:/New folder/glo_%d.flt, i) writeBin(as.double(results[[i]]), fileName, size = 4)} -- View this message in context: http://r.789695.n4.nabble.com/How-to-calculate-monthly-average-from-daily-files-in-R-tp4655869.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] Naming an object after another object...can it be done?
Hello R-helpers, I have run the following line of code: x-dat$col and now I would like to assign names(x) to be dat$col (e.g., a character string equal to the column name that I assigned to x). What I am trying to do is to assign columns in my dataframe to new objects called x and y. Then I will use x and y within a new function to make plots with informative axis labels (e.g., dat$col instead of x. So, for example, I would like to plot (y~x,xlab=names(x)) and have dat$col printed in the x-axis label. I can do this all manually, by typing names(x)- dat$col) but I'd like to do it with non-specific code within my function so I don't have to type the variable names manually each time. Many thanks, Mark Na [[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] Naming an object after another object...can it be done?
are you looking for assign()? On Jan 17, 2013 1:56 PM, mtb...@gmail.com wrote: Hello R-helpers, I have run the following line of code: x-dat$col and now I would like to assign names(x) to be dat$col (e.g., a character string equal to the column name that I assigned to x). What I am trying to do is to assign columns in my dataframe to new objects called x and y. Then I will use x and y within a new function to make plots with informative axis labels (e.g., dat$col instead of x. So, for example, I would like to plot (y~x,xlab=names(x)) and have dat$col printed in the x-axis label. I can do this all manually, by typing names(x)- dat$col) but I'd like to do it with non-specific code within my function so I don't have to type the variable names manually each time. Many thanks, Mark Na [[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] Naming an object after another object...can it be done?
Hi Liu - I have been trying with assign() but it's not working. I don't think that's what I'm looking forany other ideas? Many thanks, Mark On Thu, Jan 17, 2013 at 1:11 PM, Wensui Liu liuwen...@gmail.com wrote: are you looking for assign()? On Jan 17, 2013 1:56 PM, mtb...@gmail.com wrote: Hello R-helpers, I have run the following line of code: x-dat$col and now I would like to assign names(x) to be dat$col (e.g., a character string equal to the column name that I assigned to x). What I am trying to do is to assign columns in my dataframe to new objects called x and y. Then I will use x and y within a new function to make plots with informative axis labels (e.g., dat$col instead of x. So, for example, I would like to plot (y~x,xlab=names(x)) and have dat$col printed in the x-axis label. I can do this all manually, by typing names(x)- dat$col) but I'd like to do it with non-specific code within my function so I don't have to type the variable names manually each time. Many thanks, Mark Na [[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] How can i keep only latest entries?
Hello togehter, i have a data.frame like this one: No. Date last change 1 1 2012-10-04 change settings 2 1 2012-10-20 bug fix 3 1 2012-11-05 final 4 2 2013-01-15new task 5 2 2013-01-16Bug fix 6 2 2013-01-17final now i want a new data.frame, who show me only the newest entries according to the No. The solution look like this one: No. Datelast change 1 1 2012-11-05 final 2 2 2013-01-17 final can anyone help me? thanks. Mat -- View this message in context: http://r.789695.n4.nabble.com/How-can-i-keep-only-latest-entries-tp4655827.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] Issue while installing Hmisc package
Hello Michael, I have tried with different CRAN but still i am getting the same error. But still, i am also trying to install the package by locally giving absolute path with repos= Null and type = Source, will CRAN have any role to play here??? BR- Vaseem Shaikh On Thu, Jan 17, 2013 at 3:03 PM, Michael Weylandt michael.weyla...@gmail.com wrote: Try a different CRAN mirror. MW On Jan 17, 2013, at 7:42 AM, vaseem shaikh vsma...@gmail.com wrote: Hi, Please find the snap shot attached for the error reported wile installing Hmisc Package. Is there any thing you can help me with. Currently using R i386 2.15.2 Version of R on windows 7 platform. Ragards Vaseem Shaikh Instalation_Issue_HMISC.png __ 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.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-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
[R] Explore patterns with GAM
Dear all, I new to r and I would like your help. I want to explore the patterns (unimodal, monotonically increased/decreased) of species richness~altitude using GAM in R. Although I run the gam function in mgcv package I do not know how to manually define knots and degrees of freedom. Any help would be greatly appreciated. Spyros -- View this message in context: http://r.789695.n4.nabble.com/Explore-patterns-with-GAM-tp4655838.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] Line breaks in documentation \useage
Hi again, R community. I wonder how you do line breaks in \useage{} section in .Rd files. I am sure there's some tutorial for this somewhere, but I just haven't found it. I have tried \\, \cr, \br and \newline, admittedly arbitrarily, but all of these produce warnings or errors. br, Markku __ 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] create block diagonal with each rows
Hi, I tried with kronecker() do.call(rbind,lapply(1:4,function(i) t(kronecker(diag(4), x[i,]))[i,])) # [,1] [,2] [,3] [,4] [,5] [,6] [,7] [,8] [,9] [,10] [,11] [,12] [,13] [,14] [1,] 1 5 9 13 17 0 0 0 0 0 0 0 0 0 #[2,] 0 0 0 0 0 2 6 10 14 18 0 0 0 0 #[3,] 0 0 0 0 0 0 0 0 0 0 3 7 11 15 #[4,] 0 0 0 0 0 0 0 0 0 0 0 0 0 0 # [,15] [,16] [,17] [,18] [,19] [,20] #[1,] 0 0 0 0 0 0 #[2,] 0 0 0 0 0 0 #[3,] 19 0 0 0 0 0 #[4,] 0 4 8 12 16 20 Not sure if there are any shortcuts with kronecker() A.K. - Original Message - From: Martin Maechler maech...@stat.math.ethz.ch To: arun smartpink...@yahoo.com Cc: Kathryn Lord kathryn.lord2...@gmail.com; R help r-help@r-project.org Sent: Thursday, January 17, 2013 12:18 PM Subject: Re: [R] create block diagonal with each rows arun smartpink...@yahoo.com on Wed, 16 Jan 2013 19:20:46 -0800 writes: Hi, May be this helps: library(Matrix) res1-lapply(split(x,1:nrow(x)),function(y) sparseMatrix(i=rep(1:4,each=5),j=1:(4*5),x=y)) do.call(rbind,lapply(seq_along(res1),function(i) res1[[i]][i,])) # [,1] [,2] [,3] [,4] [,5] [,6] [,7] [,8] [,9] [,10] [,11] [,12] [,13] [,14] #[1,] 1 5 9 13 17 0 0 0 0 0 0 0 0 0 #[2,] 0 0 0 0 0 2 6 10 14 18 0 0 0 0 #[3,] 0 0 0 0 0 0 0 0 0 0 3 7 11 15 #[4,] 0 0 0 0 0 0 0 0 0 0 0 0 0 0 # [,15] [,16] [,17] [,18] [,19] [,20] #[1,] 0 0 0 0 0 0 #[2,] 0 0 0 0 0 0 #[3,] 19 0 0 0 0 0 #[4,] 0 4 8 12 16 20 Thank you for thinking of Matrix (the package, not the movie) here. If you do, x - matrix(1:20, 4,5) require(Matrix) the following is a tiny bit nicer, using the bdiag() function which has been written to create block diagonal matrices. t(bdiag(split(x,1:nrow(x 4 x 20 sparse Matrix of class dgCMatrix [1,] 1 5 9 13 17 . . . . . . . . . . . . . . . [2,] . . . . . 2 6 10 14 18 . . . . . . . . . . [3,] . . . . . . . . . . 3 7 11 15 19 . . . . . [4,] . . . . . . . . . . . . . . . 4 8 12 16 20 and if you don't want a sparse matrix for some reason, (and think twice: it may be more efficient to keep it !) you wrap the result with a as.matrix( result ) --- Martin Maechler, ETH Zurich - Original Message - From: Kathryn Lord kathryn.lord2...@gmail.com To: r-help r-help@r-project.org Cc: Sent: Wednesday, January 16, 2013 9:11 PM Subject: [R] create block diagonal with each rows Dear R users, I'd like to create a block diagonal matrix with each rows in a matrix. Here is a simple example. (In fact, the matrix is big) x - matrix(1:20, 4,5) x [,1] [,2] [,3] [,4] [,5] [1,] 1 5 9 13 17 [2,] 2 6 10 14 18 [3,] 3 7 11 15 19 [4,] 4 8 12 16 20 With each rows in matrix x, I'd like to make the matrix below. [,1] [,2] [,3] [,4] [,5] [,6] [,7] [,8] [,9][,10] [,11][,12][,13][,14][,15][,16][,17][,18][,19][,20] [1,] 1 5 9 13 17 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 [2,] 0 0 0 0 0 2 6 10 14 18 0 0 0 0 0 0 0 0 0 0 [3,] 0 0 0 0 0 0 0 0 0 0 3 7 11 15 19 0 0 0 0 0 [4,] 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 4 8 12 16 20 Any suggestion will be greatly appreciated. Best, Kathryn Lord [[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
[R] crontab to Run R Code
Could not figure out where I am going wrong. Following is my code in crontab -e:- MAILTO: users MAILTO= users # m h dom mon dow command 3 19 * * * $HOME/users/REPORT/MAIL; time R --slave report.R [[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 with interpolation
hi guys I need to interpolate values for the zero coupon yield curve. Following data is given datedays rate 1996 01 02 155.74590 1996 01 02 505.67332 1996 01 02 785.60888 1996 01 02 1695.47376 1996 01 02 2605.35267 1996 01 02 3515.27619 1996 01 03 145.74740 1996 01 03 495.67226 1996 01 03 775.60371 1996 01 03 1685.47058 1996 01 03 2595.34662 1996 01 03 3505.26630 For every day i have to interpolate 10 values, for example for maturities of 30,60 or 90 days. I have interpolate data for a one year period, 10 interpolation values a day, so that equals 3600 values. what's the easiest way to implement this in R? please hlep! -- View this message in context: http://r.789695.n4.nabble.com/Help-with-interpolation-tp4655843.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] Naming an object after another object...can it be done?
You are thinking that 'names' does something different than it does. What you seem to be after is the deparse-substitute idiom: dat - data.frame(Col1=1:10, Col2=rnorm(10)) myPlotFun - function(x, y) { plot(y ~ x, xlab=deparse(substitute(x)), ylab=deparse(substitute(y))) } myPlotFun(dat$Col1, dat$Col2) Pat On 17/01/2013 18:53, mtb...@gmail.com wrote: Hello R-helpers, I have run the following line of code: x-dat$col and now I would like to assign names(x) to be dat$col (e.g., a character string equal to the column name that I assigned to x). What I am trying to do is to assign columns in my dataframe to new objects called x and y. Then I will use x and y within a new function to make plots with informative axis labels (e.g., dat$col instead of x. So, for example, I would like to plot (y~x,xlab=names(x)) and have dat$col printed in the x-axis label. I can do this all manually, by typing names(x)- dat$col) but I'd like to do it with non-specific code within my function so I don't have to type the variable names manually each time. Many thanks, Mark Na [[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. -- Patrick Burns pbu...@pburns.seanet.com twitter: @portfolioprobe http://www.portfolioprobe.com/blog http://www.burns-stat.com (home of 'Some hints for the R beginner' and 'The R Inferno') __ 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] plotting from dataframes
thanks to your guys help I am closer to solving my problem but I have some small problem. So let's say I start with data number day hour 1 17 10 2 17 11 3 17 6 4 18 4 5 18 10 6 19 8 7 19 8 I want to split to odd days, which I am able to do, I call this object frames, which looks like: frames $`1` c1 day1 hour1 1 1 1710 2 2 1711 3 3 17 6 $`2` c1 day1 hour1 4 6 19 8 5 7 19 8 Now I want to make plot of the hours of both days, but not by hand. I need some sort of loop for this. How is this done? So par(mfrow=c(1,2)) for(…) plot(…hours…) thanks for the help -- View this message in context: http://r.789695.n4.nabble.com/plotting-from-dataframes-tp4655851.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] Getting discrete colors on plot
Hi, This is my first post; I'm new to R but am a senior statistical programmer. I have done a lot of graphs using SAS Graph but now am trying to transition to using graphs in R. I'm trying to produce a graph where the colors have three categories- ideally I would like them to be Green for good, Yellow for Questionable, and Red for bad. So I tried to do this in GGPLOT; here is my code: id - c(1,2,3,4,5) x1 - c(5,2,3,5,1) x2 - c(4,1,3,5,1) x3 - c(5,2,3,5,1) x4 - c(4,3,3,5,1) x5 - c(3,1,3,5,1) colorvar - c(3,1,2,3,1) mydata - data.frame(id,x1,x2,x3,x4,x5,colorvar) head(mydata) # convert to long format require(reshape) mydata_long - melt(mydata, id=c(id, colorvar)) head(mydata_long) require(ggplot2) p - ggplot(data=mydata_long, aes(x=variable, y=value, group=id, colour = colorvar)) + geom_line() p This works, but I get more colors on the graph than my colorvar has. I have 3 colors on my colorvar, but 5 colors show up on the graph, including 1.5 and 2.5. How do I tell ggplot only to use the 3 colors and not give me a gradient of colors? Also how would I specify the colors that I want, such as the RGB equivalents of green, yellow, and red? My real data will have many more records. -Mary __ 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] how to use ...
The ellipsis object is not listed in the base help pages! help(`+`) # this works - help on arithmetic operators help(+) # also works help(`...`) # fails with Error: '...' used in an incorrect context help(...) # fails also with No documentation for '...' in specified packages and libraries: you could try '??...' -Original Message- From: r-help-boun...@r-project.org [mailto:r-help-boun...@r-project.org] On Behalf Of Ivan Calandra Sent: Friday, 18 January 2013 4:43a To: R. Michael Weylandt Cc: R list Subject: Re: [R] how to use ... Do you know where I can find some documentation about 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] Explore patterns with GAM
Hi Spyros, I suggest that you borrow / buy the book that was written by the author of that package, and study it. It's Generalized Additive Models: An Introduction with R. There's a lot of stuff going on in GAM fitting that it would be worth paying close attention to. I hope that this helps, Andrew On Fri, Jan 18, 2013 at 12:45 AM, spyros stsif...@bio.auth.gr wrote: Dear all, I new to r and I would like your help. I want to explore the patterns (unimodal, monotonically increased/decreased) of species richness~altitude using GAM in R. Although I run the gam function in mgcv package I do not know how to manually define knots and degrees of freedom. Any help would be greatly appreciated. Spyros -- View this message in context: http://r.789695.n4.nabble.com/Explore-patterns-with-GAM-tp4655838.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. -- Andrew Robinson Director (A/g), ACERA Senior Lecturer in Applied Statistics Tel: +61-3-8344-6410 Department of Mathematics and StatisticsFax: +61-3-8344 4599 University of Melbourne, VIC 3010 Australia Email: a.robin...@ms.unimelb.edu.auWebsite: http://www.ms.unimelb.edu.au FAwR: http://www.ms.unimelb.edu.au/~andrewpr/FAwR/ SPuR: http://www.ms.unimelb.edu.au/spuRs/ [[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] crontab to Run R Code
Not sure if it would solve all your problems, but try to specify absolute path first e.g. for R, as *your* PATH is not available for the cronjob. Best, Gergely On Thu, Jan 17, 2013 at 2:53 PM, Pinaki pinakimah...@gmail.com wrote: Could not figure out where I am going wrong. Following is my code in crontab -e:- MAILTO: users MAILTO= users # m h dom mon dow command 3 19 * * * $HOME/users/REPORT/MAIL; time R --slave report.R [[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] Naming an object after another object...can it be done?
If you want the column names but not the data frame name, then you could do: with(dat, myPlotFun(Col1, Col2)) Pat On 17/01/2013 20:07, Patrick Burns wrote: You are thinking that 'names' does something different than it does. What you seem to be after is the deparse-substitute idiom: dat - data.frame(Col1=1:10, Col2=rnorm(10)) myPlotFun - function(x, y) { plot(y ~ x, xlab=deparse(substitute(x)), ylab=deparse(substitute(y))) } myPlotFun(dat$Col1, dat$Col2) Pat On 17/01/2013 18:53, mtb...@gmail.com wrote: Hello R-helpers, I have run the following line of code: x-dat$col and now I would like to assign names(x) to be dat$col (e.g., a character string equal to the column name that I assigned to x). What I am trying to do is to assign columns in my dataframe to new objects called x and y. Then I will use x and y within a new function to make plots with informative axis labels (e.g., dat$col instead of x. So, for example, I would like to plot (y~x,xlab=names(x)) and have dat$col printed in the x-axis label. I can do this all manually, by typing names(x)- dat$col) but I'd like to do it with non-specific code within my function so I don't have to type the variable names manually each time. Many thanks, Mark Na [[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. -- Patrick Burns pbu...@pburns.seanet.com twitter: @portfolioprobe http://www.portfolioprobe.com/blog http://www.burns-stat.com (home of 'Some hints for the R beginner' and 'The R Inferno') __ 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 from dataframes
It's not really clear to me what you mean when you say that you want to plot the hours, so it's hard to help. Regardless, take a look at looping and plotting in any of the free documentation on CRAN. http://cran.r-project.org/other-docs.html I hope that this helps, Andrew On Fri, Jan 18, 2013 at 2:21 AM, condor radonniko...@hotmail.nl wrote: thanks to your guys help I am closer to solving my problem but I have some small problem. So let's say I start with data number day hour 1 17 10 2 17 11 3 17 6 4 18 4 5 18 10 6 19 8 7 19 8 I want to split to odd days, which I am able to do, I call this object frames, which looks like: frames $`1` c1 day1 hour1 1 1 1710 2 2 1711 3 3 17 6 $`2` c1 day1 hour1 4 6 19 8 5 7 19 8 Now I want to make plot of the hours of both days, but not by hand. I need some sort of loop for this. How is this done? So par(mfrow=c(1,2)) for( ) plot( hours ) thanks for the help -- View this message in context: http://r.789695.n4.nabble.com/plotting-from-dataframes-tp4655851.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. -- Andrew Robinson Director (A/g), ACERA Senior Lecturer in Applied Statistics Tel: +61-3-8344-6410 Department of Mathematics and StatisticsFax: +61-3-8344 4599 University of Melbourne, VIC 3010 Australia Email: a.robin...@ms.unimelb.edu.auWebsite: http://www.ms.unimelb.edu.au FAwR: http://www.ms.unimelb.edu.au/~andrewpr/FAwR/ SPuR: http://www.ms.unimelb.edu.au/spuRs/ [[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] how to use ...
Here's a link (on my local CRAN)... http://cran.stat.auckland.ac.nz/doc/manuals/r-release/R-intro.html#The-three-dots-argument -Original Message- From: r-help-boun...@r-project.org [mailto:r-help-boun...@r-project.org] On Behalf Of Bert Gunter Sent: Friday, 18 January 2013 4:54a To: ivan.calan...@u-bourgogne.fr Cc: R list Subject: Re: [R] how to use ... Well.. On Thu, Jan 17, 2013 at 7:42 AM, Ivan Calandra ivan.calan...@u-bourgogne.fr wrote: Ok, it is that simple... Actually I had tried it but messed up so that it didn't work. Do you know where I can find some documentation about it? The R language definition manual would be the logical place to look, no? And sure enough, it's there! The Introduction to R tutorial also contains info in the writing functions section. A very good, though now dated, exposition can be found in VR's S Programming book. Although a little care is needed due to age, it's still my favorite. -- Bert Regarding return(), I know that it's not necessary, but when the function gets more complicated, I like to have it because it becomes clearer to me. Thanks all! Ivan -- Ivan CALANDRA Université de Bourgogne UMR CNRS/uB 6282 Biogéosciences 6 Boulevard Gabriel 21000 Dijon, FRANCE +33(0)3.80.39.63.06 ivan.calan...@u-bourgogne.fr http://biogeosciences.u-bourgogne.fr/calandra Le 17/01/13 15:55, R. Michael Weylandt a écrit : On Thu, Jan 17, 2013 at 2:36 PM, Ivan Calandra ivan.calan...@u-bourgogne.fr wrote: Dear users, I'm trying to learn how to use the I have written a function (simplified here) that uses doBy::summaryBy(): # 'dat' is a data.frame from which the aggregation is computed # 'vec_cat' is a integer vector defining which columns of the data.frame should be use on the right side of the formula # 'stat_fun' is the function that will be run to aggregate stat.group - function(dat, vec_cat, stat_fun){ require(doBy) df - summaryBy(as.formula(paste0(.~,paste0(names(dat)[vec_cat],collapse=+))), data=dat, FUN=stat_fun) return(df) } [SNIP EXAMPLE -- THANK YOU FOR IT] Now summaryBy() has an ... argument and I would like to use it. For example, I would like to be able to add the trim argument to my call like this: stat.group(dat=my_data, vec_cat=1, stat_fun=mean, trim=0.2) Thanks for the great working examples! It's actually not too hard here -- just pass ... down as if it were an argument and let summaryBy() do the hard work of actually handling the dots: stat.group - function(dat, vec_cat, stat_fun, ...){ require(doBy) df - summaryBy(as.formula(paste0(.~,paste0(names(dat)[vec_cat],collapse=+))), data=dat, FUN=stat_fun, ...) return(df) } Also, note that as a matter of style, you can actually clean this up a little bit: R follows the trend of many functional languages in automatically returning the value of the last expression evaluated: stat.group - function(dat, vec_cat, stat_fun, ...){ require(doBy) summaryBy(as.formula(paste0(.~,paste0(names(dat)[vec_cat],collapse=+))), data=dat, FUN=stat_fun, ...) } Cheers, Michael __ 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. __ 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] Naming an object after another object...can it be done?
? But Pat... The canonical way to do this is: myPlotFin(Col2 ~ Col1, data = dat) I have no idea what the OP wants, but my guess is that the right answer is: Don't do that. Cheers, Bert On Thu, Jan 17, 2013 at 12:25 PM, Patrick Burns pbu...@pburns.seanet.com wrote: If you want the column names but not the data frame name, then you could do: with(dat, myPlotFun(Col1, Col2)) Pat On 17/01/2013 20:07, Patrick Burns wrote: You are thinking that 'names' does something different than it does. What you seem to be after is the deparse-substitute idiom: dat - data.frame(Col1=1:10, Col2=rnorm(10)) myPlotFun - function(x, y) { plot(y ~ x, xlab=deparse(substitute(x)), ylab=deparse(substitute(y))) } myPlotFun(dat$Col1, dat$Col2) Pat On 17/01/2013 18:53, mtb...@gmail.com wrote: Hello R-helpers, I have run the following line of code: x-dat$col and now I would like to assign names(x) to be dat$col (e.g., a character string equal to the column name that I assigned to x). What I am trying to do is to assign columns in my dataframe to new objects called x and y. Then I will use x and y within a new function to make plots with informative axis labels (e.g., dat$col instead of x. So, for example, I would like to plot (y~x,xlab=names(x)) and have dat$col printed in the x-axis label. I can do this all manually, by typing names(x)- dat$col) but I'd like to do it with non-specific code within my function so I don't have to type the variable names manually each time. Many thanks, Mark Na [[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. -- Patrick Burns pbu...@pburns.seanet.com twitter: @portfolioprobe http://www.portfolioprobe.com/blog http://www.burns-stat.com (home of 'Some hints for the R beginner' and 'The R Inferno') __ 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] Naming an object after another object...can it be done?
Hi everyone, and thanks for your replies. Let me make this a little simpler. Please forget the plotting, that's not the issue. I have run the following line of code: x-dat.col Now, is there a function (or combination of functions) that will let me assign the character string dat.col to a new object (called y) without actually typing the characters dat$col, i.e. just by referring to x? Many thanks, Mark Na On Thu, Jan 17, 2013 at 3:20 PM, Bert Gunter gunter.ber...@gene.com wrote: ? But Pat... The canonical way to do this is: myPlotFin(Col2 ~ Col1, data = dat) I have no idea what the OP wants, but my guess is that the right answer is: Don't do that. Cheers, Bert On Thu, Jan 17, 2013 at 12:25 PM, Patrick Burns pbu...@pburns.seanet.com wrote: If you want the column names but not the data frame name, then you could do: with(dat, myPlotFun(Col1, Col2)) Pat On 17/01/2013 20:07, Patrick Burns wrote: You are thinking that 'names' does something different than it does. What you seem to be after is the deparse-substitute idiom: dat - data.frame(Col1=1:10, Col2=rnorm(10)) myPlotFun - function(x, y) { plot(y ~ x, xlab=deparse(substitute(x)), ylab=deparse(substitute(y))) } myPlotFun(dat$Col1, dat$Col2) Pat On 17/01/2013 18:53, mtb...@gmail.com wrote: Hello R-helpers, I have run the following line of code: x-dat$col and now I would like to assign names(x) to be dat$col (e.g., a character string equal to the column name that I assigned to x). What I am trying to do is to assign columns in my dataframe to new objects called x and y. Then I will use x and y within a new function to make plots with informative axis labels (e.g., dat$col instead of x. So, for example, I would like to plot (y~x,xlab=names(x)) and have dat$col printed in the x-axis label. I can do this all manually, by typing names(x)- dat$col) but I'd like to do it with non-specific code within my function so I don't have to type the variable names manually each time. Many thanks, Mark Na [[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. -- Patrick Burns pbu...@pburns.seanet.com twitter: @portfolioprobe http://www.portfolioprobe.com/blog http://www.burns-stat.com (home of 'Some hints for the R beginner' and 'The R Inferno') __ 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 [[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] How can i keep only latest entries?
Hello, Try the following. (I've named your data.frame 'dat') do.call(rbind, lapply(split(dat, dat$`No.`), tail, 1)) Hope this helps, Rui Barradas Em 17-01-2013 10:50, Mat escreveu: Hello togehter, i have a data.frame like this one: No. Date last change 1 1 2012-10-04 change settings 2 1 2012-10-20 bug fix 3 1 2012-11-05 final 4 2 2013-01-15new task 5 2 2013-01-16Bug fix 6 2 2013-01-17final now i want a new data.frame, who show me only the newest entries according to the No. The solution look like this one: No. Datelast change 1 1 2012-11-05 final 2 2 2013-01-17 final can anyone help me? thanks. Mat -- View this message in context: http://r.789695.n4.nabble.com/How-can-i-keep-only-latest-entries-tp4655827.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] How to convert a string to the column it represents in a dataframe, with a reproducible example
Hello R-helpers, I have run the following lines of code: x-cars$dist y-noquote(x) Now y is a string containing the characters cars$dist My questionis there an R function (or combination of functions) that I can apply to y that will cause y to contain the numbers in cars$dist? Even better, can I do it without using noquote()? Many thanks, Mark Na [[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] Naming an object after another object...can it be done?
On Thu, Jan 17, 2013 at 1:29 PM, mtb...@gmail.com wrote: Hi everyone, and thanks for your replies. Let me make this a little simpler. Please forget the plotting, that's not the issue. I have run the following line of code: x-dat.col Now, is there a function (or combination of functions) that will let me assign the character string dat.col to a new object (called y) without actually typing the characters dat$col, i.e. just by referring to x? No. x contains only the values. As I said, don't do this. -- Bert Many thanks, Mark Na On Thu, Jan 17, 2013 at 3:20 PM, Bert Gunter gunter.ber...@gene.com wrote: ? But Pat... The canonical way to do this is: myPlotFin(Col2 ~ Col1, data = dat) I have no idea what the OP wants, but my guess is that the right answer is: Don't do that. Cheers, Bert On Thu, Jan 17, 2013 at 12:25 PM, Patrick Burns pbu...@pburns.seanet.com wrote: If you want the column names but not the data frame name, then you could do: with(dat, myPlotFun(Col1, Col2)) Pat On 17/01/2013 20:07, Patrick Burns wrote: You are thinking that 'names' does something different than it does. What you seem to be after is the deparse-substitute idiom: dat - data.frame(Col1=1:10, Col2=rnorm(10)) myPlotFun - function(x, y) { plot(y ~ x, xlab=deparse(substitute(x)), ylab=deparse(substitute(y))) } myPlotFun(dat$Col1, dat$Col2) Pat On 17/01/2013 18:53, mtb...@gmail.com wrote: Hello R-helpers, I have run the following line of code: x-dat$col and now I would like to assign names(x) to be dat$col (e.g., a character string equal to the column name that I assigned to x). What I am trying to do is to assign columns in my dataframe to new objects called x and y. Then I will use x and y within a new function to make plots with informative axis labels (e.g., dat$col instead of x. So, for example, I would like to plot (y~x,xlab=names(x)) and have dat$col printed in the x-axis label. I can do this all manually, by typing names(x)- dat$col) but I'd like to do it with non-specific code within my function so I don't have to type the variable names manually each time. Many thanks, Mark Na [[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. -- Patrick Burns pbu...@pburns.seanet.com twitter: @portfolioprobe http://www.portfolioprobe.com/blog http://www.burns-stat.com (home of 'Some hints for the R beginner' and 'The R Inferno') __ 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 -- 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.
[R] How to delete repeated values in MCMC sampling and get index of unique values?
Dear list, How do you delete repeated samples? In MCMC, when your candidate value has been reject, so you remain on the same point, so you keep that value. Say I have this toy example, c(1,6,6,6,3,5,4,4,2,3,5) The 6 and 4 are repeated, I only want the index of the non-repeated values. I thought of using which() and unique(), but that does not give you the index of the unique values. Thanks in advance. Mike [[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] How to delete repeated values in MCMC sampling and get index of unique values?
On 13-01-17 4:50 PM, C W wrote: Dear list, How do you delete repeated samples? In MCMC, when your candidate value has been reject, so you remain on the same point, so you keep that value. Say I have this toy example, c(1,6,6,6,3,5,4,4,2,3,5) The 6 and 4 are repeated, I only want the index of the non-repeated values. I thought of using which() and unique(), but that does not give you the index of the unique values. You could use x[!duplicated(x)] or rle(x)$values, depending on your definition of repeated. I hope you're aware that you can't use either for things like quantiles and moments of the limiting distribution. x - c(1,6,6,6,3,5,4,4,2,3,5) x[!duplicated(x)] [1] 1 6 3 5 4 2 rle(x)$values [1] 1 6 3 5 4 2 3 5 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] fastICA package: C, R codes provide vastly different results
Dear friends, I have been trying out the C and the R codes in the fastICA package. However, it turns out that these often give vastly different results, especially when row.norm is set to T. This happens even though I have initialized the input matrix to be exactly the same for both of them. Here is an example: ### cut code here xx - read.table(file = http://maitra.public.iastate.edu/SharadUtshob05.dat;) win - matrix(c(-0.434590, 1.288207, -0.597128, -0.501621, 1.434678, 0.812076, -1.281559, -1.798178, 0.409151), ncol = 3) library(fastICA) adeflate.C - fastICA(X = xx, alg.typ=deflation, row.norm=T, w.init=win, n.comp=3, fun = logcosh, method = C) adeflate.R - fastICA(X = xx, alg.typ=deflation, row.norm=T, w.init=win, n.comp=3, fun = logcosh, method = R) ### end code here. The answers follow: note that the final un-mixing matrix estimate W is not even close to each other. adeflate.R$W [,1] [,2] [,3] [1,] -0.85074291 -0.2385149 0.4683451 [2,] 0.02907471 -0.9110909 -0.4111789 [3,] -0.52477726 0.3361905 -0.7820388 adeflate.C$W [,1] [,2] [,3] [1,] -0.001317682 -0.9904552102 -0.137828767 [2,] -0.006132130 0.1378342956 -0.990436316 [3,] 0.80330 -0.0004598964 -0.006255222 Can anyone throw light on this matter? On the other hand, using row.norm = F provides the following results: adeflate.R$W [,1] [,2] [,3] [1,] -0.86309623 -0.2103872 0.4591319 [2,] -0.01433631 -0.8985285 -0.4386811 [3,] -0.50483598 0.3852062 -0.7725003 which is not as much different (but still quite different) from adeflate.C$W [,1] [,2] [,3] [1,] -0.83111268 0.2247869 0.5086478 [2,] -0.01217191 0.9070906 -0.4207594 [3,] -0.55597085 -0.3558897 -0.7511584 What is the problem? Am I assuming something here that i should not in my inputs? Many thanks again for any help! Best wishes, Ranjan -- Important Notice: This mailbox is ignored: e-mails are set to be deleted on receipt. For those needing to send personal or professional e-mail, please use appropriate addresses. GET FREE SMILEYS FOR YOUR IM EMAIL - Learn more at http://www.inbox.com/smileys Works with AIM®, MSN® Messenger, Yahoo!® Messenger, ICQ®, Google Talk™ and most webmails __ 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] Naming an object after another object...can it be done?
On Jan 17, 2013, at 1:29 PM, mtb...@gmail.com wrote: Hi everyone, and thanks for your replies. Let me make this a little simpler. Please forget the plotting, that's not the issue. I have run the following line of code: x-dat.col Now, is there a function (or combination of functions) that will let me assign the character string dat.col to a new object (called y) without actually typing the characters dat$col, i.e. just by referring to x? It is unclear what you intend. It is possible to rename the x-object and it is possible to name individual elements of a multi-element object named x. It is furthermore possble to construct an attribute that will remain with x. So, provide a complete example and it may become clearer. Also specify whether you are attempting to do this on an object which has been attached, and if so, then the right answer will be don't use attach(). -- David. Many thanks, Mark Na On Thu, Jan 17, 2013 at 3:20 PM, Bert Gunter gunter.ber...@gene.com wrote: ? But Pat... The canonical way to do this is: myPlotFin(Col2 ~ Col1, data = dat) I have no idea what the OP wants, but my guess is that the right answer is: Don't do that. Cheers, Bert On Thu, Jan 17, 2013 at 12:25 PM, Patrick Burns pbu...@pburns.seanet.com wrote: If you want the column names but not the data frame name, then you could do: with(dat, myPlotFun(Col1, Col2)) Pat On 17/01/2013 20:07, Patrick Burns wrote: You are thinking that 'names' does something different than it does. What you seem to be after is the deparse-substitute idiom: dat - data.frame(Col1=1:10, Col2=rnorm(10)) myPlotFun - function(x, y) { plot(y ~ x, xlab=deparse(substitute(x)), ylab=deparse(substitute(y))) } myPlotFun(dat$Col1, dat$Col2) Pat On 17/01/2013 18:53, mtb...@gmail.com wrote: Hello R-helpers, I have run the following line of code: x-dat$col and now I would like to assign names(x) to be dat$col (e.g., a character string equal to the column name that I assigned to x). What I am trying to do is to assign columns in my dataframe to new objects called x and y. Then I will use x and y within a new function to make plots with informative axis labels (e.g., dat$col instead of x. So, for example, I would like to plot (y~x,xlab=names(x)) and have dat$col printed in the x-axis label. I can do this all manually, by typing names(x)- dat$col) but I'd like to do it with non-specific code within my function so I don't have to type the variable names manually each time. Many thanks, Mark Na [[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. -- Patrick Burns pbu...@pburns.seanet.com twitter: @portfolioprobe http://www.portfolioprobe.com/blog http://www.burns-stat.com (home of 'Some hints for the R beginner' and 'The R Inferno') __ 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 [[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. David Winsemius Alameda, CA, USA __ 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] Issue while installing Hmisc package
On Thu, Jan 17, 2013 at 4:57 AM, vaseem shaikh vsma...@gmail.com wrote: But still, i am also trying to install the package by locally giving absolute path with repos= Null and type = Source, will CRAN have any role to play here??? To compile a package on Windows, you need to install R tools (Rtools) that contain the compilers and other software necessary for the compilation. The error you saw with the installation from local .tar.gz file indeed has nothing to do with CRAN but with the fact that you are missing the tools. See http://cran.r-project.org/doc/manuals/r-release/R-admin.html#The-Windows-toolset for details. If you don't want to install the Windows toolset, you can go to the Hmisc CRAN web page at http://cran.r-project.org/web/packages/Hmisc/index.html , download the Windows binary and install that using repos = NULL (but not type = source). HTH 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] How to convert a string to the column it represents in a dataframe, with a reproducible example
On Jan 17, 2013, at 1:36 PM, mtb...@gmail.com wrote: Hello R-helpers, I have run the following lines of code: x-cars$dist y-noquote(x) Now y is a string containing the characters cars$dist My questionis there an R function (or combination of functions) that I can apply to y that will cause y to contain the numbers in cars$dist? Even better, can I do it without using noquote()? What is the goal of this effort? -- David Winsemius Alameda, CA, USA __ 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] How to delete repeated values in MCMC sampling and get index of unique values?
Exactly what I am looking for. Thanks a lot! Mike On Thu, Jan 17, 2013 at 4:59 PM, Duncan Murdoch murdoch.dun...@gmail.comwrote: On 13-01-17 4:50 PM, C W wrote: Dear list, How do you delete repeated samples? In MCMC, when your candidate value has been reject, so you remain on the same point, so you keep that value. Say I have this toy example, c(1,6,6,6,3,5,4,4,2,3,5) The 6 and 4 are repeated, I only want the index of the non-repeated values. I thought of using which() and unique(), but that does not give you the index of the unique values. You could use x[!duplicated(x)] or rle(x)$values, depending on your definition of repeated. I hope you're aware that you can't use either for things like quantiles and moments of the limiting distribution. x - c(1,6,6,6,3,5,4,4,2,3,5) x[!duplicated(x)] [1] 1 6 3 5 4 2 rle(x)$values [1] 1 6 3 5 4 2 3 5 Duncan Murdoch [[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] How to delete repeated values in MCMC sampling and get index of unique values?
On Jan 17, 2013, at 1:50 PM, C W wrote: Dear list, How do you delete repeated samples? In MCMC, when your candidate value has been reject, so you remain on the same point, so you keep that value. Say I have this toy example, c(1,6,6,6,3,5,4,4,2,3,5) c(1,6,6,6,3,5,4,4,2,3,5)[!duplicated(c(1,6,6,6,3,5,4,4,2,3,5))] [1] 1 6 3 5 4 2 x - c(1,6,6,6,3,5,4,4,2,3,5) x[!duplicated(x)] [1] 1 6 3 5 4 2 !duplicated(x) [1] TRUE TRUE FALSE FALSE TRUE TRUE TRUE FALSE TRUE FALSE FALSE which(!duplicated(x)) [1] 1 2 5 6 7 9 The 6 and 4 are repeated, I only want the index of the non-repeated values. I thought of using which() and unique(), but that does not give you the index of the unique values. Thanks in advance. Mike [[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. David Winsemius Alameda, CA, USA __ 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] How to delete repeated values in MCMC sampling and get index of unique values?
What answer is wanted for c(1,1,1,2,3,1) ? Note that Duncan's two suggestions below give different answers for this. -- Bert On Thu, Jan 17, 2013 at 1:59 PM, Duncan Murdoch murdoch.dun...@gmail.com wrote: On 13-01-17 4:50 PM, C W wrote: Dear list, How do you delete repeated samples? In MCMC, when your candidate value has been reject, so you remain on the same point, so you keep that value. Say I have this toy example, c(1,6,6,6,3,5,4,4,2,3,5) The 6 and 4 are repeated, I only want the index of the non-repeated values. I thought of using which() and unique(), but that does not give you the index of the unique values. You could use x[!duplicated(x)] or rle(x)$values, depending on your definition of repeated. I hope you're aware that you can't use either for things like quantiles and moments of the limiting distribution. x - c(1,6,6,6,3,5,4,4,2,3,5) x[!duplicated(x)] [1] 1 6 3 5 4 2 rle(x)$values [1] 1 6 3 5 4 2 3 5 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. -- 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] How to convert a string to the column it represents in a dataframe, with a reproducible example
Hi David, I would like to have two objects, one containing the values in a column and the other containing the column's name. Of course, that's easy to do manually, but I don't want to have to type out the name of the column more than once (thus, below, I have typed it once in quotes, and I am trying to find a programatic way to create the other object, without typing the column name again). Thank you for your help. Mark Na On Thu, Jan 17, 2013 at 4:06 PM, David Winsemius dwinsem...@comcast.netwrote: On Jan 17, 2013, at 1:36 PM, mtb...@gmail.com wrote: Hello R-helpers, I have run the following lines of code: x-cars$dist y-noquote(x) Now y is a string containing the characters cars$dist My questionis there an R function (or combination of functions) that I can apply to y that will cause y to contain the numbers in cars$dist? Even better, can I do it without using noquote()? What is the goal of this effort? -- David Winsemius Alameda, CA, USA [[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] How to delete repeated values in MCMC sampling and get index of unique values?
I was looking for the first answer. In MCMC, at time t, when the candidate sample is rejected, candidate_sample[t] - current_sample say, at time t+1, the sample is rejected AGAIN, we have candidate_sample[t+1] - current_sample so, at time t, and t+1, we have the same value. When I calculate the monte carlo mean, I don't want repeated value. Mike On Thu, Jan 17, 2013 at 5:20 PM, Bert Gunter gunter.ber...@gene.com wrote: What answer is wanted for c(1,1,1,2,3,1) ? Note that Duncan's two suggestions below give different answers for this. -- Bert On Thu, Jan 17, 2013 at 1:59 PM, Duncan Murdoch murdoch.dun...@gmail.com wrote: On 13-01-17 4:50 PM, C W wrote: Dear list, How do you delete repeated samples? In MCMC, when your candidate value has been reject, so you remain on the same point, so you keep that value. Say I have this toy example, c(1,6,6,6,3,5,4,4,2,3,5) The 6 and 4 are repeated, I only want the index of the non-repeated values. I thought of using which() and unique(), but that does not give you the index of the unique values. You could use x[!duplicated(x)] or rle(x)$values, depending on your definition of repeated. I hope you're aware that you can't use either for things like quantiles and moments of the limiting distribution. x - c(1,6,6,6,3,5,4,4,2,3,5) x[!duplicated(x)] [1] 1 6 3 5 4 2 rle(x)$values [1] 1 6 3 5 4 2 3 5 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. -- 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 [[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] How to convert a string to the column it represents in a dataframe, with a reproducible example
On Jan 17, 2013, at 2:26 PM, mtb...@gmail.com wrote: Hi David, I would like to have two objects, one containing the values in a column and the other containing the column's name. You have not addressed the question ... why? Where are you going with this? Of course, that's easy to do manually, but I don't want to have to type out the name of the column more than once (thus, below, I have typed it once in quotes, and I am trying to find a programatic way to create the other object, without typing the column name again). I would think that this is be best way to proceed: x - cars[ , dist, drop=FALSE] Now x is a data.frame (and inherits from the list-class) and names(x) will return dist and the usual access methods would work. -- David. Thank you for your help. Mark Na On Thu, Jan 17, 2013 at 4:06 PM, David Winsemius dwinsem...@comcast.net wrote: On Jan 17, 2013, at 1:36 PM, mtb...@gmail.com wrote: Hello R-helpers, I have run the following lines of code: x-cars$dist y-noquote(x) Now y is a string containing the characters cars$dist My questionis there an R function (or combination of functions) that I can apply to y that will cause y to contain the numbers in cars$dist? Even better, can I do it without using noquote()? What is the goal of this effort? -- David Winsemius Alameda, CA, USA David Winsemius Alameda, CA, USA __ 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] How to convert a string to the column it represents in a dataframe, with a reproducible example
Inline below. -- Bert On Thu, Jan 17, 2013 at 3:02 PM, David Winsemius dwinsem...@comcast.net wrote: On Jan 17, 2013, at 2:26 PM, mtb...@gmail.com wrote: Hi David, I would like to have two objects, one containing the values in a column and the other containing the column's name. You have not addressed the question ... why? Where are you going with this? Of course, that's easy to do manually, but I don't want to have to type out the name of the column more than once (thus, below, I have typed it once in quotes, and I am trying to find a programatic way to create the other object, without typing the column name again). I would think that this is be best way to proceed: x - cars[ , dist, drop=FALSE] Now x is a data.frame (and inherits from the list-class) and names(x) will return dist and the usual access methods would work. ... which, of course, begs the question: why bother. as you would do the same with the original data frame. -- Bert -- David. Thank you for your help. Mark Na On Thu, Jan 17, 2013 at 4:06 PM, David Winsemius dwinsem...@comcast.net wrote: On Jan 17, 2013, at 1:36 PM, mtb...@gmail.com wrote: Hello R-helpers, I have run the following lines of code: x-cars$dist y-noquote(x) Now y is a string containing the characters cars$dist My questionis there an R function (or combination of functions) that I can apply to y that will cause y to contain the numbers in cars$dist? Even better, can I do it without using noquote()? What is the goal of this effort? -- David Winsemius Alameda, CA, USA David Winsemius Alameda, CA, USA __ 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] How to delete repeated values in MCMC sampling and get index of unique values?
On 13-01-17 5:33 PM, C W wrote: I was looking for the first answer. In MCMC, at time t, when the candidate sample is rejected, candidate_sample[t] - current_sample say, at time t+1, the sample is rejected AGAIN, we have candidate_sample[t+1] - current_sample so, at time t, and t+1, we have the same value. When I calculate the monte carlo mean, I don't want repeated value. Then you will get the wrong answer, unless you want something very strange. Duncan Murdoch Mike On Thu, Jan 17, 2013 at 5:20 PM, Bert Gunter gunter.ber...@gene.com mailto:gunter.ber...@gene.com wrote: What answer is wanted for c(1,1,1,2,3,1) ? Note that Duncan's two suggestions below give different answers for this. -- Bert On Thu, Jan 17, 2013 at 1:59 PM, Duncan Murdoch murdoch.dun...@gmail.com mailto:murdoch.dun...@gmail.com wrote: On 13-01-17 4:50 PM, C W wrote: Dear list, How do you delete repeated samples? In MCMC, when your candidate value has been reject, so you remain on the same point, so you keep that value. Say I have this toy example, c(1,6,6,6,3,5,4,4,2,3,5) The 6 and 4 are repeated, I only want the index of the non-repeated values. I thought of using which() and unique(), but that does not give you the index of the unique values. You could use x[!duplicated(x)] or rle(x)$values, depending on your definition of repeated. I hope you're aware that you can't use either for things like quantiles and moments of the limiting distribution. x - c(1,6,6,6,3,5,4,4,2,3,5) x[!duplicated(x)] [1] 1 6 3 5 4 2 rle(x)$values [1] 1 6 3 5 4 2 3 5 Duncan Murdoch __ R-help@r-project.org mailto: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] How to convert a string to the column it represents in a dataframe, with a reproducible example
-Original Message- From: r-help-boun...@r-project.org [mailto:r-help-bounces@r- project.org] On Behalf Of mtb...@gmail.com Sent: Thursday, January 17, 2013 2:27 PM To: David Winsemius; r-help@r-project.org Subject: Re: [R] How to convert a string to the column it represents in a dataframe, with a reproducible example Hi David, I would like to have two objects, one containing the values in a column and the other containing the column's name. Of course, that's easy to do manually, but I don't want to have to type out the name of the column more than once (thus, below, I have typed it once in quotes, and I am trying to find a programatic way to create the other object, without typing the column name again). Thank you for your help. Mark Na Something like this eval(parse(text=y)) could be what you want. But even if it is, I am not sure it is what you should want. Without more context, it is hard to say. Hope this is at least somewhat helpful, Dan Daniel J. Nordlund Washington State Department of Social and Health Services Planning, Performance, and Accountability Research and Data Analysis Division Olympia, WA 98504-5204 __ 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] How can i keep only latest entries?
Quoting Mat matthias.we...@fnt.de: Hello togehter, i have a data.frame like this one: No. Date last change 1 1 2012-10-04 change settings 2 1 2012-10-20 bug fix 3 1 2012-11-05 final 4 2 2013-01-15new task 5 2 2013-01-16Bug fix 6 2 2013-01-17final Calling your data frame, x and assuming the `last change` column is character, x[x$`last change` == final,] will give what you want. If `last change` is a factor column (likely), x[as.character(x$`last change`) == final,] If you don't have spaces in your column names, you'd avoid using the backticks. HTH now i want a new data.frame, who show me only the newest entries according to the No. The solution look like this one: No. Datelast change 1 1 2012-11-05 final 2 2 2013-01-17 final can anyone help me? thanks. Mat -- View this message in context: http://r.789695.n4.nabble.com/How-can-i-keep-only-latest-entries-tp4655827.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] Sweave, Texshop, and sync with included Rnw file
Hi, I just updated R and patchDVI (from CRAN). Now I can reverse search from the pdf to the included.Rnw. However, I cannot forward search from the included to the pdf. Is this how it is expected to work? Forward and inverse search work between main Rnw and pdf. I am pasting below the code in the two files. % Sweavetest.Rnw \documentclass{article} \begin{document} \SweaveOpts{concordance=TRUE} \title{an Sweave inclusion test} \author{Michele} \maketitle This is an example for the inclusion of RNW files and forward-inverse search. following is a chunk of sweave code: = n - 5 for(i in 1:n){ print(i) } @ \section{text from an included file} \SweaveInput{included.Rnw} \end{document} % Included.Rnw % !Rnw root = Sweavetest.Rnw this is some text included in an Rnw file = for(i in 1:3){ print('included') } @ On Jan 11, 2013, at 5:38 AM, Duncan Murdoch wrote: On 13-01-10 4:54 PM, michele caseposta wrote: Hi everybody, thanks for the replies. I might have not explained the problem completely. Duncan Mackay: Yes, I am already having a master file and separate Rnw files. Duncan Murdock: I am using patchDVI in the TexShop Sweave engine. Sync works flawlessly between the master file and the pdf produced by pdflatex. My problem is that I don't seem to be able to obtain sync between the *included* Rnws and the pdf, either way. The sweave engine is as follows: #!/bin/bash R CMD Sweave $1 latexmk -pdf -silent -pdflatex=‘pdflatex –shell-escape –synctex=1′${1%.*} Rscript -e library(‘patchDVI’);patchSynctex(‘${1%.*}.synctex.gz’) Funny thing is that the sync works in texworks, using the following Rscript line patchDVI::SweavePDF('$fullname',stylepath=FALSE) I tried to mix and match configurations between texshop and texworks but I had no luck I just tried a simple example in TeXShop and it worked for me. My Sweave engine is #!/bin/tcsh # set path= ($path /usr/local/bin) Rscript -e patchDVI::SweavePDF( '$1' ) So it seems to be work listing versions: On the Mac, I'm using R 2.15.0 patched, rev 59478, with patchDVI version 1.8.1584 (I just uploaded 1.9 to CRAN, by the way), TeXShop version 2.43. It also works on Windows, where I have current releases of R and patchDVI installed. If you've got current versions of everything installed and it's still not working, could you try putting together a small reproducible example? Duncan Murdoch On Jan 10, 2013, at 11:23 AM, Duncan Murdoch wrote: On 13-01-09 9:09 PM, Duncan Murdoch wrote: On 13-01-09 3:25 PM, michele caseposta wrote: Hello everyone. I am in the process of writing a book in Latex with Texshop, on Mac. This book contains a lot of R code, hence the need to use Sweave. I was able to compile Rnw files, and to sync back and forth from the pdf to the source Rnw. My problem now is that the book is divided in Chapters, and every chapter is in its own Rnw file. I can compile them from the main one (book.Rnw) using the directive \SweaveInput{chapter1.Rnw} The problem stands in the fact that like this I am missing synchronization between the pdf and the source Rnw. If part of text is in book.Rnw I can synchronize, but if the text is in one of the included files, it just doesn't work. I am using the sweave engine found in the following webpage: http://cameron.bracken.bz/synctex-with-sweavepgfsweave-in-texshoptexworks Has anybody succeeded in synchronizing with included Rnw files? This is a problem addressed by my patchDVI package, available on R-forge. You have a main file (which can be .tex or .Rnw), and put code at the start of each .Rnw file to indicate where to find it. Then you just run Sweave on one of the chapters, and it automatically produces the full document. The sample document here: http://www.umanitoba.ca/statistics/seminars/2011/3/4/duncan-murdoch-using-sweave-R/ includes an appendix describing how to set this up with TeXShop. I just committed an update to the vignette in patchDVI giving a quick version of the instructions for basic use. Version 1.8.1585 has the new vignette. I should get around to pushing it to CRAN one of these days... 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.
Re: [R] Line breaks in documentation \useage
On 01/18/2013 12:33 AM, Markku Karhunen wrote: Hi again, R community. I wonder how you do line breaks in \useage{} section in .Rd files. I am sure there's some tutorial for this somewhere, but I just haven't found it. I have tried \\, \cr, \br and \newline, admittedly arbitrarily, but all of these produce warnings or errors. The \usage{} section appears to be treated verbatim or as if it were preformated. So just put the line break literally in your *.Rd and it will automagically appear in the resulting help. cheers, Rolf Turner __ 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] how to use ...
The help facility is applicable to functions and data sets. It is not designed or intended to give help with respect to R syntax (with the exception of the basic syntax of the operators --- unary and binary --- and the associated rules of precedence). cheers, Rolf Turner On 01/18/2013 09:17 AM, Steve Taylor wrote: The ellipsis object is not listed in the base help pages! help(`+`) # this works - help on arithmetic operators help(+) # also works help(`...`) # fails with Error: '...' used in an incorrect context help(...) # fails also with No documentation for '...' in specified packages and libraries: you could try '??...' -Original Message- From: r-help-boun...@r-project.org [mailto:r-help-boun...@r-project.org] On Behalf Of Ivan Calandra Sent: Friday, 18 January 2013 4:43a To: R. Michael Weylandt Cc: R list Subject: Re: [R] how to use ... Do you know where I can find some documentation about 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] powerTransform Warning Message
Hello, I would like to perform a Box-Cox (âbcPowerâ) transformation on my data. For this, I am determining lambda using the âpowerTransformâ function. However, with one of my variables I get the following Warning Message: In estimateTransform(x, y, NULL, ...) : Convergence failure: return code = 52 My variable is: x [1] 0.0001031130 0.0001029480 0.0001040010 0.0001037940 0.0001046280 0.927650 0.942960 [8] 0.950250 0.949780 0.988210 0.975860 0.962850 0.0001015800 0.0001009190 [15] 0.0001035350 0.0001033210 0.0001028420 0.0001023150 0.0001033000 0.0001036910 0.0001026890 [22] 0.0001032480 0.0001012160 0.0001031270 0.0001034390 0.0001028180 0.0001034820 0.0001022700 [29] 0.0001042640 0.0001046720 0.0001045860 0.0001045160 0.0001045850 0.0001038040 0.0001037020 [36] 0.0001034050 0.0001048150 0.0001017180 0.0001017920 0.0001032730 0.0001029420 0.0001025220 [43] 0.0001031490 0.0001036995 0.0001039735 0.0001014877 0.0001027960 And my code is:dlambda - powerTransform(x) #It is here where I get the warning message x_BCx - bcPower(x, lambda= dlambda$lambda, jacobian.adjusted= FALSE) Does anyone have an idea of why I could be getting this Warning Message? If you require more details please get in touch. Thanks a lot! Bea [[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] Sweave, Texshop, and sync with included Rnw file
Anybody know if it is possible to use texshop and knitr with the sync working? I add a knitr engine but cannot sync. PS, I am comfortable with texshop but not RStudio. Huang On Fri, Jan 18, 2013 at 7:33 AM, michele caseposta mic.c...@gmail.comwrote: Hi, I just updated R and patchDVI (from CRAN). Now I can reverse search from the pdf to the included.Rnw. However, I cannot forward search from the included to the pdf. Is this how it is expected to work? Forward and inverse search work between main Rnw and pdf. I am pasting below the code in the two files. % Sweavetest.Rnw \documentclass{article} \begin{document} \SweaveOpts{concordance=TRUE} \title{an Sweave inclusion test} \author{Michele} \maketitle This is an example for the inclusion of RNW files and forward-inverse search. following is a chunk of sweave code: = n - 5 for(i in 1:n){ print(i) } @ \section{text from an included file} \SweaveInput{included.Rnw} \end{document} % Included.Rnw % !Rnw root = Sweavetest.Rnw this is some text included in an Rnw file = for(i in 1:3){ print('included') } @ On Jan 11, 2013, at 5:38 AM, Duncan Murdoch wrote: On 13-01-10 4:54 PM, michele caseposta wrote: Hi everybody, thanks for the replies. I might have not explained the problem completely. Duncan Mackay: Yes, I am already having a master file and separate Rnw files. Duncan Murdock: I am using patchDVI in the TexShop Sweave engine. Sync works flawlessly between the master file and the pdf produced by pdflatex. My problem is that I don't seem to be able to obtain sync between the *included* Rnws and the pdf, either way. The sweave engine is as follows: #!/bin/bash R CMD Sweave $1 latexmk -pdf -silent -pdflatex=âpdflatex âshell-escape âsynctex=1â²${1%.*} Rscript -e library(âpatchDVIâ);patchSynctex(â${1%.*}.synctex.gzâ) Funny thing is that the sync works in texworks, using the following Rscript line patchDVI::SweavePDF('$fullname',stylepath=FALSE) I tried to mix and match configurations between texshop and texworks but I had no luck I just tried a simple example in TeXShop and it worked for me. My Sweave engine is #!/bin/tcsh # set path= ($path /usr/local/bin) Rscript -e patchDVI::SweavePDF( '$1' ) So it seems to be work listing versions: On the Mac, I'm using R 2.15.0 patched, rev 59478, with patchDVI version 1.8.1584 (I just uploaded 1.9 to CRAN, by the way), TeXShop version 2.43. It also works on Windows, where I have current releases of R and patchDVI installed. If you've got current versions of everything installed and it's still not working, could you try putting together a small reproducible example? Duncan Murdoch On Jan 10, 2013, at 11:23 AM, Duncan Murdoch wrote: On 13-01-09 9:09 PM, Duncan Murdoch wrote: On 13-01-09 3:25 PM, michele caseposta wrote: Hello everyone. I am in the process of writing a book in Latex with Texshop, on Mac. This book contains a lot of R code, hence the need to use Sweave. I was able to compile Rnw files, and to sync back and forth from the pdf to the source Rnw. My problem now is that the book is divided in Chapters, and every chapter is in its own Rnw file. I can compile them from the main one (book.Rnw) using the directive \SweaveInput{chapter1.Rnw} The problem stands in the fact that like this I am missing synchronization between the pdf and the source Rnw. If part of text is in book.Rnw I can synchronize, but if the text is in one of the included files, it just doesn't work. I am using the sweave engine found in the following webpage: http://cameron.bracken.bz/synctex-with-sweavepgfsweave-in-texshoptexworks Has anybody succeeded in synchronizing with included Rnw files? This is a problem addressed by my patchDVI package, available on R-forge. You have a main file (which can be .tex or .Rnw), and put code at the start of each .Rnw file to indicate where to find it. Then you just run Sweave on one of the chapters, and it automatically produces the full document. The sample document here: http://www.umanitoba.ca/statistics/seminars/2011/3/4/duncan-murdoch-using-sweave-R/ includes an appendix describing how to set this up with TeXShop. I just committed an update to the vignette in patchDVI giving a quick version of the instructions for basic use. Version 1.8.1585 has the new vignette. I should get around to pushing it to CRAN one of these days... 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. [[alternative HTML version deleted]]
Re: [R] Sweave, Texshop, and sync with included Rnw file
Sweave produces foo-concordance.tex from foo.Rnw, and writes \input{foo-concordance.tex} in the LaTeX output. You can turn on the concordance option in knitr as well. Since you do not use RStudio, you have a couple of more steps to go: 1. borrow \Sconcordance from Sweave.sty; 2. manually \input{foo-concordance.tex}; 3. set the option concordance=TRUE in opts_knit; The rest of steps are the same as Sweave -- you compile the output by `pdflatex --synctex=1 foo.tex`, and run patchDVI on the results. I do not use TeXShop, so I'm not sure if it really works. \documentclass{article} % from Sweave.sty in R \newcommand{\Sconcordance}[1]{% \ifx\pdfoutput\undefined% \csname newcount\endcsname\pdfoutput\fi% \ifcase\pdfoutput\special{#1}% \else% \begingroup% \pdfcompresslevel=0% \immediate\pdfobj stream{#1}% \pdfcatalog{/SweaveConcordance \the\pdflastobj\space 0 R}% \endgroup% \fi} \input{foo-concordance.tex} setup, include=FALSE= opts_knit$set(concordance=TRUE) @ \begin{document} = for (i in 1:5) { print(i) } @ \end{document} Regards, Yihui -- Yihui Xie xieyi...@gmail.com Phone: 515-294-2465 Web: http://yihui.name Department of Statistics, Iowa State University 2215 Snedecor Hall, Ames, IA On Thu, Jan 17, 2013 at 7:45 PM, huang min minhua...@gmail.com wrote: Anybody know if it is possible to use texshop and knitr with the sync working? I add a knitr engine but cannot sync. PS, I am comfortable with texshop but not RStudio. Huang On Fri, Jan 18, 2013 at 7:33 AM, michele caseposta mic.c...@gmail.comwrote: Hi, I just updated R and patchDVI (from CRAN). Now I can reverse search from the pdf to the included.Rnw. However, I cannot forward search from the included to the pdf. Is this how it is expected to work? Forward and inverse search work between main Rnw and pdf. I am pasting below the code in the two files. % Sweavetest.Rnw \documentclass{article} \begin{document} \SweaveOpts{concordance=TRUE} \title{an Sweave inclusion test} \author{Michele} \maketitle This is an example for the inclusion of RNW files and forward-inverse search. following is a chunk of sweave code: = n - 5 for(i in 1:n){ print(i) } @ \section{text from an included file} \SweaveInput{included.Rnw} \end{document} % Included.Rnw % !Rnw root = Sweavetest.Rnw this is some text included in an Rnw file = for(i in 1:3){ print('included') } @ On Jan 11, 2013, at 5:38 AM, Duncan Murdoch wrote: On 13-01-10 4:54 PM, michele caseposta wrote: Hi everybody, thanks for the replies. I might have not explained the problem completely. Duncan Mackay: Yes, I am already having a master file and separate Rnw files. Duncan Murdock: I am using patchDVI in the TexShop Sweave engine. Sync works flawlessly between the master file and the pdf produced by pdflatex. My problem is that I don't seem to be able to obtain sync between the *included* Rnws and the pdf, either way. The sweave engine is as follows: #!/bin/bash R CMD Sweave $1 latexmk -pdf -silent -pdflatex=‘pdflatex –shell-escape –synctex=1′${1%.*} Rscript -e library(‘patchDVI’);patchSynctex(‘${1%.*}.synctex.gz’) Funny thing is that the sync works in texworks, using the following Rscript line patchDVI::SweavePDF('$fullname',stylepath=FALSE) I tried to mix and match configurations between texshop and texworks but I had no luck I just tried a simple example in TeXShop and it worked for me. My Sweave engine is #!/bin/tcsh # set path= ($path /usr/local/bin) Rscript -e patchDVI::SweavePDF( '$1' ) So it seems to be work listing versions: On the Mac, I'm using R 2.15.0 patched, rev 59478, with patchDVI version 1.8.1584 (I just uploaded 1.9 to CRAN, by the way), TeXShop version 2.43. It also works on Windows, where I have current releases of R and patchDVI installed. If you've got current versions of everything installed and it's still not working, could you try putting together a small reproducible example? Duncan Murdoch On Jan 10, 2013, at 11:23 AM, Duncan Murdoch wrote: On 13-01-09 9:09 PM, Duncan Murdoch wrote: On 13-01-09 3:25 PM, michele caseposta wrote: Hello everyone. I am in the process of writing a book in Latex with Texshop, on Mac. This book contains a lot of R code, hence the need to use Sweave. I was able to compile Rnw files, and to sync back and forth from the pdf to the source Rnw. My problem now is that the book is divided in Chapters, and every chapter is in its own Rnw file. I can compile them from the main one (book.Rnw) using the directive \SweaveInput{chapter1.Rnw} The problem stands in the fact that like this I am missing synchronization between the pdf and the source Rnw. If part of text is in book.Rnw I can synchronize, but if the text is in one of the included files, it just doesn't work. I am using the sweave
Re: [R] Colors in interaction plots
But I don't want to plot random colors. ... That's why I have this vector with length 24 - each one matches one line in the npk dataset. ... which is not what interaction.plot, or matplot, needs; it needs one per line on the plot. How can I inform to the interaction.plot function the color corresponding to the block it will plot? You need a colour vector the same length as the number of levels you're plotting. One easy way to do that would be to do something like col=1:nlevels(fac), for example as in interaction.plot(npk$N, npk$block, fit, xlab=N, ylab=yield,col=1:nlevels(fac)) If you have several levels that correspond to the same level of a third factor, you need to provide a cross-reference of sorts. In your toy example, fac corresponds to three levels of block, so one could specify manually. One way of doing it in code, though, could be to use table to identify levels of fac corresponding to levels of block. That sounds a bit complicated, but let's see: npk$fac - fac #just so it's in the same data frame fac.by.block - with(npk, table(fac, block)) #cross-reference fac levels by block fac.index.by.block.level - apply(fac.by.block, 2, function(x) which(x0)[1]) #Assumes that you want the first nonzero table entry and that numerical indices are OK # you could also use which directly: which(fac.by.block 1, arr.ind=TRUE)[,1] gives the same result IF there's a 1:1 fac:block matching Then interaction.plot(npk$N, npk$block, fit, xlab=N, ylab=yield,col=(1:nlevels(fac))[fac.index.by.block.level]) ... which I think is something like what you;re after? S *** This email and any attachments are confidential. Any use...{{dropped:8}} __ 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] Using table to get frequencies of several factors at once
The tables package may be of use to you for this. On Fri, Jan 11, 2013 at 4:17 AM, Pancho Mulongeni p.mulong...@namibia.pharmaccess.org wrote: Hi, I have a dataframe with n columns, but I am only looking at five of them. And lots of rows, over 700. So I would like to find frequencies for each of the numeric columns (variables) using the table function. However, is there a fast way to produce a frequency table where the 5 rows represent the 5 numeric variables and the columns refer to the values (levels) of the respective numeric variables, which in this case are 0 and 1. The only way I have figured it out is via a for loop: m-seq(218,222,1) #these are columns of the variables in the larger dataframe tm-m[1:5] #I need this for the for loop l.tm-length(tm) B-matrix(nrow=l.tm,ncol=2) #the matrix to hold the freqs for (p in 1:l.tm) { var.num-m[p] B[p,]-table(DATA[,var.num]) } B [,1] [,2] [1,] 6979 [2,] 512 194 [3,] 604 102 [4,] 7006 [5,] 706 706 So the rows represent my five variables (columns) that occupy columns 218 through 222 in the DATA dataframe. So the second column represents my frequencies of the value 1, which is what I am interested in. The last row has a double entry, because there was only one value, 0, with a freq of 706 and so R duplicated in the two columns, but that's ok, I can just ignore it. So is there are better way to do this? Is there a way to use the so called tapply function? I struggle to understand the help doc for this.function. Pancho Mulongeni Research Assistant PharmAccess Foundation 1 Fouché Street Windhoek West Windhoek Namibia Tel: +264 61 419 000 Fax: +264 61 419 001/2 Mob: +264 81 4456 286 __ 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. -- Gregory (Greg) L. Snow Ph.D. 538...@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.
Re: [R] how to use ...
Rolf Perhaps the philosophy of the help system needs to change . . . John Sent from my iPhone On Jan 17, 2013, at 7:11 PM, Rolf Turner rolf.tur...@xtra.co.nz rolf.tur...@xtra.co.nz wrote: The help facility is applicable to functions and data sets. It is not designed or intended to give help with respect to R syntax (with the exception of the basic syntax of the operators --- unary and binary --- and the associated rules of precedence). cheers, Rolf Turner On 01/18/2013 09:17 AM, Steve Taylor wrote: The ellipsis object is not listed in the base help pages! help(`+`) # this works - help on arithmetic operators help(+) # also works help(`...`) # fails with Error: '...' used in an incorrect context help(...) # fails also with No documentation for '...' in specified packages and libraries: you could try '??...' -Original Message- From: r-help-boun...@r-project.org [mailto:r-help-boun...@r-project.org] On Behalf Of Ivan Calandra Sent: Friday, 18 January 2013 4:43a To: R. Michael Weylandt Cc: R list Subject: =?utf-8?B?UmU6IFtSXSBob3cgdG8gdXNlICIuLi4i==? Do you know where I can find some documentation about 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. Confidentiality Statement: This email message, including any attachments, is for th...{{dropped:6}} __ 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] how to use ...
On Jan 17, 2013, at 7:00 PM, John Sorkin wrote: Rolf Perhaps the philosophy of the help system needs to change . . . John It's probably unwise to accept any one person's claim regarding the philosophy of the help system. If you have the time, energy and skills to construct a help page for ... then I would inquire on the r-devel mailing list whether such a submission would be considered. After looking at the help page for + I think it needs at the very least a reference to both the ?formula page (since that is a core part of hte language) and alos suggest it should describe the overloadings of + in the lattice and ggplot2 packages. I think it's too much to expect users to know that is an S4 generic implies a wide variety of potential meanings. I think those oft-used examples of such meanings ought to be mentioned. -- David. Sent from my iPhone On Jan 17, 2013, at 7:11 PM, Rolf Turner rolf.tur...@xtra.co.nz rolf.tur...@xtra.co.nz wrote: The help facility is applicable to functions and data sets. It is not designed or intended to give help with respect to R syntax (with the exception of the basic syntax of the operators --- unary and binary --- and the associated rules of precedence). cheers, Rolf Turner On 01/18/2013 09:17 AM, Steve Taylor wrote: The ellipsis object is not listed in the base help pages! help(`+`) # this works - help on arithmetic operators help(+) # also works help(`...`) # fails with Error: '...' used in an incorrect context help(...) # fails also with No documentation for '...' in specified packages and libraries: you could try '??...' -Original Message- From: r-help-boun...@r-project.org [mailto:r-help-boun...@r-project.org ] On Behalf Of Ivan Calandra Sent: Friday, 18 January 2013 4:43a To: R. Michael Weylandt Cc: R list Subject: =?utf-8?B?UmU6IFtSXSBob3cgdG8gdXNlICIuLi4i==? Do you know where I can find some documentation about 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. Confidentiality Statement: This email message, including any attachments, is for th...{{dropped: 6}} __ 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. David Winsemius, MD Alameda, CA, USA __ 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] Getting discrete colors on plot
On 01/18/2013 04:02 AM, Mary wrote: Hi, This is my first post; I'm new to R but am a senior statistical programmer. I have done a lot of graphs using SAS Graph but now am trying to transition to using graphs in R. I'm trying to produce a graph where the colors have three categories- ideally I would like them to be Green for good, Yellow for Questionable, and Red for bad. So I tried to do this in GGPLOT; here is my code: id- c(1,2,3,4,5) x1- c(5,2,3,5,1) x2- c(4,1,3,5,1) x3- c(5,2,3,5,1) x4- c(4,3,3,5,1) x5- c(3,1,3,5,1) colorvar- c(3,1,2,3,1) mydata- data.frame(id,x1,x2,x3,x4,x5,colorvar) head(mydata) # convert to long format require(reshape) mydata_long- melt(mydata, id=c(id, colorvar)) head(mydata_long) require(ggplot2) p- ggplot(data=mydata_long, aes(x=variable, y=value, group=id, colour = colorvar)) + geom_line() p This works, but I get more colors on the graph than my colorvar has. I have 3 colors on my colorvar, but 5 colors show up on the graph, including 1.5 and 2.5. How do I tell ggplot only to use the 3 colors and not give me a gradient of colors? Also how would I specify the colors that I want, such as the RGB equivalents of green, yellow, and red? My real data will have many more records. -Mary Hi Mary, I'm not exactly sure what you are doing with the melt function, but does: matplot(mydata$id,mydata[,2:6],col=mydata$colorvar+1,type=l) give you something like what you want? 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] reading multiple key=value pairs per line
Hi, Thanks for a great environmentfor statistical computing :-) I have some input data in a file (input_kvpairs.csv) of the form key1=23, key2=67, key3=hello there key1=7, key2=22, key3=how are you key1=2, key2=77, key3=nice day, thanks Now in my head I wish it was of the form (input.csv) #key1, key2, key3 23,67, hello there 7, 22, how are you 2, 77, nice day, thanks so I could do data - read.csv(input.csv, header=TRUE) where the header column names are derived from the key names dynamically, and I could access the data using normal data$key1 or data$key2 mechanism. I guess I could just pre process the file first using python etc to create a CSV file with column header derived from key names, and values derived from key values, but I am interested to see how experienced R folks would handle this inside R. Thanks, Frank __ 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] Getting discrete colors on plot
HI, May be this helps: mydata_long1-within(mydata_long,{colorvar-factor(colorvar,levels=1:3)}) require(ggplot2) p - ggplot(data=mydata_long1, aes(x=variable, y=value, group=id, colour = colorvar)) + geom_line() p A.K. - Original Message - From: Mary mlhow...@avalon.net To: r-help@r-project.org Cc: Sent: Thursday, January 17, 2013 12:02 PM Subject: Re: [R] Getting discrete colors on plot Hi, This is my first post; I'm new to R but am a senior statistical programmer. I have done a lot of graphs using SAS Graph but now am trying to transition to using graphs in R. I'm trying to produce a graph where the colors have three categories- ideally I would like them to be Green for good, Yellow for Questionable, and Red for bad. So I tried to do this in GGPLOT; here is my code: id - c(1,2,3,4,5) x1 - c(5,2,3,5,1) x2 - c(4,1,3,5,1) x3 - c(5,2,3,5,1) x4 - c(4,3,3,5,1) x5 - c(3,1,3,5,1) colorvar - c(3,1,2,3,1) mydata - data.frame(id,x1,x2,x3,x4,x5,colorvar) head(mydata) # convert to long format require(reshape) mydata_long - melt(mydata, id=c(id, colorvar)) head(mydata_long) require(ggplot2) p - ggplot(data=mydata_long, aes(x=variable, y=value, group=id, colour = colorvar)) + geom_line() p This works, but I get more colors on the graph than my colorvar has. I have 3 colors on my colorvar, but 5 colors show up on the graph, including 1.5 and 2.5. How do I tell ggplot only to use the 3 colors and not give me a gradient of colors? Also how would I specify the colors that I want, such as the RGB equivalents of green, yellow, and red? My real data will have many more records. -Mary __ 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] Getting discrete colors on plot
Hi -Original Message- From: r-help-boun...@r-project.org [mailto:r-help-bounces@r- project.org] On Behalf Of Mary Sent: Thursday, January 17, 2013 6:02 PM To: r-help@r-project.org Subject: Re: [R] Getting discrete colors on plot Hi, This is my first post; I'm new to R but am a senior statistical programmer. I have done a lot of graphs using SAS Graph but now am trying to transition to using graphs in R. I'm trying to produce a graph where the colors have three categories- ideally I would like them to be Green for good, Yellow for Questionable, and Red for bad. So I tried to do this in GGPLOT; here is my code: id - c(1,2,3,4,5) x1 - c(5,2,3,5,1) x2 - c(4,1,3,5,1) x3 - c(5,2,3,5,1) x4 - c(4,3,3,5,1) x5 - c(3,1,3,5,1) colorvar - c(3,1,2,3,1) mydata - data.frame(id,x1,x2,x3,x4,x5,colorvar) head(mydata) # convert to long format require(reshape) mydata_long - melt(mydata, id=c(id, colorvar)) head(mydata_long) require(ggplot2) p - ggplot(data=mydata_long, aes(x=variable, y=value, group=id, colour = colorvar)) + geom_line() p This works, but I get more colors on the graph than my colorvar has. I have 3 colors on my colorvar, but 5 colors show up on the graph, including 1.5 and 2.5. How do I tell ggplot only to use the 3 colors and not give me a gradient of colors? Also how would I specify the colors that I want, such as the RGB equivalents of green, yellow, and red? My real data will have many more records. Learn to use factors. str(mydata) 'data.frame': 5 obs. of 7 variables: $ id : num 1 2 3 4 5 $ x1 : num 5 2 3 5 1 $ x2 : num 4 1 3 5 1 $ x3 : num 5 2 3 5 1 $ x4 : num 4 3 3 5 1 $ x5 : num 3 1 3 5 1 $ colorvar: num 3 1 2 3 1 Your colorvar is numeric therefore the scale. If you want to make it discrete change it to factor. mydata_long$colorvar-factor(mydata_long$colorvar) and use your function to see the difference. Regards Petr -Mary __ 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 multiple key=value pairs per line
Maybe you can use ',=' as separators. ( I don't have R to check). Otherwise, I would clean the file with an editor or tool like 'sed' to replace the regular expression /key[0-9]=/ by nothing. On Jan 18, 2013 8:05 AM, Frank Singleton b17fly...@gmail.com wrote: Hi, Thanks for a great environmentfor statistical computing :-) I have some input data in a file (input_kvpairs.csv) of the form key1=23, key2=67, key3=hello there key1=7, key2=22, key3=how are you key1=2, key2=77, key3=nice day, thanks Now in my head I wish it was of the form (input.csv) #key1, key2, key3 23,67, hello there 7, 22, how are you 2, 77, nice day, thanks so I could do data - read.csv(input.csv, header=TRUE) where the header column names are derived from the key names dynamically, and I could access the data using normal data$key1 or data$key2 mechanism. I guess I could just pre process the file first using python etc to create a CSV file with column header derived from key names, and values derived from key values, but I am interested to see how experienced R folks would handle this inside R. Thanks, Frank __** 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.html 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.