[R] A question about call()
The question is as below: Exercises 1.The following two calls look the same, but are actually different: (a - call(mean, 1:10)) # mean(1:10) (b - call(mean, quote(1:10))) # mean(1:10) identical(a, b) # [1] FALSE What¡¯s the difference? Which one should you prefer? So, how i can figure out this question? [[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] Problems with Installing RMySQL Package (Windows, R: 3.1.0 (64 bit), using RStudio)
Hi all, I'm trying to install the RMySQL package; I'm working on a Windows 64-bit machine with version 3.1.0 installed in R. I've tried two different methods of installing this software: through RStudio and through good old Command Prompt. Additionally, I have Cygwin installed and have gotten this installation to work through Cygwin, but am still trying to install this package under my Windows installation of R so that I can use RStudio. Also, I have installed the most recent of Rtools, but did not include the Cygwin DLLs (as I have Cygwin installed). I first tried installing RMySQL through RStudio. I have the MYSQL_HOME variable correctly set in my Renviron.site file. I then tried entering install.packages(RMySQL, type = source) on the RStudio prompt. The following is output from that command: install.packages(RMySQL, type = source)Installing package into âC:/Users/Ashutosh/Documents/R/win-library/3.1â (as âlibâ is unspecified)trying URL 'http://cran.rstudio.com/src/contrib/RMySQL_0.9-3.tar.gz'Content type 'application/x-gzip' length 165363 bytes (161 Kb)opened URLdownloaded 161 Kb --- Output coming from .Rprofile in ~ directory --- Welcome at Wed Jul 23 23:35:18 2014 Set JAVA_HOME environment variable to empty (for rJava purposes) Firstly, don't call your matrix 'matrix'. Would you call your dog 'dog'? Anyway, it might clash with the function 'matrix'. -- Barry Rowlingson R-help (October 2004) * installing *source* package 'RMySQL' ... ** package 'RMySQL' successfully unpacked and MD5 sums checked checking for $MYSQL_HOME... C:/MySQL_5.6 test: Output: unknown operand Warning: running command 'sh ./configure.win' had status 127 ERROR: configuration failed for package 'RMySQL' * removing 'C:/Users/Ashutosh/Documents/R/win-library/3.1/RMySQL' Warning in install.packages : running command 'C:/PROGRA~1/R/R-31~1.0/bin/x64/R CMD INSTALL -l C:\Users\Ashutosh\Documents\R\win-library\3.1 C:\Users\Ashutosh\AppData\Local\Temp\Rtmp0CV6RO/downloaded_packages/RMySQL_0.9-3.tar.gz' had status 1 Warning in install.packages : installation of package âRMySQLâ had non-zero exit status The downloaded source packages are in âC:\Users\Ashutosh\AppData\Local\Temp\Rtmp0CV6RO\downloaded_packagesâ Something seems to be up with the configure.win file but I cannot modify it as the MD5 sums won't check out. If there is something I can do so that the test command actually works, please let me know, and maybe this installation option will work!! I then tried running that exact command in Command Prompt (in Administrator mode) to see if I could get more information. To my surprise, it seemed to install the entire package successfully. Here is output corresponding to the command: C:\Users\Ashutosh\Documents\R Packages (Manually Installed)C:\Program Files\R\ R-3.1.0\bin\x64\R CMD INSTALL RMySQL_0.9-3.tar.gz --- Output coming from .Rprofile in ~ directory --- Welcome at Wed Jul 23 23:57:32 2014 Set JAVA_HOME environment variable to empty (for rJava purposes) Uwe Ligges: Please stop sending unsensible bug reports! Those have to be handled manually in the bug repository! Barry Rowlingson: Really? They seem to be being handled automatically and frighteningly well by the Uwe-bot at the moment. Congratulations, you've passed the Turing Test. -- Uwe Ligges and Barry Rowlingson (after several nonsensical mails to R-bugs) R-devel (July 2004) * installing to library 'C:/Users/Ashutosh/Documents/R/win-library/3.1' * installing *source* package 'RMySQL' ... ** package 'RMySQL' successfully unpacked and MD5 sums checked checking for $MYSQL_HOME... C:/MySQL_5.6 ./configure.win: line 16: test: too many arguments ** libs Warning: this package has a non-empty 'configure.win' file, so building only the main architecture gcc -m64 -IC:/PROGRA~1/R/R-31~1.0/include -DNDEBUG -IC:/MySQL_5.6/include -Id:/RCompile/CRANpkg/extralibs64/local/include -O2 -Wall -std=gnu99 -mt une=core2 -c RS-DBI.c -o RS-DBI.o RS-DBI.c: In function 'RS_DBI_makeSQLNames': RS-DBI.c:1197:7: warning: array subscript has type 'char' [-Wchar-subscripts] if(!isalpha(c) c!='') *name = 'X'; ^ RS-DBI.c: In function 'RS_na_set': RS-DBI.c:1219:11: warning: variable 'c' set but not used [-Wunused-but-set-varia ble] char *c; ^ gcc -m64 -IC:/PROGRA~1/R/R-31~1.0/include -DNDEBUG -IC:/MySQL_5.6/include -Id:/RCompile/CRANpkg/extralibs64/local/include -O2 -Wall -std=gnu99 -mt une=core2 -c RS-MySQL.c -o RS-MySQL.o RS-MySQL.c: In function 'RS_MySQL_fetch': RS-MySQL.c:657:13: warning: variable 'fld_nullOk' set but not used [-Wunused-but -set-variable] Sint *fld_nullOk, completed; ^ RS-MySQL.c: In function 'RS_DBI_invokeBeginGroup': RS-MySQL.c:1137:30: warning: variable 'val' set but not used [-Wunused-but-set-v ariable] s_object *s_group_name, *val; ^ RS-MySQL.c: In function 'RS_DBI_invokeNewRecord': RS-MySQL.c:1158:20: warning: variable 'val'
[R] A question about call()
The question is as below: Exercises 1.The following two calls look the same, but are actually different: (a - call(mean, 1:10)) # mean(1:10) (b - call(mean, quote(1:10))) # mean(1:10) identical(a, b) # [1] FALSE What¡¯s the difference? Which one should you prefer? So, how i can figure out this question? [[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] Cairo package error: unable to load...
I presume this about the CRAN binary packages for R and Cairo (from CRAN, not BioC), in which case you should have asked on R-sig-mac. But the likely answer is that you forgot to install X11 via XQuartz. See the 'R Installation and Administration Manual', and if you need more help, use R-sig-mac. On 24/07/2014 02:25, Leonardo Gama wrote: Hi! I've just installed R on my OS X 10.9 and was trying to make arrayQualityMetrics package work. I've installed it via the biocLite Bioconductor script, and everything was apparently fine. But when I tried to load the package, I've got an issue with the Cairo package... Then I tried to load only Cairo: library(Cairo) Error : .onLoad failed in loadNamespace() for 'Cairo', details: call: dyn.load(file, DLLpath = DLLpath, ...) error: unable to load shared object '/Library/Frameworks/R.framework/Versions/3.1/Resources/library/Cairo/libs/Cairo.so': dlopen(/Library/Frameworks/R.framework/Versions/3.1/Resources/library/Cairo/libs/Cairo.so, 6): Library not loaded: /opt/X11/lib/libXrender.1.dylib Referenced from: /Library/Frameworks/R.framework/Versions/3.1/Resources/library/Cairo/libs/Cairo.so Reason: image not found Error: package or namespace load failed for 'Cairo' traceback() 2: stop(gettextf(package or namespace load failed for %s, sQuote(package)), call. = FALSE, domain = NA) 1: library(Cairo) Verified it version and dependencies: packageDescription(Cairo) Package: Cairo Version: 1.5-6 Title: [...] Author: Simon Urbanek simon.urba...@r-project.org, Jeffrey Horner jeff.hor...@vanderbilt.edu Maintainer: Simon Urbanek simon.urba...@r-project.org Depends: R (= 2.4.0) Suggests: png Enhances: FastRWeb Description: [...] SystemRequirements: cairo (= 1.2 http://www.cairographics.org/) URL: http://www.rforge.net/Cairo/ Packaged: 2014-06-26 14:50:25 UTC; svnuser NeedsCompilation: yes Repository: CRAN Date/Publication: 2014-06-26 17:15:22 Built: R 3.1.0; x86_64-apple-darwin13.1.0; 2014-06-27 05:04:27 UTC; unix -- File: /Library/Frameworks/R.framework/Versions/3.1/Resources/library/Cairo/Meta/package.rds Tried to update it and got another error/warning: upgrade.packages(Cairo) Warning message: In doTryCatch(return(expr), name, parentenv, handler) : unable to load shared object '/Library/Frameworks/R.framework/Resources/modules//R_X11.so': dlopen(/Library/Frameworks/R.framework/Resources/modules//R_X11.so, 6): Library not loaded: /opt/X11/lib/libSM.6.dylib Referenced from: /Library/Frameworks/R.framework/Resources/modules//R_X11.so Reason: image not found traceback() No traceback available And finally: sessionInfo() R version 3.1.1 (2014-07-10) Platform: x86_64-apple-darwin13.1.0 (64-bit) locale: [1] C/UTF-8/C/C/C/C attached base packages: [1] stats graphics grDevices utils datasets methods base loaded via a namespace (and not attached): [1] tools_3.1.1 pack packBits packageEvent packageSlot packageStatus package.skeleton packageHasNamespacepackageSlot- packageVersion packageDescription packageNamepackageStartupMessage package_version I've also verified the cairo.os file cited in the first error message, and it was there: $ file /Library/Frameworks/R.framework/Versions/3.1/Resources/library/Cairo/libs/Cairo.so /Library/Frameworks/R.framework/Versions/3.1/Resources/library/Cairo/libs/Cairo.so: Mach-O 64-bit dynamically linked shared library x86_64 $ ls -lh /Library/Frameworks/R.framework/Versions/3.1/Resources/library/Cairo/libs/Cairo.so -rwxrwxr-x 1 root admin 3.2M Jun 27 02:04 /Library/Frameworks/R.framework/Versions/3.1/Resources/library/Cairo/libs/Cairo.so I have no idea of what's going wrong. Somebody could help me? Thank you, and sorry for the bad English. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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] A question about call()
Please read the Posting Guide. There is a no HTML policy and a no homework policy. --- 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. On July 23, 2014 11:40:09 PM PDT, super desolato...@163.com wrote: The question is as below: Exercises 1.The following two calls look the same, but are actually different: (a - call(mean, 1:10)) # mean(1:10) (b - call(mean, quote(1:10))) # mean(1:10) identical(a, b) # [1] FALSE What��s the difference? Which one should you prefer? So, how i can figure out this question? [[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] MCMCglmm question
Hi list members, I'm doing some analysis about differences in behaviours between rural and urban birds and, after reading and searching in different sources, I have a lot of doubts about how I'm performing them. I would greatly appreciate any feedback from you. Here are my questions, models and results: Background I performed some behavioural test on individuals belonging to the same territory (breeding birds), some of them located in rural areas and others in urban ones. I have 7 variables describing different behaviours in 178 breeding birds, most of them sharing territories as they are mates. Some of these variables should be considered as censored data. My main questions are: 1) which is the relationship between these behaviours and 2) whether urban birds differ in these behaviours (means) and/or in the strength of their relationships compare with rural ones. ## MODELS AND RESULTS QUESTION 1) which is the relationship between the behaviours measured: prior = list(R = list(V = diag(7), nu = 8), G = list(G1 = list(V = diag(7), nu = 8))) m1 - MCMCglmm(fixed = cbind (var1, var2min, var2max, var3min, var3max, var4min, var4max, var5, var6min, var6max, var7) ~ trait - 1, random = ~ us(trait):nest, rcov = ~ us(trait):units, prior = prior, family =c(gaussian, cengaussian, cengaussian, cengaussian, poisson, cengaussian, poisson), nitt = 6, burnin = 1000, thin = 25, data = datos) I obtained the correlation between behaviours with the general formula: model$VCV[,var1:var2.nest]/sqrt(model$VCV[,var1:var1.nest]*model$VCV[,var2:var2.nest])) so that: cor(var2:var1): 0.379; 95%CI = 0.376 - 0.383 cor(var3:var1): 0.246; 95%CI = 0.242 - 0.249 cor(var4:var1): 0.150; 95%CI = 0.146 - 0.155 cor(var5:var1): -0.022; 95%CI = -0.027 - -0.017 cor(var6:var1): 0.171; 95%CI = 0.167 - 0.176 cor(var7:var1): 0.001; 95%CI = -0.004 - 0.006 cor(var3:var2): 0.364; 95%CI = 0.360 - 0.369 cor(var4:var2): 0.121; 95%CI = 0.115 - 0.127 cor(var5:var2): -0.037; 95%CI = -0.044 - -0.030 cor(var6:var2): 0.209; 95%CI = 0.203 - 0.215 cor(var7:var2): -0.031; 95%CI = -0.038 - -0.024 cor(var4:var3): 0.062; 95%CI = 0.056 - 0.068 cor(var5:var3): 0.037; 95%CI = 0.030 - 0.045 cor(var6:var3): 0.210; 95%CI = 0.204 - 0.216 cor(var7:var3): 0.028; 95%CI = 0.021 - 0.035 cor(var5:var4): -0.436; 95%CI = -0.442 - -0.429 cor(var6:var4): 0.133; 95%CI = 0.126 - 0.140 cor(var7:var4): -0.120; 95%CI = -0.128 - -0.111 cor(var6:var5): -0.160; 95%CI = -0.169 - -0.151 cor(var7:var5): 0.346; 95%CI = 0.336 - 0.357 cor(var7:var6): -0.371; 95%CI = -0.379 - -0.364 So my first response would be that yes, all my behavioural measures are correlated (with different strength or sign). Just to be sure: even if birds are nested within territories (nest), these correlations are at the individual level (within the individual), and nest is a random term because we replicate individuals within the same territory, but nothing about resemblance between mates. OK? ## QUESTION 2) urban birds differ in mean or the strength of the relationship between these behaviours compare with rural ones. I include in models the term habitat which is a factor with 2 levels (urban or rural). Here I have some doubts, as I'm not sure how to do the model: m2a - MCMCglmm(fixed = cbind(var1, var2min, var2max, var3min, var3max, var4min, var4max, var5, var6min, var6max, var7) ~ trait - 1 + habitat, random = ~ us(trait):nest, rcov = ~ us(trait):units, prior = prior,family = c(gaussian, cengaussian, cengaussian, cengaussian, poisson, cengaussian, poisson), nitt = 6, burnin = 1000, thin = 25, data = datos) m2b - MCMCglmm(fixed = cbind(var1, var2min, var2max, var3min, var3max, var4min, var4max, var5, var6min, var6max, var7) ~ trait - 1 + trait:habitat, random = ~ us(trait):nest, rcov = ~ us(trait):units, prior = prior,family = c(gaussian, cengaussian, cengaussian, cengaussian, poisson, cengaussian, poisson), nitt = 6, burnin = 1000, thin = 25, data = datos) m2a, and m2b are different models, but I'm not sure which is their meanings: after reading, what I understood is that m2a test the hypothesis that the relationship between variables changes but in the same way between habitats, while in m2b the idea is that habitat type affect the relationship between variables differently. DIC(m2a): 1514.612 DIC(m2b): 1517.572 m2a is the best model, but m2b is close (âDIC= 2.96), so should I conclude that the relationship between variables is similar in both habitat types? Then, I don't know how to obtain the correlations between the different behaviours using this model (m2b). I find a recomendation in the Rlist, something like this: m2c - MCMCglmm(fixed = cbind(var1, var2min, var2max, var3min, var3max, var4min, var4max, var5, var6min, var6max, var7) ~
Re: [R] Fast function for each row of a data.table
Hi If your problem is not bigger than example (regarding columns following maybe can help (I shortened target.column to tc) dt$target.value - dt[,3]*(dt$tc==3)+dt[,2]*(dt$tc==2)+dt[,1]*(dt$tc==1) and changed dt to data frame as I do not use data table. But it shall work with data table too. Regards Petr -Original Message- From: r-help-boun...@r-project.org [mailto:r-help-bounces@r- project.org] On Behalf Of Aurélien Philippot Sent: Thursday, July 24, 2014 1:39 AM To: R-help@r-project.org Subject: [R] Fast function for each row of a data.table Dear R experts, I have the following data.table: dt- data.table(A=rep(1:5), B=c(20:24), C=rep(30:34), target.name=c(A,B, C,B,A), target.column=c(1,2,3,2,1), target.value=rep(NA,5)) Columns A, B and C are the variables of interest. For each row, I want to get the value of the variable given in the column target.column. For example, in the second row, I want to get the value B. (the column target.column just gives the corresponding column index). I plan to store the results in the column target value. Solution 1: very slow for (i in (1:5)){ dt$target.value[i]- dt[i, c(dt[, target.column[i]]), with=FALSE] } dt Solution 2: faster but still slow df- data.frame(dt) aaa- lapply(1:5, function(i) df[i, which(colnames(df)==df$target.name[i])]) aaa- do.call(rbind,aaa) df$target.value- aaa Not convenient on a big data frame because of rbind Other tries: dt[, c(dt$target.name), with=FALSE] The solution appears on the diagonal term for some reason... The original data.table is big (18 million rows), so time efficiency is a primary concern. Any advice is very welcome. Thanks for your help. Aurelien [[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. Tento e-mail a jakékoliv k němu připojené dokumenty jsou důvěrné a jsou určeny pouze jeho adresátům. Jestliže jste obdržel(a) tento e-mail omylem, informujte laskavě neprodleně jeho odesílatele. Obsah tohoto emailu i s přílohami a jeho kopie vymažte ze svého systému. Nejste-li zamýšleným adresátem tohoto emailu, nejste oprávněni tento email jakkoliv užívat, rozšiřovat, kopírovat či zveřejňovat. Odesílatel e-mailu neodpovídá za eventuální škodu způsobenou modifikacemi či zpožděním přenosu e-mailu. V případě, že je tento e-mail součástí obchodního jednání: - vyhrazuje si odesílatel právo ukončit kdykoliv jednání o uzavření smlouvy, a to z jakéhokoliv důvodu i bez uvedení důvodu. - a obsahuje-li nabídku, je adresát oprávněn nabídku bezodkladně přijmout; Odesílatel tohoto e-mailu (nabídky) vylučuje přijetí nabídky ze strany příjemce s dodatkem či odchylkou. - trvá odesílatel na tom, že příslušná smlouva je uzavřena teprve výslovným dosažením shody na všech jejích náležitostech. - odesílatel tohoto emailu informuje, že není oprávněn uzavírat za společnost žádné smlouvy s výjimkou případů, kdy k tomu byl písemně zmocněn nebo písemně pověřen a takové pověření nebo plná moc byly adresátovi tohoto emailu případně osobě, kterou adresát zastupuje, předloženy nebo jejich existence je adresátovi či osobě jím zastoupené známá. This e-mail and any documents attached to it may be confidential and are intended only for its intended recipients. If you received this e-mail by mistake, please immediately inform its sender. Delete the contents of this e-mail with all attachments and its copies from your system. If you are not the intended recipient of this e-mail, you are not authorized to use, disseminate, copy or disclose this e-mail in any manner. The sender of this e-mail shall not be liable for any possible damage caused by modifications of the e-mail or by delay with transfer of the email. In case that this e-mail forms part of business dealings: - the sender reserves the right to end negotiations about entering into a contract in any time, for any reason, and without stating any reasoning. - if the e-mail contains an offer, the recipient is entitled to immediately accept such offer; The sender of this e-mail (offer) excludes any acceptance of the offer on the part of the recipient containing any amendment or variation. - the sender insists on that the respective contract is concluded only upon an express mutual agreement on all its aspects. - the sender of this e-mail informs that he/she is not authorized to enter into any contracts on behalf of the company except for cases in which he/she is expressly authorized to do so in writing, and such authorization or power of attorney is submitted to the recipient or the person represented by the recipient, or the existence of such authorization is known to the recipient of the person
Re: [R] A question about call()
On 24/07/2014, 2:41 AM, super wrote: The question is as below: Exercises 1.The following two calls look the same, but are actually different: (a - call(mean, 1:10)) # mean(1:10) This one creates a call where the first argument is a vector containing 10 elements. (b - call(mean, quote(1:10))) # mean(1:10) This one creates a call where the first argument is a call to the : function to produce a sequence. identical(a, b) # [1] FALSE What¡¯s the difference? Which one should you prefer? So, how i can figure out this question? In this case they deparse the same, but in other cases they wouldn't, e.g. call(mean, rnorm(10)) appears quite different from call(mean, quote(rnorm(10))) The difference is when the evaluation takes place. Which should you prefer? That's up to you. 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] Creating Functions in R
Hello Guys I am new at writing Functions in R, and as a result am struggling with it. I am trying to use Google other resources, but it's hard to find solutions when you don't know what to look for. I have the following small dataset dput(sub) structure(list(week = c(1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30), value = c(9.45, 7.99, 9.29, 11.66, 12.16, 10.18, 8.04, 11.46, 9.2, 10.34, 9.03, 11.47, 10.51, 9.4, 10.08, 9.37, 10.62, 10.31, 10, 13, 10.9, 9.33, 12.29, 11.5, 10.6, 11.08, 10.38, 11.62, 11.31, 10.52)), .Names = c(week, value), row.names = c(NA, -30L), class = data.frame) I want to take each of the value and subtract from a target {in this case its 10}. This is what I have written in my function so far: vmask - function(data,target){ for(k in 1:length(data)) deviation - data[k]- target dev - return(data.frame(cbind(data,deviation))) return(dev) } vmask(sub,10) View(dev) But when I run this I get the results as expected. But I expected the new coloumn to be called deviation, whereas R just calls in value.1. How can I fix this? Also I was hoping to see this new dataset with columns week, value, and now deviation when I use View(dev) - but it comes up with error 'dev not found'. How can i fix this? Also is there anyway instead of me making a new dataset called dev with the 3 columns, I can just re-use my original dataset sub and give me all the 3 new columns? The next step I want to do is to perform a cumulative sum. So looking at the results, I want a new coloumn in existing dataset (or new dataset), which will now have 4 columns. The 4th column I want to be called CuSum. So the first row of Cusum will be -0.55, the second = -0.55+(-2.01) which will give me -2.56 and so on forth. How can I do this in R using a function? Please help *** MORE THN is a trading style of Royal Sun Alliance Insurance plc (No. 93792). Registered in England and Wales at St. Markâs Court, Chart Way, Horsham, West Sussex, RH12 1XL. Authorised by the Prudential Regulation Authority and regulated by the Financial Conduct Authority and the Prudential Regulation Authority. [[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] Cairo package error: unable to load...
Leonardo, you don't have X11 installed and it no longer ships with OS X 10.9 - you need to get it from http://xquartz.macosforge.org Cheers, Simon On Jul 23, 2014, at 9:25 PM, Leonardo Gama leonardo.g...@usp.br wrote: Hi! I've just installed R on my OS X 10.9 and was trying to make arrayQualityMetrics package work. I've installed it via the biocLite Bioconductor script, and everything was apparently fine. But when I tried to load the package, I've got an issue with the Cairo package... Then I tried to load only Cairo: library(Cairo) Error : .onLoad failed in loadNamespace() for 'Cairo', details: call: dyn.load(file, DLLpath = DLLpath, ...) error: unable to load shared object '/Library/Frameworks/R.framework/Versions/3.1/Resources/library/Cairo/libs/Cairo.so': dlopen(/Library/Frameworks/R.framework/Versions/3.1/Resources/library/Cairo/libs/Cairo.so, 6): Library not loaded: /opt/X11/lib/libXrender.1.dylib Referenced from: /Library/Frameworks/R.framework/Versions/3.1/Resources/library/Cairo/libs/Cairo.so Reason: image not found Error: package or namespace load failed for ‘Cairo’ traceback() 2: stop(gettextf(package or namespace load failed for %s, sQuote(package)), call. = FALSE, domain = NA) 1: library(Cairo) Verified it version and dependencies: packageDescription(Cairo) Package: Cairo Version: 1.5-6 Title: [...] Author: Simon Urbanek simon.urba...@r-project.org, Jeffrey Horner jeff.hor...@vanderbilt.edu Maintainer: Simon Urbanek simon.urba...@r-project.org Depends: R (= 2.4.0) Suggests: png Enhances: FastRWeb Description: [...] SystemRequirements: cairo (= 1.2 http://www.cairographics.org/) URL: http://www.rforge.net/Cairo/ Packaged: 2014-06-26 14:50:25 UTC; svnuser NeedsCompilation: yes Repository: CRAN Date/Publication: 2014-06-26 17:15:22 Built: R 3.1.0; x86_64-apple-darwin13.1.0; 2014-06-27 05:04:27 UTC; unix -- File: /Library/Frameworks/R.framework/Versions/3.1/Resources/library/Cairo/Meta/package.rds Tried to update it and got another error/warning: upgrade.packages(Cairo) Warning message: In doTryCatch(return(expr), name, parentenv, handler) : unable to load shared object '/Library/Frameworks/R.framework/Resources/modules//R_X11.so': dlopen(/Library/Frameworks/R.framework/Resources/modules//R_X11.so, 6): Library not loaded: /opt/X11/lib/libSM.6.dylib Referenced from: /Library/Frameworks/R.framework/Resources/modules//R_X11.so Reason: image not found traceback() No traceback available And finally: sessionInfo() R version 3.1.1 (2014-07-10) Platform: x86_64-apple-darwin13.1.0 (64-bit) locale: [1] C/UTF-8/C/C/C/C attached base packages: [1] stats graphics grDevices utils datasets methods base loaded via a namespace (and not attached): [1] tools_3.1.1 pack packBits packageEvent packageSlot packageStatus package.skeleton packageHasNamespacepackageSlot- packageVersion packageDescription packageNamepackageStartupMessage package_version I've also verified the cairo.os file cited in the first error message, and it was there: $ file /Library/Frameworks/R.framework/Versions/3.1/Resources/library/Cairo/libs/Cairo.so /Library/Frameworks/R.framework/Versions/3.1/Resources/library/Cairo/libs/Cairo.so: Mach-O 64-bit dynamically linked shared library x86_64 $ ls -lh /Library/Frameworks/R.framework/Versions/3.1/Resources/library/Cairo/libs/Cairo.so -rwxrwxr-x 1 root admin 3.2M Jun 27 02:04 /Library/Frameworks/R.framework/Versions/3.1/Resources/library/Cairo/libs/Cairo.so I have no idea of what's going wrong. Somebody could help me? Thank you, and sorry for the bad English. -- Leonardo Gama, acadêmico Ciências Moleculares / Medicina Universidade de São Paulo, Brasil __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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] Creating Functions in R
Hi, On Thu, Jul 24, 2014 at 9:35 AM, Pavneet Arora pavneet.ar...@uk.rsagroup.com wrote: Hello Guys I am new at writing Functions in R, and as a result am struggling with it. I am trying to use Google other resources, but it's hard to find solutions when you don't know what to look for. How about the introduction to R that comes with your installation? It's got a section on writing functions, and some other useful information that you seem to not have learned yet. I have the following small dataset dput(sub) structure(list(week = c(1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30), value = c(9.45, 7.99, 9.29, 11.66, 12.16, 10.18, 8.04, 11.46, 9.2, 10.34, 9.03, 11.47, 10.51, 9.4, 10.08, 9.37, 10.62, 10.31, 10, 13, 10.9, 9.33, 12.29, 11.5, 10.6, 11.08, 10.38, 11.62, 11.31, 10.52)), .Names = c(week, value), row.names = c(NA, -30L), class = data.frame) I want to take each of the value and subtract from a target {in this case its 10}. Thank you for providing data with dput()! There are a bunch of things wrong with your function, starting with the lack of need for a function. If I understand your description correctly, what you actually want is: sub$deviation - sub$value - 10 But for educational purposes, here goes: This is what I have written in my function so far: vmask - function(data,target){ for(k in 1:length(data)) this actually loops through the COLUMNS of data, so first you're subtracting target from week, then from value deviation - data[k]- target but coincidentally it gives you what you thought you were getting, because you're overwriting deviation with each value of k, so the week -target column is never saved. It's a really good idea to explicitly mark the loop with { } too, to reduce confusion. dev - return(data.frame(cbind(data,deviation))) Hm. I don't know what you're trying to do with return() here, and using both data.frame() and cbind() is superfluous. It isn't always necessary, but I find it useful to explicitly name the columns of your data frame when you create it, which gives dev - data.frame(data, deviation = deviation)) return(dev) The last item of a function is what's returned, so all you really need here is dev } vmask(sub,10) View(dev) dev only exists within the scope of the function. But you didn't assign the return value of the function to anything. If you assign it to an object named dev, then dev will exist in the global environment: dev - vmask(sub, 10) But when I run this I get the results as expected. But I expected the new coloumn to be called deviation, whereas R just calls in value.1. How can I fix this? Also I was hoping to see this new dataset with columns week, value, and now deviation when I use View(dev) - but it comes up with error 'dev not found'. How can i fix this? Also is there anyway instead of me making a new dataset called dev with the 3 columns, I can just re-use my original dataset sub and give me all the 3 new columns? The next step I want to do is to perform a cumulative sum. So looking at the results, I want a new coloumn in existing dataset (or new dataset), which will now have 4 columns. The 4th column I want to be called CuSum. So the first row of Cusum will be -0.55, the second = -0.55+(-2.01) which will give me -2.56 and so on forth. How can I do this in R using a function? Please help You don't need a function. Just add the cumulative sum as a new column. sub$Cusum - cumsum(sub$deviation) Sarah -- Sarah Goslee http://www.functionaldiversity.org __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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] Creating Functions in R
Before you start writing functions, you should learn the basics of R by reading An Introduction to R (http://cran.r-project.org/doc/manuals/r-release/R-intro.pdf). Pages 7 and 8 cover what you are asking. There is no need for a for() loop at all and your function is simply overwriting the value of deviation so you only get the last value recycled (page 20, The recycling rule). - David L Carlson Department of Anthropology Texas AM University College Station, TX 77840-4352 -Original Message- From: r-help-boun...@r-project.org [mailto:r-help-boun...@r-project.org] On Behalf Of Pavneet Arora Sent: Thursday, July 24, 2014 8:36 AM To: r-help@r-project.org Subject: [R] Creating Functions in R Hello Guys I am new at writing Functions in R, and as a result am struggling with it. I am trying to use Google other resources, but it's hard to find solutions when you don't know what to look for. I have the following small dataset dput(sub) structure(list(week = c(1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30), value = c(9.45, 7.99, 9.29, 11.66, 12.16, 10.18, 8.04, 11.46, 9.2, 10.34, 9.03, 11.47, 10.51, 9.4, 10.08, 9.37, 10.62, 10.31, 10, 13, 10.9, 9.33, 12.29, 11.5, 10.6, 11.08, 10.38, 11.62, 11.31, 10.52)), .Names = c(week, value), row.names = c(NA, -30L), class = data.frame) I want to take each of the value and subtract from a target {in this case its 10}. This is what I have written in my function so far: vmask - function(data,target){ for(k in 1:length(data)) deviation - data[k]- target dev - return(data.frame(cbind(data,deviation))) return(dev) } vmask(sub,10) View(dev) But when I run this I get the results as expected. But I expected the new coloumn to be called deviation, whereas R just calls in value.1. How can I fix this? Also I was hoping to see this new dataset with columns week, value, and now deviation when I use View(dev) - but it comes up with error 'dev not found'. How can i fix this? Also is there anyway instead of me making a new dataset called dev with the 3 columns, I can just re-use my original dataset sub and give me all the 3 new columns? The next step I want to do is to perform a cumulative sum. So looking at the results, I want a new coloumn in existing dataset (or new dataset), which will now have 4 columns. The 4th column I want to be called CuSum. So the first row of Cusum will be -0.55, the second = -0.55+(-2.01) which will give me -2.56 and so on forth. How can I do this in R using a function? Please help *** MORE THN is a trading style of Royal Sun Alliance Insurance plc (No. 93792). Registered in England and Wales at St. Mark’s Court, Chart Way, Horsham, West Sussex, RH12 1XL. Authorised by the Prudential Regulation Authority and regulated by the Financial Conduct Authority and the Prudential Regulation Authority. [[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] Creating Functions in R
Modified your function and also you don't need a function to do this: sub - structure(list(week = c(1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30), value = c(9.45, 7.99, 9.29, 11.66, 12.16, 10.18, 8.04, 11.46, 9.2, 10.34, 9.03, 11.47, 10.51, 9.4, 10.08, 9.37, 10.62, 10.31, 10, 13, 10.9, 9.33, 12.29, 11.5, 10.6, 11.08, 10.38, 11.62, 11.31, 10.52)), .Names = c(week, value), row.names = c(NA, -30L), class = data.frame) vmask - function(data,target){ data$deviation - data$value - target data # return value } newSub - vmask(sub,10) # need to assign return value View(newSub) # do the same thing without a function sub$deviation - sub$value - 10 View(sub) Jim Holtman Data Munger Guru What is the problem that you are trying to solve? Tell me what you want to do, not how you want to do it. On Thu, Jul 24, 2014 at 10:17 AM, David L Carlson dcarl...@tamu.edu wrote: Before you start writing functions, you should learn the basics of R by reading An Introduction to R (http://cran.r-project.org/doc/manuals/r-release/R-intro.pdf). Pages 7 and 8 cover what you are asking. There is no need for a for() loop at all and your function is simply overwriting the value of deviation so you only get the last value recycled (page 20, The recycling rule). - David L Carlson Department of Anthropology Texas AM University College Station, TX 77840-4352 -Original Message- From: r-help-boun...@r-project.org [mailto:r-help-boun...@r-project.org] On Behalf Of Pavneet Arora Sent: Thursday, July 24, 2014 8:36 AM To: r-help@r-project.org Subject: [R] Creating Functions in R Hello Guys I am new at writing Functions in R, and as a result am struggling with it. I am trying to use Google other resources, but it's hard to find solutions when you don't know what to look for. I have the following small dataset dput(sub) structure(list(week = c(1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30), value = c(9.45, 7.99, 9.29, 11.66, 12.16, 10.18, 8.04, 11.46, 9.2, 10.34, 9.03, 11.47, 10.51, 9.4, 10.08, 9.37, 10.62, 10.31, 10, 13, 10.9, 9.33, 12.29, 11.5, 10.6, 11.08, 10.38, 11.62, 11.31, 10.52)), .Names = c(week, value), row.names = c(NA, -30L), class = data.frame) I want to take each of the value and subtract from a target {in this case its 10}. This is what I have written in my function so far: vmask - function(data,target){ for(k in 1:length(data)) deviation - data[k]- target dev - return(data.frame(cbind(data,deviation))) return(dev) } vmask(sub,10) View(dev) But when I run this I get the results as expected. But I expected the new coloumn to be called deviation, whereas R just calls in value.1. How can I fix this? Also I was hoping to see this new dataset with columns week, value, and now deviation when I use View(dev) - but it comes up with error 'dev not found'. How can i fix this? Also is there anyway instead of me making a new dataset called dev with the 3 columns, I can just re-use my original dataset sub and give me all the 3 new columns? The next step I want to do is to perform a cumulative sum. So looking at the results, I want a new coloumn in existing dataset (or new dataset), which will now have 4 columns. The 4th column I want to be called CuSum. So the first row of Cusum will be -0.55, the second = -0.55+(-2.01) which will give me -2.56 and so on forth. How can I do this in R using a function? Please help *** MORE THN is a trading style of Royal Sun Alliance Insurance plc (No. 93792). Registered in England and Wales at St. Mark’s Court, Chart Way, Horsham, West Sussex, RH12 1XL. Authorised by the Prudential Regulation Authority and regulated by the Financial Conduct Authority and the Prudential Regulation Authority. [[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] A question about call()
Thanks a lot, it is much clear to me now, but i still have a question:br/The raw question is from:br/Hadley wickham's book advanced r programming, Chapter Meta programming, section expressions, in the part Creating a call from its componentsbr/He said:br/To create a new call from its components, you can use call() or as.call(). The first argument to call() is a string which gives a function name. The other arguments are expressions that represent the arguments of the call.br/And He also said in the same section expressions before:br/There are four possible components of an expression: constants, names, calls and pairlists.br/constants are length one atomic vectors, like a or 10. ast() displays them as isbr/So, i can't figure out are 1:10 and rnorm(10) both the expressions? I am confused, or 1:10 is a expression but it is evaled immediately so the expression actually represent it's value? br/I hope you can read the section expressions. At 2014-07-24 07:15:55, Duncan Murdoch murdoch.dun...@gmail.com wrote: On 24/07/2014, 2:41 AM, super wrote: The question is as below: Exercises 1.The following two calls look the same, but are actually different: (a - call(mean, 1:10)) # mean(1:10) This one creates a call where the first argument is a vector containing 10 elements. (b - call(mean, quote(1:10))) # mean(1:10) This one creates a call where the first argument is a call to the : function to produce a sequence. identical(a, b) # [1] FALSE What¡¯s the difference? Which one should you prefer? So, how i can figure out this question? In this case they deparse the same, but in other cases they wouldn't, e.g. call(mean, rnorm(10)) appears quite different from call(mean, quote(rnorm(10))) The difference is when the evaluation takes place. Which should you prefer? That's up to you. 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] Creating Functions in R
Hello Sarah Thank you the detailed explanation, it helped me understand a lot. However, I don't understand what you meant by - It's a really good idea to explicitly mark the loop with { } too, to reduce confusion. Also as per your suggestion I tried to say sub$value, but i get the same value -2.01 for each row. Not sure what I did wrong there? This is my code now: vmask - function(sub,target){ for(k in 1:length(sub)) deviation - sub[k]- target dev - data.frame(sub,deviation=deviation) dev cusums - cumsum(dev$deviation) cusums - data.frame(dev,cusums=cusums) cusums } vmask(sub,10) View(dev) cusums - vmask(sub,10) View(cusums) Also when I try the cusums command, I get the following error: Error in data.frame(dev, cusums = cusums) : arguments imply differing number of rows: 30, 0 What does this mean? And how can i fix it? PS: Thank you so much for helping me with this. From: Sarah Goslee sarah.gos...@gmail.com To: Pavneet Arora/UK/RoyalSun@RoyalSun Cc: r-help r-help@r-project.org Date: 24/07/2014 15:04 Subject:Re: [R] Creating Functions in R Hi, On Thu, Jul 24, 2014 at 9:35 AM, Pavneet Arora pavneet.ar...@uk.rsagroup.com wrote: Hello Guys I am new at writing Functions in R, and as a result am struggling with it. I am trying to use Google other resources, but it's hard to find solutions when you don't know what to look for. How about the introduction to R that comes with your installation? It's got a section on writing functions, and some other useful information that you seem to not have learned yet. I have the following small dataset dput(sub) structure(list(week = c(1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30), value = c(9.45, 7.99, 9.29, 11.66, 12.16, 10.18, 8.04, 11.46, 9.2, 10.34, 9.03, 11.47, 10.51, 9.4, 10.08, 9.37, 10.62, 10.31, 10, 13, 10.9, 9.33, 12.29, 11.5, 10.6, 11.08, 10.38, 11.62, 11.31, 10.52)), .Names = c(week, value), row.names = c(NA, -30L), class = data.frame) I want to take each of the value and subtract from a target {in this case its 10}. Thank you for providing data with dput()! There are a bunch of things wrong with your function, starting with the lack of need for a function. If I understand your description correctly, what you actually want is: sub$deviation - sub$value - 10 But for educational purposes, here goes: This is what I have written in my function so far: vmask - function(data,target){ for(k in 1:length(data)) this actually loops through the COLUMNS of data, so first you're subtracting target from week, then from value deviation - data[k]- target but coincidentally it gives you what you thought you were getting, because you're overwriting deviation with each value of k, so the week -target column is never saved. It's a really good idea to explicitly mark the loop with { } too, to reduce confusion. dev - return(data.frame(cbind(data,deviation))) Hm. I don't know what you're trying to do with return() here, and using both data.frame() and cbind() is superfluous. It isn't always necessary, but I find it useful to explicitly name the columns of your data frame when you create it, which gives dev - data.frame(data, deviation = deviation)) return(dev) The last item of a function is what's returned, so all you really need here is dev } vmask(sub,10) View(dev) dev only exists within the scope of the function. But you didn't assign the return value of the function to anything. If you assign it to an object named dev, then dev will exist in the global environment: dev - vmask(sub, 10) But when I run this I get the results as expected. But I expected the new coloumn to be called deviation, whereas R just calls in value.1. How can I fix this? Also I was hoping to see this new dataset with columns week, value, and now deviation when I use View(dev) - but it comes up with error 'dev not found'. How can i fix this? Also is there anyway instead of me making a new dataset called dev with the 3 columns, I can just re-use my original dataset sub and give me all the 3 new columns? The next step I want to do is to perform a cumulative sum. So looking at the results, I want a new coloumn in existing dataset (or new dataset), which will now have 4 columns. The 4th column I want to be called CuSum. So the first row of Cusum will be -0.55, the second = -0.55+(-2.01) which will give me -2.56 and so on forth. How can I do this in R using a function? Please help You don't need a function. Just add the cumulative sum as a new column. sub$Cusum - cumsum(sub$deviation) Sarah -- Sarah Goslee http://www.functionaldiversity.org __ The following message has been automatically added to comply with the RSA Group IT Security requirements: This email arrived via the internet, over a secure Opportunistic TLS
Re: [R] Windows R doesn't recognize shortcuts ?
On 23/07/2014 14:21, Duncan Murdoch wrote: On 23/07/2014 9:08 AM, ce wrote: Hi All, In Windows 7 , R installation: R version 3.1.1 Patched (2014-07-14 r66149) -- Sock it to Me Copyright (C) 2014 The R Foundation for Statistical Computing Platform: x86_64-w64-mingw32/x64 (64-bit) it doesn't recognize shortcuts in path : list.files(path = cygwin) character(0) cygwin is a shortcut, in properties window Target shows : C:\Users\me\cygwin64\home\me Real path works : list.files(path = C:/Users/me/cygwin64/home/me) [1] 1010week.sh10week.sh a.Raa.sh I don't think R should recognize that. Windows wouldn't recognize it either, if you used dir cygwin in a shell, for example. Duncan Murdoch The shortcut which appears as cygwin is actually a file called cygwin.lnk readWindowsShellLink {R.utils} reads such files: readWindowsShellLink(con=cygwin.lnk) __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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] Cairo package error: unable to load...
On Jul 24, 2014, at 12:03 PM, Leonardo Gama leonardo.g...@usp.br wrote: Sorry, Simon. I should have suspected that it was a trivial problem. But there was an X11 app icon in Applications and I assumed it was installed, but was not. This mensgem only appeared when I clicked on such icon: Screen Shot 2014-07-24 at 11.44.31 AM.png Yes, as you can see it says X11 is *no longer* included with OS X [...] and it asks you if you want to know how to install it - if you continue, it will point you to a page that says that you have to download it from http://xquartz.macosforge.org It doesn't actually do anything - you have to install it yourself - it just tells you how. Cheers, Simon Thank you again! Leonardo 2014-07-24 10:43 GMT-03:00 Simon Urbanek simon.urba...@r-project.org: Leonardo, you don't have X11 installed and it no longer ships with OS X 10.9 - you need to get it from http://xquartz.macosforge.org Cheers, Simon On Jul 23, 2014, at 9:25 PM, Leonardo Gama leonardo.g...@usp.br wrote: Hi! I've just installed R on my OS X 10.9 and was trying to make arrayQualityMetrics package work. I've installed it via the biocLite Bioconductor script, and everything was apparently fine. But when I tried to load the package, I've got an issue with the Cairo package... Then I tried to load only Cairo: library(Cairo) Error : .onLoad failed in loadNamespace() for 'Cairo', details: call: dyn.load(file, DLLpath = DLLpath, ...) error: unable to load shared object '/Library/Frameworks/R.framework/Versions/3.1/Resources/library/Cairo/libs/Cairo.so': dlopen(/Library/Frameworks/R.framework/Versions/3.1/Resources/library/Cairo/libs/Cairo.so, 6): Library not loaded: /opt/X11/lib/libXrender.1.dylib Referenced from: /Library/Frameworks/R.framework/Versions/3.1/Resources/library/Cairo/libs/Cairo.so Reason: image not found Error: package or namespace load failed for ‘Cairo’ traceback() 2: stop(gettextf(package or namespace load failed for %s, sQuote(package)), call. = FALSE, domain = NA) 1: library(Cairo) Verified it version and dependencies: packageDescription(Cairo) Package: Cairo Version: 1.5-6 Title: [...] Author: Simon Urbanek simon.urba...@r-project.org, Jeffrey Horner jeff.hor...@vanderbilt.edu Maintainer: Simon Urbanek simon.urba...@r-project.org Depends: R (= 2.4.0) Suggests: png Enhances: FastRWeb Description: [...] SystemRequirements: cairo (= 1.2 http://www.cairographics.org/) URL: http://www.rforge.net/Cairo/ Packaged: 2014-06-26 14:50:25 UTC; svnuser NeedsCompilation: yes Repository: CRAN Date/Publication: 2014-06-26 17:15:22 Built: R 3.1.0; x86_64-apple-darwin13.1.0; 2014-06-27 05:04:27 UTC; unix -- File: /Library/Frameworks/R.framework/Versions/3.1/Resources/library/Cairo/Meta/package.rds Tried to update it and got another error/warning: upgrade.packages(Cairo) Warning message: In doTryCatch(return(expr), name, parentenv, handler) : unable to load shared object '/Library/Frameworks/R.framework/Resources/modules//R_X11.so': dlopen(/Library/Frameworks/R.framework/Resources/modules//R_X11.so, 6): Library not loaded: /opt/X11/lib/libSM.6.dylib Referenced from: /Library/Frameworks/R.framework/Resources/modules//R_X11.so Reason: image not found traceback() No traceback available And finally: sessionInfo() R version 3.1.1 (2014-07-10) Platform: x86_64-apple-darwin13.1.0 (64-bit) locale: [1] C/UTF-8/C/C/C/C attached base packages: [1] stats graphics grDevices utils datasets methods base loaded via a namespace (and not attached): [1] tools_3.1.1 pack packBits packageEvent packageSlot packageStatus package.skeleton packageHasNamespacepackageSlot- packageVersion packageDescription packageNamepackageStartupMessage package_version I've also verified the cairo.os file cited in the first error message, and it was there: $ file /Library/Frameworks/R.framework/Versions/3.1/Resources/library/Cairo/libs/Cairo.so /Library/Frameworks/R.framework/Versions/3.1/Resources/library/Cairo/libs/Cairo.so: Mach-O 64-bit dynamically linked shared library x86_64 $ ls -lh /Library/Frameworks/R.framework/Versions/3.1/Resources/library/Cairo/libs/Cairo.so -rwxrwxr-x 1 root admin 3.2M Jun 27 02:04 /Library/Frameworks/R.framework/Versions/3.1/Resources/library/Cairo/libs/Cairo.so I have no idea of what's going wrong. Somebody could help me? Thank you, and sorry for the bad English. -- Leonardo Gama, acadêmico Ciências Moleculares / Medicina Universidade de São Paulo, Brasil -- Leonardo Gama, acadêmico Ciências Moleculares / Medicina Universidade de São Paulo, Brasil
Re: [R] Creating Functions in R
Hi, On Thu, Jul 24, 2014 at 11:08 AM, Pavneet Arora pavneet.ar...@uk.rsagroup.com wrote: Hello Sarah Thank you the detailed explanation, it helped me understand a lot. However, I don't understand what you meant by - It's a really good idea to explicitly mark the loop with { } too, to reduce confusion. Instead of for(k in 1:length(sub)) deviation - sub[k]- target it's clearer to use for(k in 1:length(sub)) { deviation - sub[k]- target } so it's explicit what's being looped over. But as I already explained, along with several other people, you not only don't need a loop, but your loop is overwriting each iteration and not at all doing what you think it is. Also as per your suggestion I tried to say sub$value, but i get the same value -2.01 for each row. Not sure what I did wrong there? Where did you do that? This is my code now: vmask - function(sub,target){ for(k in 1:length(sub)) deviation - sub[k]- target dev - data.frame(sub,deviation=deviation) dev cusums - cumsum(dev$deviation) cusums - data.frame(dev,cusums=cusums) cusums } vmask(sub,10) View(dev) cusums - vmask(sub,10) View(cusums) Also when I try the cusums command, I get the following error: Error in data.frame(dev, cusums = cusums) : arguments imply differing number of rows: 30, 0 What does this mean? And how can i fix it? It means your function is still a mess and you haven't read the Introduction to R guide. Your question isn't clear: when you try it where? On its own? When running the function? There is no cusums command either. If you're determined to use a function, needed or not, lose the loop. sub - structure(list(week = c(1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30), value = c(9.45, 7.99, 9.29, 11.66, 12.16, 10.18, 8.04, 11.46, 9.2, 10.34, 9.03, 11.47, 10.51, 9.4, 10.08, 9.37, 10.62, 10.31, 10, 13, 10.9, 9.33, 12.29, 11.5, 10.6, 11.08, 10.38, 11.62, 11.31, 10.52)), .Names = c(week, value), row.names = c(NA, -30L), class = data.frame) vmask - function(sub,target){ deviation - sub$value - target cusums - cumsum(deviation) data.frame(sub, deviation=deviation,cusums=cusums) } vmask(sub, 10) Note that this makes substantial assumptions about the structure of the sub argument, namely that it has a column named value. Sarah PS: Thank you so much for helping me with this. From:Sarah Goslee sarah.gos...@gmail.com To:Pavneet Arora/UK/RoyalSun@RoyalSun Cc:r-help r-help@r-project.org Date:24/07/2014 15:04 Subject:Re: [R] Creating Functions in R Hi, On Thu, Jul 24, 2014 at 9:35 AM, Pavneet Arora pavneet.ar...@uk.rsagroup.com wrote: Hello Guys I am new at writing Functions in R, and as a result am struggling with it. I am trying to use Google other resources, but it's hard to find solutions when you don't know what to look for. How about the introduction to R that comes with your installation? It's got a section on writing functions, and some other useful information that you seem to not have learned yet. I have the following small dataset dput(sub) structure(list(week = c(1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30), value = c(9.45, 7.99, 9.29, 11.66, 12.16, 10.18, 8.04, 11.46, 9.2, 10.34, 9.03, 11.47, 10.51, 9.4, 10.08, 9.37, 10.62, 10.31, 10, 13, 10.9, 9.33, 12.29, 11.5, 10.6, 11.08, 10.38, 11.62, 11.31, 10.52)), .Names = c(week, value), row.names = c(NA, -30L), class = data.frame) I want to take each of the value and subtract from a target {in this case its 10}. Thank you for providing data with dput()! There are a bunch of things wrong with your function, starting with the lack of need for a function. If I understand your description correctly, what you actually want is: sub$deviation - sub$value - 10 But for educational purposes, here goes: This is what I have written in my function so far: vmask - function(data,target){ for(k in 1:length(data)) this actually loops through the COLUMNS of data, so first you're subtracting target from week, then from value deviation - data[k]- target but coincidentally it gives you what you thought you were getting, because you're overwriting deviation with each value of k, so the week -target column is never saved. It's a really good idea to explicitly mark the loop with { } too, to reduce confusion. dev - return(data.frame(cbind(data,deviation))) Hm. I don't know what you're trying to do with return() here, and using both data.frame() and cbind() is superfluous. It isn't always necessary, but I find it useful to explicitly name the columns of your data frame when you create it, which gives dev - data.frame(data, deviation = deviation)) return(dev) The last item of a function is what's returned, so all you really need here is dev }
Re: [R] R CMD BATCH *without* saving output
On Thu, Jul 24, 2014 at 12:16 PM, Nick Matzke mat...@nimbios.org wrote: Hi all, Hi have a series of scripts that print a lot of notes etc. to screen. I have to run them on a massive set of input files. The scripts are self-contained and save the important output to data files in an organized way. I don't need the screen output for anything. Problems: - If I run the script from the R command line, the output printed to Terminal got so huge that it crashed Terminal (I was running 10 of these at once) - I tried R CMD BATCH, but this just created .Rout files that are size 50 GB and counting. I suppose I could be a grownup and refactor all my code with print options that I can turn off, but I would rather be lazy. So, is there a way to run R CMD BATCH or something similar, and NOT print the output to screen or to the .Rout file? I tried: R CMD BATCH --no-save , but that still seems to save the the screen output etc. to .Rout. Thanks, Nick Here is one likely solution to the above question (also, I am now sending from the email address that is subscribed to R-help): Put: sink(/dev/null) ...at the beginning of the script. All screen output now goes to the black hole of /dev/null and is not saved. At the end of the script, put sink() ...to turn this behavior off. (Tip courtesy of Brian O'Meara) There may be even easier solutions, if so, I'm still interested, since I couldn't find anything obvious googling R CMD BATCH (although this function seems to have many options not listed in the help for R CMD BATCH). Thanks, Nick [[alternative HTML version deleted]] __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] R CMD BATCH *without* saving output
Actually, this was the full solution: At the beginning of the script: # Suppressing all output/warnings/try errors: # Open connection to black hole con=file(open=/dev/null) # Don't print anything to screen sink(file=con, type=output) # Don't print messages (e.g. errors/warnings) sink(file=con, type=message) At the end of the script: # Turn off output sink sink() # Turn off message sink sink(type=message) # Close connection to black hole close(con) On Thu, Jul 24, 2014 at 12:27 PM, Nick Matzke mat...@berkeley.edu wrote: On Thu, Jul 24, 2014 at 12:16 PM, Nick Matzke mat...@nimbios.org wrote: Hi all, Hi have a series of scripts that print a lot of notes etc. to screen. I have to run them on a massive set of input files. The scripts are self-contained and save the important output to data files in an organized way. I don't need the screen output for anything. Problems: - If I run the script from the R command line, the output printed to Terminal got so huge that it crashed Terminal (I was running 10 of these at once) - I tried R CMD BATCH, but this just created .Rout files that are size 50 GB and counting. I suppose I could be a grownup and refactor all my code with print options that I can turn off, but I would rather be lazy. So, is there a way to run R CMD BATCH or something similar, and NOT print the output to screen or to the .Rout file? I tried: R CMD BATCH --no-save , but that still seems to save the the screen output etc. to .Rout. Thanks, Nick Here is one likely solution to the above question (also, I am now sending from the email address that is subscribed to R-help): Put: sink(/dev/null) ...at the beginning of the script. All screen output now goes to the black hole of /dev/null and is not saved. At the end of the script, put sink() ...to turn this behavior off. (Tip courtesy of Brian O'Meara) There may be even easier solutions, if so, I'm still interested, since I couldn't find anything obvious googling R CMD BATCH (although this function seems to have many options not listed in the help for R CMD BATCH). Thanks, Nick [[alternative HTML version deleted]] __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] R CMD BATCH *without* saving output
You also might try wrapping the call to the scripts with capture.output(). Bill Dunlap TIBCO Software wdunlap tibco.com On Thu, Jul 24, 2014 at 9:54 AM, Nick Matzke mat...@berkeley.edu wrote: Actually, this was the full solution: At the beginning of the script: # Suppressing all output/warnings/try errors: # Open connection to black hole con=file(open=/dev/null) # Don't print anything to screen sink(file=con, type=output) # Don't print messages (e.g. errors/warnings) sink(file=con, type=message) At the end of the script: # Turn off output sink sink() # Turn off message sink sink(type=message) # Close connection to black hole close(con) On Thu, Jul 24, 2014 at 12:27 PM, Nick Matzke mat...@berkeley.edu wrote: On Thu, Jul 24, 2014 at 12:16 PM, Nick Matzke mat...@nimbios.org wrote: Hi all, Hi have a series of scripts that print a lot of notes etc. to screen. I have to run them on a massive set of input files. The scripts are self-contained and save the important output to data files in an organized way. I don't need the screen output for anything. Problems: - If I run the script from the R command line, the output printed to Terminal got so huge that it crashed Terminal (I was running 10 of these at once) - I tried R CMD BATCH, but this just created .Rout files that are size 50 GB and counting. I suppose I could be a grownup and refactor all my code with print options that I can turn off, but I would rather be lazy. So, is there a way to run R CMD BATCH or something similar, and NOT print the output to screen or to the .Rout file? I tried: R CMD BATCH --no-save , but that still seems to save the the screen output etc. to .Rout. Thanks, Nick Here is one likely solution to the above question (also, I am now sending from the email address that is subscribed to R-help): Put: sink(/dev/null) ...at the beginning of the script. All screen output now goes to the black hole of /dev/null and is not saved. At the end of the script, put sink() ...to turn this behavior off. (Tip courtesy of Brian O'Meara) There may be even easier solutions, if so, I'm still interested, since I couldn't find anything obvious googling R CMD BATCH (although this function seems to have many options not listed in the help for R CMD BATCH). Thanks, Nick [[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] R CMD BATCH *without* saving output
Hi all, Hi have a series of scripts that print a lot of notes etc. to screen. I have to run them on a massive set of input files. The scripts are self-contained and save the important output to data files in an organized way. I don't need the screen output for anything. Problems: - If I run the script from the R command line, the output printed to Terminal got so huge that it crashed Terminal (I was running 10 of these at once) - I tried R CMD BATCH, but this just created .Rout files that are size 50 GB and counting. I suppose I could be a grownup and refactor all my code with print options that I can turn off, but I would rather be lazy. So, is there a way to run R CMD BATCH or something similar, and NOT print the output to screen or to the .Rout file? I tried: R CMD BATCH --no-save , but that still seems to save the the screen output etc. to .Rout. Thanks, Nick [[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] Technological/Logistic Substitution Model
Any one with an idea of estimating the Technological/Logistic substitution model. The model is specified as: fi(t(j)) = 1/[1-exp(-alpa(t(i))-beta(i)] for t tb and alpha 0 fi(t(j)) = 1-sum(f(j-1))- sum(f(j+1)) for tb =t = tc fi(t(j)) = 1/[1+ exp(alpas(t(i)-betas(i))] for t =tc and alphas 0. The models assume that n technologies are introduced to the market, where 1 is the oldest and technology n is the newest, i and j are subscripts representing the type of technology, fi is the market share, t is a subscript denoting time, alpha, alphas, beta, and betas are parameters, tb and tc are time periods during which the technology i starts to enter the saturation and decline phase, respectively. Any suggestion, reading is helpful. Peter Maclean Department of Economics UDSM __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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] Kernel smoothing density function
Hello all, In order to find the kernel smoothing density function of a 3 dimensional data-set, I wrote this code in R: library(ks)defect -read.table(file.choose(),sep=,)hat -kde(defect)pdf(SampleGraph.pdf)plot(hat,drawpoints=TRUE)dev.off() But I have problem in interpretation of the result..I don't see the estimated values for density function (I need to have the values of f to use it in another code). The other problem is that the pdf file is not created correctly..Although the plot is created in R window, when I want to open the pdf file, it says:There was an error opening this document. This file cannot be opened because it has no pages. [[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] Using apply() with functions I wrote
Hello! Does apply() not work with customized functions? Here is a simple example: AddSeven-function(n){n+7} AddSeven(3) [1] 10 M-matrix(nrow=2,ncol=2,data=c(1,2,3,4),byrow=TRUE) M [,1] [,2] [1,]12 [2,]34 apply(x=M,margin=c(1,2),fun=AddSeven) Error in match.fun(FUN) : argument FUN is missing, with no default Thanks for your help! -Steve Pfeiffer [[alternative HTML version deleted]] __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] R CMD BATCH *without* saving output
On *nix like systems: Rscript myscript.R /dev/null 21 On Windows: Rscript myscript.R NUL 21 The above sends both standard output (1) and standard error (2) to nirvana. I prefer using 'Rscript', but the same works with any command including 'R CMD BATCH'. /Henrik PS. Bill, capture.output() would more or less hang your R session for such large outputs (here 50 GB and counting), cf. http://www.jottr.org/2014/05/captureOutput.html On Thu, Jul 24, 2014 at 7:42 PM, William Dunlap wdun...@tibco.com wrote: You also might try wrapping the call to the scripts with capture.output(). Bill Dunlap TIBCO Software wdunlap tibco.com On Thu, Jul 24, 2014 at 9:54 AM, Nick Matzke mat...@berkeley.edu wrote: Actually, this was the full solution: At the beginning of the script: # Suppressing all output/warnings/try errors: # Open connection to black hole con=file(open=/dev/null) # Don't print anything to screen sink(file=con, type=output) # Don't print messages (e.g. errors/warnings) sink(file=con, type=message) At the end of the script: # Turn off output sink sink() # Turn off message sink sink(type=message) # Close connection to black hole close(con) On Thu, Jul 24, 2014 at 12:27 PM, Nick Matzke mat...@berkeley.edu wrote: On Thu, Jul 24, 2014 at 12:16 PM, Nick Matzke mat...@nimbios.org wrote: Hi all, Hi have a series of scripts that print a lot of notes etc. to screen. I have to run them on a massive set of input files. The scripts are self-contained and save the important output to data files in an organized way. I don't need the screen output for anything. Problems: - If I run the script from the R command line, the output printed to Terminal got so huge that it crashed Terminal (I was running 10 of these at once) - I tried R CMD BATCH, but this just created .Rout files that are size 50 GB and counting. I suppose I could be a grownup and refactor all my code with print options that I can turn off, but I would rather be lazy. So, is there a way to run R CMD BATCH or something similar, and NOT print the output to screen or to the .Rout file? I tried: R CMD BATCH --no-save , but that still seems to save the the screen output etc. to .Rout. Thanks, Nick Here is one likely solution to the above question (also, I am now sending from the email address that is subscribed to R-help): Put: sink(/dev/null) ...at the beginning of the script. All screen output now goes to the black hole of /dev/null and is not saved. At the end of the script, put sink() ...to turn this behavior off. (Tip courtesy of Brian O'Meara) There may be even easier solutions, if so, I'm still interested, since I couldn't find anything obvious googling R CMD BATCH (although this function seems to have many options not listed in the help for R CMD BATCH). Thanks, Nick [[alternative HTML version deleted]] __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] Using apply() with functions I wrote
ummm R is case sensitive! fun != FUN (Have you gone through any R tutorials yet? If not, please do so before posting further). Cheers, Bert Bert Gunter Genentech Nonclinical Biostatistics (650) 467-7374 Data is not information. Information is not knowledge. And knowledge is certainly not wisdom. Clifford Stoll On Thu, Jul 24, 2014 at 10:07 AM, Pfeiffer, Steven pfeif...@miamioh.edu wrote: Hello! Does apply() not work with customized functions? Here is a simple example: AddSeven-function(n){n+7} AddSeven(3) [1] 10 M-matrix(nrow=2,ncol=2,data=c(1,2,3,4),byrow=TRUE) M [,1] [,2] [1,]12 [2,]34 apply(x=M,margin=c(1,2),fun=AddSeven) Error in match.fun(FUN) : argument FUN is missing, with no default Thanks for your help! -Steve Pfeiffer [[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] Using apply() with functions I wrote
Ugghh... Sorry for bothering you all!! (Yes, I analyzed the data for my ecology M.S. project with R, but I wasted countless hours committing silly mistakes like this.) On Thu, Jul 24, 2014 at 4:11 PM, Bert Gunter gunter.ber...@gene.com wrote: ummm R is case sensitive! fun != FUN (Have you gone through any R tutorials yet? If not, please do so before posting further). Cheers, Bert Bert Gunter Genentech Nonclinical Biostatistics (650) 467-7374 Data is not information. Information is not knowledge. And knowledge is certainly not wisdom. Clifford Stoll On Thu, Jul 24, 2014 at 10:07 AM, Pfeiffer, Steven pfeif...@miamioh.edu wrote: Hello! Does apply() not work with customized functions? Here is a simple example: AddSeven-function(n){n+7} AddSeven(3) [1] 10 M-matrix(nrow=2,ncol=2,data=c(1,2,3,4),byrow=TRUE) M [,1] [,2] [1,]12 [2,]34 apply(x=M,margin=c(1,2),fun=AddSeven) Error in match.fun(FUN) : argument FUN is missing, with no default Thanks for your help! -Steve Pfeiffer [[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] Using apply() with functions I wrote
Tena koe Steven R is case-sensitive. FUN is missing (you have supplied fun - and × and margin) ... HTH Peter Alspach -Original Message- From: r-help-boun...@r-project.org [mailto:r-help-boun...@r-project.org] On Behalf Of Pfeiffer, Steven Sent: Friday, 25 July 2014 5:08 a.m. To: r-help@r-project.org Subject: [R] Using apply() with functions I wrote Hello! Does apply() not work with customized functions? Here is a simple example: AddSeven-function(n){n+7} AddSeven(3) [1] 10 M-matrix(nrow=2,ncol=2,data=c(1,2,3,4),byrow=TRUE) M [,1] [,2] [1,]12 [2,]34 apply(x=M,margin=c(1,2),fun=AddSeven) Error in match.fun(FUN) : argument FUN is missing, with no default Thanks for your help! -Steve Pfeiffer [[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. The contents of this e-mail are confidential and may be ...{{dropped:14}} __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
[R] R-3.1.1 - R CMD INSTALL problem
Hello I have recently upgraded R to the newest version. Unfortunately my old (fortran and C) R-package cannot be installed anymore (was built before R 3.0.0: please re-install it). I have tried R CMD INSTALL package_name but I noticed that R requests gcc-4.8.2 and specific locations for the libraries (gcc and gfortran). Can someone point me to the documentation on how to install gcc as R requires, please? Please note that I have used brew install gcc on another mac and soft linked all the necessary libraries so that gcc-4.9.1 can be used as 4.8 (as R requires). However I would like a clean installation. Many thanks Ed __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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-3.1.1 - R CMD INSTALL problem
You need to rebuild it with an appropriate Depends entry (version of R greater than 3) in the DESCRIPTION file. Further discussion about how to fix packages belongs on the R-devel mailing list. --- 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. On July 24, 2014 3:52:26 PM PDT, Eduardo M. A. M.Mendes emammen...@gmail.com wrote: Hello I have recently upgraded R to the newest version. Unfortunately my old (fortran and C) R-package cannot be installed anymore (was built before R 3.0.0: please re-install it). I have tried R CMD INSTALL package_name but I noticed that R requests gcc-4.8.2 and specific locations for the libraries (gcc and gfortran). Can someone point me to the documentation on how to install gcc as R requires, please? Please note that I have used brew install gcc on another mac and soft linked all the necessary libraries so that gcc-4.9.1 can be used as 4.8 (as R requires). However I would like a clean installation. Many thanks Ed __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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] working on a data frame
I am coming from the perspective of Excel and VBA scripts, but I would like to do the following in R. I have a data frame with 14 columns and 32,795 rows. I want to check the value in column 8 (row 1) to see if it is a 0. If it is not a zero, proceed to the next row and check the value for column 8. If it is a zero, then a) change the zero to a 1, b) divide the value in column 9 (row 1) by 1, c) place the result in column 10 (row 1) and d) repeat this for each of the other 32,794 rows. Is this possible with an R script, and is this the way to go about it. If it is, could anyone get me started ? Matthew __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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] Retrieve Axis coordinates from map
Hi, i want to automatise the creation of some maps with R, however, I would need to be able to retrieve the coordinates of the axes that R is automatically generated. When using the package MAPS, and creating a map, R will automatically adjust the plot to the region that you are plotting. for example the two command: map(regions=Morocco) or map(regions=France) will generate plots with completely different axis and scale. If I want to automatically generate a map and add a legend to it, I would need to be able to retrieve the coordinates of my axis that were automatically generated in order to give coordinate to place my legend on the map. Basically I would like to automatise the following with a function, and be able to automatically get the coordinates for my legend) map(regions=Morocco) map.axes() legend(-12,34, blablabla) map(regions=France) map.axes() legend(-150,40, blablabla) mapcountry - function(country) { map(regions=country) map.axes() legend(, , blablabla) } I want to be able to extract the and automatically to be able to generate the legend within the function. Thanks Julien [[alternative HTML version deleted]] __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] R-3.1.1 - R CMD INSTALL problem
Many thanks. With 4.9.1 (as I did) no need to modify Depends. Ed PS. I have posted the question to R-devel mailing list. Many thanks. On Jul 24, 2014, at 8:52 PM, Jeff Newmiller jdnew...@dcn.davis.ca.us wrote: You need to rebuild it with an appropriate Depends entry (version of R greater than 3) in the DESCRIPTION file. Further discussion about how to fix packages belongs on the R-devel mailing list. --- 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. On July 24, 2014 3:52:26 PM PDT, Eduardo M. A. M.Mendes emammen...@gmail.com wrote: Hello I have recently upgraded R to the newest version. Unfortunately my old (fortran and C) R-package cannot be installed anymore (was built before R 3.0.0: please re-install it). I have tried R CMD INSTALL package_name but I noticed that R requests gcc-4.8.2 and specific locations for the libraries (gcc and gfortran). Can someone point me to the documentation on how to install gcc as R requires, please? Please note that I have used brew install gcc on another mac and soft linked all the necessary libraries so that gcc-4.9.1 can be used as 4.8 (as R requires). However I would like a clean installation. Many thanks Ed __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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] working on a data frame
Hi, Your description isn't clear: On Thursday, July 24, 2014, Matthew mccorm...@molbio.mgh.harvard.edu wrote: I am coming from the perspective of Excel and VBA scripts, but I would like to do the following in R. I have a data frame with 14 columns and 32,795 rows. I want to check the value in column 8 (row 1) to see if it is a 0. If it is not a zero, proceed to the next row and check the value for column 8. If it is a zero, then a) change the zero to a 1, b) divide the value in column 9 (row 1) by 1, Row 1, or the row in which column 8 == 0? Why do you want to divide by 1? c) place the result in column 10 (row 1) and Ditto on the row 1 question. What do you want column 10 to be if column 8 isn't 0? Does it already have a value. I suppose it must. d) repeat this for each of the other 32,794 rows. Is this possible with an R script, and is this the way to go about it. If it is, could anyone get me started ? Assuming you want to put the new values in the rows where column 8 == 0, you can do it in two steps: mydata[,10] - ifelse(mydata[,8] == 0, mydata[,9]/whatever, mydata[,10]) #where whatever is the thing you want to divide by that probably isn't 1 mydata[,8] - ifelse(mydata[,8] == 0, 1, mydata[,8]) R programming is best done by thinking about vectorizing things, rather than doing them in loops. Reading the Intro to R that comes with your installation is a good place to start. Sarah Matthew -- Sarah Goslee http://www.stringpage.com http://www.sarahgoslee.com http://www.functionaldiversity.org [[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] Retrieve Axis coordinates from map
Tena koe Julien I don't use the maps package much, but I suspect par()$usr will allow you to do what you want. HTH Peter Alspach -Original Message- From: r-help-boun...@r-project.org [mailto:r-help-boun...@r-project.org] On Behalf Of Julien Million Sent: Friday, 25 July 2014 9:05 a.m. To: r-help@r-project.org Subject: [R] Retrieve Axis coordinates from map Hi, i want to automatise the creation of some maps with R, however, I would need to be able to retrieve the coordinates of the axes that R is automatically generated. When using the package MAPS, and creating a map, R will automatically adjust the plot to the region that you are plotting. for example the two command: map(regions=Morocco) or map(regions=France) will generate plots with completely different axis and scale. If I want to automatically generate a map and add a legend to it, I would need to be able to retrieve the coordinates of my axis that were automatically generated in order to give coordinate to place my legend on the map. Basically I would like to automatise the following with a function, and be able to automatically get the coordinates for my legend) map(regions=Morocco) map.axes() legend(-12,34, blablabla) map(regions=France) map.axes() legend(-150,40, blablabla) mapcountry - function(country) { map(regions=country) map.axes() legend(, , blablabla) } I want to be able to extract the and automatically to be able to generate the legend within the function. Thanks Julien [[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. The contents of this e-mail are confidential and may be ...{{dropped:14}} __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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] Retrieve Axis coordinates from map
On Jul 24, 2014, at 2:05 PM, Julien Million wrote: Hi, i want to automatise the creation of some maps with R, however, I would need to be able to retrieve the coordinates of the axes that R is automatically generated. When using the package MAPS, Case matters in R so this is the wrong spelling. and creating a map, R will automatically adjust the plot to the region that you are plotting. for example the two command: map(regions=Morocco) or map(regions=France) will generate plots with completely different axis and scale. If I want to automatically generate a map and add a legend to it, I would need to be able to retrieve the coordinates of my axis that were automatically generated in order to give coordinate to place my legend on the map. Basically I would like to automatise the following with a function, and be able to automatically get the coordinates for my legend) require(maps) map(regions=Morocco) map.axes() legend(-12,34, blablabla) Perhaps something like this: legend(-12,35.5, paste( paste(Xrange = , round( par(usr)[1:2],2), collapse= ), paste( Yrange = , round( par(usr)[3:4],2) , collapse= ), sep=\n) ) ?par # since pkg::maps uses base graphics. map(regions=France) map.axes() legend(-150,40, blablabla) mapcountry - function(country) { map(regions=country) map.axes() legend(, , blablabla) } I want to be able to extract the and automatically to be able to generate the legend within the function. Thanks Julien [[alternative HTML version deleted]] r-help is a plain text mailing list. PLEASE do read the posting guide http://www.R-project.org/posting-guide.html And thank you for providing working 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.
[R] XLConnect on Linux Mint Maya
Folks, I have been trying to get XLConnect to work on my Linux Mint Maya machine. R works fine but this package doesn't seem to want to build. Here is the message I get after supposedly building XLConnect and rJava: require(XLConnect) Loading required package: XLConnect Error : .onLoad failed in loadNamespace() for 'rJava', details: call: dyn.load(file, DLLpath = DLLpath, ...) error: unable to load shared object '/home/refserv/R/i686-pc-linux-gnu-library/3.1/rJava/libs/rJava.so': libjvm.so: cannot open shared object file: No such file or directory I purged the openJDK and downloaded the 1.7.0_65 JDK form Oracle. The build and the compile seemed to work ok as there were no errors. For example I can generate ggplot2 graphs. I know this is probably the wrong forum but if someone could gently point me in the right direction I would be very appreciative. Thanks so much for your time, KW -- __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] working on a data frame
On 7/24/2014 8:52 PM, Sarah Goslee wrote: Hi, Your description isn't clear: On Thursday, July 24, 2014, Matthew mccorm...@molbio.mgh.harvard.edu mailto:mccorm...@molbio.mgh.harvard.edu wrote: I am coming from the perspective of Excel and VBA scripts, but I would like to do the following in R. I have a data frame with 14 columns and 32,795 rows. I want to check the value in column 8 (row 1) to see if it is a 0. If it is not a zero, proceed to the next row and check the value for column 8. If it is a zero, then a) change the zero to a 1, b) divide the value in column 9 (row 1) by 1, Row 1, or the row in which column 8 == 0? All rows in which the value in column 8==0. Why do you want to divide by 1? Column 10 contains the result of the value in column 9 divided by the value in column 8. If the value in column 8==0, then the division can not be done, so I want to change the zero to a one in order to do the division. This is a fairly standard thing to do with this data. (The data are measurements of amounts at two time points. Sometimes a thing will not be present in the beginning (0), but very present at the later time. Column 10 is the log2 of the change. Infinite is not an easy number to work with, so it is common to change the 0 to a 1. On the other hand, something may be present at time 1, but not at the later time. In this case column 10 would be taking the log2 of a number divided by 0, so again the zero is commonly changed to a one in order to get a useable value in column 10. In both the preceding cases there was a real change, but Inf and NaN are not helpful.) c) place the result in column 10 (row 1) and Ditto on the row 1 question. I want to work on all rows where column 8 (and column 9) contain a zero. Column 10 contains the result of the value in column 9 divided by the value in column 8. So, for row 1, column 10 row 1 contains the ratio column 9 row 1 divided by column 8 row 1, and so on through the whole 32,000 or so rows. Most rows do not have a zero in columns 8 or 9. Some rows have zero in column 8 only, and some rows have a zero in column 9 only. I want to get rid of the zeros in these two columns and then do the division to get a manageable value in column 10. Division by zero and Inf are not considered 'manageable' by me. What do you want column 10 to be if column 8 isn't 0? Does it already have a value. I suppose it must. Yes column 10 does have something, but this something can be Inf or NaN, which I want to get rid of. d) repeat this for each of the other 32,794 rows. Is this possible with an R script, and is this the way to go about it. If it is, could anyone get me started ? Assuming you want to put the new values in the rows where column 8 == 0, you can do it in two steps: mydata[,10] - ifelse(mydata[,8] == 0, mydata[,9]/whatever, mydata[,10]) #where whatever is the thing you want to divide by that probably isn't 1 mydata[,8] - ifelse(mydata[,8] == 0, 1, mydata[,8]) R programming is best done by thinking about vectorizing things, rather than doing them in loops. Reading the Intro to R that comes with your installation is a good place to start. Would it be better to change the data frame into a matrix, or something else ? Thanks for your help. Sarah Matthew -- Sarah Goslee http://www.stringpage.com http://www.sarahgoslee.com http://www.functionaldiversity.org [[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] XLConnect on Linux Mint Maya
On Thu, Jul 24, 2014 at 8:36 PM, Keith S Weintraub kw1...@gmail.com wrote: Folks, I have been trying to get XLConnect to work on my Linux Mint Maya machine. R works fine but this package doesn't seem to want to build. Here is the message I get after supposedly building XLConnect and rJava: require(XLConnect) Loading required package: XLConnect Error : .onLoad failed in loadNamespace() for 'rJava', details: call: dyn.load(file, DLLpath = DLLpath, ...) error: unable to load shared object '/home/refserv/R/i686-pc-linux-gnu-library/3.1/rJava/libs/rJava.so': libjvm.so: cannot open shared object file: No such file or directory I purged the openJDK and downloaded the 1.7.0_65 JDK form Oracle. The build and the compile seemed to work ok as there were no errors. For example I can generate ggplot2 graphs. I know this is probably the wrong forum but if someone could gently point me in the right direction I would be very appreciative. Thanks so much for your time, KW It works fine for me on Fedora 20 (and 19 before it). When I installed R, it installed into /usr/lib64/R. There exists a file: /usr/lib64/R/etc/ldpaths which is executed by the R executable script. This sets up the LD_LIBRARY_PATH to point to the Java installation on my machine. In the /usr/lib64/R/bin directory, there is a program called javareconf. I would suggest that you run this with the -n switch, like: R CMD /usr/lib64/R/bin/javareconf -n This will show you what it _would_ do if you left off the -n. Make sure it looks reasonable. If it does, then run the same command, without the -n, as the root superuser. In my case, that would be: sudo R CMD /usr/lib64/R/bin/javareconf You need to be root because it update the file /usr/lib64/R/etc/ldpaths . I am fairly sure this will fix your problem. === As a possible alternative to XLConnect, have you looked at openxlsx? It appears to have the same abilities, just some different syntax. It says that it is written in C and so should be faster than XLConnect. I have tested both packages, a little, and they both seem to work well. Well, it's 22:14 hours here and I wish that I could fall asleep. We're having problems at work and I know that the big boss will blame us peons if the hardware isn't fixed promptly Despite the fact that we are only software people and aren't allowed to touch the hardware. Our management's minds are not using the same logic as mine does. Frustrating. -- There is nothing more pleasant than traveling and meeting new people! Genghis Khan Maranatha! John McKown __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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] XLConnect on Linux Mint Maya
John, I will look at your solution over the weekend. I looked into openxlsx but I don't think it handles named ranges which are useful. Thanks for your help, KW On Thursday, July 24, 2014, John McKown john.archie.mck...@gmail.com wrote: On Thu, Jul 24, 2014 at 8:36 PM, Keith S Weintraub kw1...@gmail.com javascript:; wrote: Folks, I have been trying to get XLConnect to work on my Linux Mint Maya machine. R works fine but this package doesn't seem to want to build. Here is the message I get after supposedly building XLConnect and rJava: require(XLConnect) Loading required package: XLConnect Error : .onLoad failed in loadNamespace() for 'rJava', details: call: dyn.load(file, DLLpath = DLLpath, ...) error: unable to load shared object '/home/refserv/R/i686-pc-linux-gnu-library/3.1/rJava/libs/rJava.so': libjvm.so: cannot open shared object file: No such file or directory I purged the openJDK and downloaded the 1.7.0_65 JDK form Oracle. The build and the compile seemed to work ok as there were no errors. For example I can generate ggplot2 graphs. I know this is probably the wrong forum but if someone could gently point me in the right direction I would be very appreciative. Thanks so much for your time, KW It works fine for me on Fedora 20 (and 19 before it). When I installed R, it installed into /usr/lib64/R. There exists a file: /usr/lib64/R/etc/ldpaths which is executed by the R executable script. This sets up the LD_LIBRARY_PATH to point to the Java installation on my machine. In the /usr/lib64/R/bin directory, there is a program called javareconf. I would suggest that you run this with the -n switch, like: R CMD /usr/lib64/R/bin/javareconf -n This will show you what it _would_ do if you left off the -n. Make sure it looks reasonable. If it does, then run the same command, without the -n, as the root superuser. In my case, that would be: sudo R CMD /usr/lib64/R/bin/javareconf You need to be root because it update the file /usr/lib64/R/etc/ldpaths . I am fairly sure this will fix your problem. === As a possible alternative to XLConnect, have you looked at openxlsx? It appears to have the same abilities, just some different syntax. It says that it is written in C and so should be faster than XLConnect. I have tested both packages, a little, and they both seem to work well. Well, it's 22:14 hours here and I wish that I could fall asleep. We're having problems at work and I know that the big boss will blame us peons if the hardware isn't fixed promptly Despite the fact that we are only software people and aren't allowed to touch the hardware. Our management's minds are not using the same logic as mine does. Frustrating. -- There is nothing more pleasant than traveling and meeting new people! Genghis Khan Maranatha! John McKown -- KW [[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] working on a data frame
Tena koe Matthew Column 10 contains the result of the value in column 9 divided by the value in column 8. If the value in column 8==0, then the division can not be done, so I want to change the zero to a one in order to do the division.. That being the case, think in terms of vectors, as Sarah says. Try: yourData[,10] - yourData[,9]/yourData[,8] yourData[yourData[,8]==0,10] - yourData[yourData[,8]==0,9] This doesn't change the 0 to 1 in column 8, but it doesn't appear you actually need to do that. HTH Peter Alspach -Original Message- From: r-help-boun...@r-project.org [mailto:r-help-boun...@r-project.org] On Behalf Of Matthew McCormack Sent: Friday, 25 July 2014 3:16 p.m. To: Sarah Goslee Cc: r-help@r-project.org Subject: Re: [R] working on a data frame On 7/24/2014 8:52 PM, Sarah Goslee wrote: Hi, Your description isn't clear: On Thursday, July 24, 2014, Matthew mccorm...@molbio.mgh.harvard.edu mailto:mccorm...@molbio.mgh.harvard.edu wrote: I am coming from the perspective of Excel and VBA scripts, but I would like to do the following in R. I have a data frame with 14 columns and 32,795 rows. I want to check the value in column 8 (row 1) to see if it is a 0. If it is not a zero, proceed to the next row and check the value for column 8. If it is a zero, then a) change the zero to a 1, b) divide the value in column 9 (row 1) by 1, Row 1, or the row in which column 8 == 0? All rows in which the value in column 8==0. Why do you want to divide by 1? Column 10 contains the result of the value in column 9 divided by the value in column 8. If the value in column 8==0, then the division can not be done, so I want to change the zero to a one in order to do the division. This is a fairly standard thing to do with this data. (The data are measurements of amounts at two time points. Sometimes a thing will not be present in the beginning (0), but very present at the later time. Column 10 is the log2 of the change. Infinite is not an easy number to work with, so it is common to change the 0 to a 1. On the other hand, something may be present at time 1, but not at the later time. In this case column 10 would be taking the log2 of a number divided by 0, so again the zero is commonly changed to a one in order to get a useable value in column 10. In both the preceding cases there was a real change, but Inf and NaN are not helpful.) c) place the result in column 10 (row 1) and Ditto on the row 1 question. I want to work on all rows where column 8 (and column 9) contain a zero. Column 10 contains the result of the value in column 9 divided by the value in column 8. So, for row 1, column 10 row 1 contains the ratio column 9 row 1 divided by column 8 row 1, and so on through the whole 32,000 or so rows. Most rows do not have a zero in columns 8 or 9. Some rows have zero in column 8 only, and some rows have a zero in column 9 only. I want to get rid of the zeros in these two columns and then do the division to get a manageable value in column 10. Division by zero and Inf are not considered 'manageable' by me. What do you want column 10 to be if column 8 isn't 0? Does it already have a value. I suppose it must. Yes column 10 does have something, but this something can be Inf or NaN, which I want to get rid of. d) repeat this for each of the other 32,794 rows. Is this possible with an R script, and is this the way to go about it. If it is, could anyone get me started ? Assuming you want to put the new values in the rows where column 8 == 0, you can do it in two steps: mydata[,10] - ifelse(mydata[,8] == 0, mydata[,9]/whatever, mydata[,10]) #where whatever is the thing you want to divide by that probably isn't 1 mydata[,8] - ifelse(mydata[,8] == 0, 1, mydata[,8]) R programming is best done by thinking about vectorizing things, rather than doing them in loops. Reading the Intro to R that comes with your installation is a good place to start. Would it be better to change the data frame into a matrix, or something else ? Thanks for your help. Sarah Matthew -- Sarah Goslee http://www.stringpage.com http://www.sarahgoslee.com http://www.functionaldiversity.org [[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. The contents of this e-mail are confidential and may be ...{{dropped:14}} __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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-es] Calcular Conductance, cut ratio, Expansion
Saludo!, ante todo gracias por su ayuda. Estoy trabajando con grafos y querÃa validar las comunidades encontradas con los diferentes algoritmos presentes en igraph. A la hora de validar las comunidades considero la modularidad, pero también me gustarÃa ver Conductancia, Radio de corte, Expansión, pero no se si ya están implementados en algunas otras librerÃas, alguien sabe?, pues busqué y no hay sugerencias. Por otro lado tenÃa pensado calcularlas pero alguien sabe como se puede contar los edges de un grafo en base a unos determinados nodos indicados?.POR FAVOR SE RECIBE SUGERENCIAS. [[alternative HTML version deleted]] ___ R-help-es mailing list R-help-es@r-project.org https://stat.ethz.ch/mailman/listinfo/r-help-es
Re: [R-es] Calcular Conductance, cut ratio, Expansion
Hola. Quizá te pueda servir la charla que dieron en el GIL (Grupo de Interés Local) de Madrid que se impartió el jueves 4 de Abril de 2013. Mira aquí http://r-es.org/tiki-index.php?page=Grupo%20de%20Inter%C3%A9s%20Local%20de%20Madrid%20-%20GIL%20Madrid y busca en la página *Análisis de Redes Sociales con R* Saludos. PD: Y ya de paso podrías darte de alta en la comunidad de usuarios de R-hispano ;) El 24/07/14 a las #4, Amalia Carolina Guaymas Canavire escribió: Saludo!, ante todo gracias por su ayuda. Estoy trabajando con grafos y quería validar las comunidades encontradas con los diferentes algoritmos presentes en igraph. A la hora de validar las comunidades considero la modularidad, pero también me gustaría ver Conductancia, Radio de corte, Expansión, pero no se si ya están implementados en algunas otras librerías, alguien sabe?, pues busqué y no hay sugerencias. Por otro lado tenía pensado calcularlas pero alguien sabe como se puede contar los edges de un grafo en base a unos determinados nodos indicados?.POR FAVOR SE RECIBE SUGERENCIAS. [[alternative HTML version deleted]] ___ R-help-es mailing list R-help-es@r-project.org https://stat.ethz.ch/mailman/listinfo/r-help-es [[alternative HTML version deleted]] ___ R-help-es mailing list R-help-es@r-project.org https://stat.ethz.ch/mailman/listinfo/r-help-es
[R-es] wordcloud y tabla de palabras
Buenas noches grupo. Saludos cordiales. He seguido en la búsqueda de una forma que me permita realizar la comparación de dos documentos pertenecientes a los años 2005 y 2013, y que pueda representar finalmente con wordcloud y con una table en la que las columnas sean los años de cada informe 2005 y 2013, y las filas sean las palabras con la frecuencia de cada una de ellas por cada informe: -- || 2005 | 2013 | -- | terminos | | | -- | terminos | | | -- De manera que buscando y experimentando, adaptando de otras experiencias logré llegar a lo siguiente: ## informes-c(2013, 2005) pathname-C:/Users/d_2/Documents/Comision/PLAN de INSPECCIONES/Informes/ TDM-function(informes, pathname) { info.dir-sprintf(%s/%s, pathname, informes) info.cor-Corpus(DirSource(directory=info.dir, encoding=UTF-8)) info.cor.cl-tm_map(info.cor, content_transformer(tolower)) info.cor.cl-tm_map(info.cor.cl, stripWhitespace) info.cor.cl-tm_map(info.cor.cl,removePunctuation) sw-readLines(C:/Users/d_2/Documents/StopWords.txt, encoding=UTF-8) sw-iconv(enc2utf8(sw), sub = byte) info.cor.cl-tm_map(info.cor.cl, removeWords, stopwords(spanish)) info.tdm-TermDocumentMatrix(info.cor.cl) result-list(name = informes, tdm= info.tdm) } tdm-lapply(informes, TDM, path = pathname) Resultado: tdm [[1]] [[1]]$name [1] 2013 [[1]]$tdm TermDocumentMatrix (terms: 1540, documents: 1) Non-/sparse entries: 1540/0 Sparsity : 0% Maximal term length: 18 Weighting : term frequency (tf) [[2]] [[2]]$name [1] 2005 [[2]]$tdm TermDocumentMatrix (terms: 1849, documents: 1) Non-/sparse entries: 1849/0 Sparsity : 0% Maximal term length: 19 Weighting : term frequency (tf) str(tdm) List of 2 $ :List of 2 ..$ name: 2013 ..$ tdm :List of 6 .. ..$ i : int [1:1540] 1 2 3 4 5 6 7 8 9 10 ... .. ..$ j : int [1:1540] 1 1 1 1 1 1 1 1 1 1 ... .. ..$ v : num [1:1540] 1 5 8 1 1 1 1 3 1 1 ... .. ..$ nrow: int 1540 .. ..$ ncol: int 1 .. ..$ dimnames:List of 2 .. .. ..$ Terms: [1:1540] 070812 100 10 117735 ... .. .. ..$ Docs : 2013_21SeguridadCiudadana.txt .. ..- attr(*, class)= [1:2] TermDocumentMatrix simple_triplet_matrix .. ..- attr(*, weighting)= [1:2] term frequency tf $ :List of 2 ..$ name: 2005 ..$ tdm :List of 6 .. ..$ i : int [1:1849] 1 2 3 4 5 6 7 8 9 10 ... .. ..$ j : int [1:1849] 1 1 1 1 1 1 1 1 1 1 ... .. ..$ v : num [1:1849] 1 1 1 1 1 1 1 1 1 1 ... .. ..$ nrow: int 1849 .. ..$ ncol: int 1 .. ..$ dimnames:List of 2 .. .. ..$ Terms: [1:1849] 071004 10 101005 1022 ... .. .. ..$ Docs : 05_seguridad_ciudadana.txt .. ..- attr(*, class)= [1:2] TermDocumentMatrix simple_triplet_matrix .. ..- attr(*, weighting)= [1:2] term frequency tf m-as.matrix(tdm) Al probar str(tdm), se obtiene lo siguiente: List of 2 $ :List of 2 ..$ name: chr 2013 ..$ tdm :List of 6 .. ..$ i : int [1:1540] 1 2 3 4 5 6 7 8 9 10 ... .. ..$ j : int [1:1540] 1 1 1 1 1 1 1 1 1 1 ... .. ..$ v : num [1:1540] 1 5 8 1 1 1 1 3 1 1 ... .. ..$ nrow: int 1540 .. ..$ ncol: int 1 .. ..$ dimnames:List of 2 .. .. ..$ Terms: chr [1:1540] 070812 100 10 117735 ... .. .. ..$ Docs : chr 2013_21SeguridadCiudadana.txt .. ..- attr(*, class)= chr [1:2] TermDocumentMatrix simple_triplet_matrix .. ..- attr(*, weighting)= chr [1:2] term frequency tf $ :List of 2 ..$ name: chr 2005 ..$ tdm :List of 6 .. ..$ i : int [1:1849] 1 2 3 4 5 6 7 8 9 10 ... .. ..$ j : int [1:1849] 1 1 1 1 1 1 1 1 1 1 ... .. ..$ v : num [1:1849] 1 1 1 1 1 1 1 1 1 1 ... .. ..$ nrow: int 1849 .. ..$ ncol: int 1 .. ..$ dimnames:List of 2 .. .. ..$ Terms: chr [1:1849] 071004 10 101005 1022 ... .. .. ..$ Docs : chr 05_seguridad_ciudadana.txt .. ..- attr(*, class)= chr [1:2] TermDocumentMatrix simple_triplet_matrix .. ..- attr(*, weighting)= chr [1:2] term frequency tf - attr(*, dim)= int [1:2] 2 1 m-as.matrix(tdm) m [,1] [1,] List,2 [2,] List,2 ### Pero no logro poder avanzar en los pasos para tener la comparativa de palabras por años par avanzar en una visualización de wordcloud. Si alguien se le ocurre alguna idea, agradecería mucho la ayuda. ___ R-help-es mailing list R-help-es@r-project.org https://stat.ethz.ch/mailman/listinfo/r-help-es