Re: [R] how to generate 2 dimensional mesh and hyper-cubes ?
Tks a lot, i will study the limma package as you mentioned first ~ ~ -- PO SU mail: desolato...@163.com Majored in Statistics from SJTU At 2015-08-26 00:17:18, David Winsemius dwinsem...@comcast.net wrote: On Aug 25, 2015, at 4:15 AM, PO SU wrote: Dear expeRts, i want to know how to generate the 2 dimensional mesh (i.e. grid on the torus) of size n, The grid mesh (with wrap around of boundaries into a torus to avoid edge-effects). and the hyper-cube which is the log2(n)-dimensional grid of size n.Does anyone happen to know it? BTW, how to find spargraphs this package, i find almost everywhere i know but still can not find it in R, is it a matlab package or other language package? Tks! In searching I found nothing re: spargraphs. I did find some genetics oriented tutorials for students that mentioned producing spar graphs with the limma-package. You might address this question to the BioConductor mailing list if your area of interest is genetics/molecular biology. -- David Winsemius Alameda, CA, USA [[alternative HTML version deleted]] __ R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
[R] how to generate 2 dimensional mesh and hyper-cubes ?
Dear expeRts, i want to know how to generate the 2 dimensional mesh (i.e. grid on the torus) of size n, The grid mesh (with wrap around of boundaries into a torus to avoid edge-effects). and the hyper-cube which is the log2(n)-dimensional grid of size n. Does anyone happen to know it? BTW, how to find spargraphs this package, i find almost everywhere i know but still can not find it in R, is it a matlab package or other language package? Tks! -- PO SU mail: desolato...@163.com Majored in Statistics from SJTU __ R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
[R] how to use nlme package to analysis mixed effect model
Dear experts, i want to use nlme or plm to analysis mixed effect model, my data has the format : city year area y x 1 2010 A 1.2 2 1 2011 A 3 3 2 2010 A 5 4 2 2011 A 2.1 1.8 3 2010 B 1.7 2 I want to know does y has relationsheep with x? how to use nlme or plm to do the task? the two packages seems does not have viggnette to guide me ? Does anyone happen to know ? -- PO SU mail: desolato...@163.com Majored in Statistics from SJTU __ R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see https://stat.ethz.ch/mailman/listinfo/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] A strange problem using pls package
Dear expeRts, Today i used the pls package to do the PLSR, i don' t know if anyone happen to have the same problem as me, it is so strange, my problem is: when i used codes like: suppose data has 20 columns traindata - data[ 1:10, 1:10] testdata - data[11:15,1:10] pls.fit - plsr(y~x, ncomp = 5, data = traindata, method= simpls, scale = FALSE, model = TRUE, validation = CV) ok, i get some result, the srange thing happens when i redo the plsr, i mean, i use traindata - data[ 1:10, 1:20] testdata - data[11:15,1:20] pls.fit - plsr(y~x, ncomp = 5, data = traindata, method= simpls, scale = FALSE, model = TRUE, validation = CV) I get the same result as the first one!!! i explore it a lot, even restart my computer, but still the same, however i changed the data, the result is the same!! I think the pls package must write the result into some files, and read it back ~~ but i can't say~~ PLZ help me if you happen to know it -- PO SU mail: desolato...@163.com Majored in Statistics from SJTU __ R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see https://stat.ethz.ch/mailman/listinfo/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] Two stage cluster in R(two step in spss), which package implement it ?
Dear, expeRts, I am confused in finding an implementation of two stage cluster in R(which is two step cluster in spss), i do some searching, but still can not find it. Has someone happen to know it ? -- PO SU mail: desolato...@163.com Majored in Statistics from SJTU __ R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see https://stat.ethz.ch/mailman/listinfo/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] RWebdriver and RSelenium returns the same error while trying to connect the java server
Dear expeRts, when i using RWebdriver and RSelenium , require(RSelenium) Loading required package: RSelenium remDr - remoteDriver(remoteServerAddr = localhost + , port = + , browserName = firefox + ) remDr$open() [1] Connecting to remote server Error: Summary: UnknownError Detail: An unknown server-side error occurred while processing the command. class: org.openqa.selenium.firefox.NotConnectedException from the cmd lines, it show unable to connect 127.0.0.1 7055 after 45000ms i don't know why, is there anybody who happens to know it ? -- PO SU mail: desolato...@163.com Majored in Statistics from SJTU __ R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see https://stat.ethz.ch/mailman/listinfo/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] Needing help about recosystem package
Dear expeRt, I am using recosystem package which is an wrapper of the LIBMF library, it implements matrix factorize which needed in latent factor model, but the package only provides the predict method, not include matrix P,Q which estimated. I just need the P and Q matrix, so ,if anyone happen to know it ? -- PO SU mail: desolato...@163.com Majored in Statistics from SJTU __ R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] How to build a vignette?
Yeah, i can write some roxygen2 which transformed to .RD files. The pdf of a package in the cran is not a vignette? That's to say some packages have not vignettes? And the pdf version is generated by me or cran ? If by me , how can i generate it from my .RD files. i am writing a package, source R codes are already written but i don't very clear about how to subbmmit to cran. -- PO SU mail: desolato...@163.com Majored in Statistics from SJTU At 2014-12-06 11:12:32, Jeff Newmiller jdnew...@dcn.davis.ca.us wrote: You are not talking about a vignette. That is the pdf version of the help files, automatically generated from the same Rd files as the HTML versions. If you are not going to write the Rd file directly, you probably want roxygen. Markdown is weak on links and template structures, and Rd files use a lot of them. RStudio makes using roxygen to generate Rd files easy, though raw Rd files aren't that bad. Keep in mind that you will probably end up learning a bit of Rd syntax even if you preprocess with roxygen, so don't be shy about diving in to section 2 of the Writing R Extensions documentation. --- 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 December 5, 2014 1:12:36 PM PST, PO SU rhelpmaill...@163.com wrote: Dear expeRts, I know we can build a vignette from .Rmd file, but i find a lot of r packages have R topic documented words then followed an index, then functions'document which are already described in .RD files. I mean that , i don't want to write a vignette , but rather using function documents from .Rd files, how can i do? TKS. -- PO SU mail: desolato...@163.com Majored in Statistics from SJTU __ R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see https://stat.ethz.ch/mailman/listinfo/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 -- To UNSUBSCRIBE and more, see https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] How to build a vignette?
OK, I got it , you helped me a lot , tks very much. :) -- PO SU mail: desolato...@163.com Majored in Statistics from SJTU At 2014-12-06 14:12:45, Jeff Newmiller jdnew...@dcn.davis.ca.us wrote: If you run R CMD check on your package successfully, then that file will be generated as needed automatically. If you install your package for you're own use before sending it to CRAN then you can see the file by following the link on the help index html page for your package. --- 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 December 5, 2014 9:47:36 PM PST, PO SU rhelpmaill...@163.com wrote: Yeah, i can write some roxygen2 which transformed to .RD files. The pdf of a package in the cran is not a vignette? That's to say some packages have not vignettes? And the pdf version is generated by me or cran ? If by me , how can i generate it from my .RD files. i am writing a package, source R codes are already written but i don't very clear about how to subbmmit to cran. -- PO SU mail: desolato...@163.com Majored in Statistics from SJTU At 2014-12-06 11:12:32, Jeff Newmiller jdnew...@dcn.davis.ca.us wrote: You are not talking about a vignette. That is the pdf version of the help files, automatically generated from the same Rd files as the HTML versions. If you are not going to write the Rd file directly, you probably want roxygen. Markdown is weak on links and template structures, and Rd files use a lot of them. RStudio makes using roxygen to generate Rd files easy, though raw Rd files aren't that bad. Keep in mind that you will probably end up learning a bit of Rd syntax even if you preprocess with roxygen, so don't be shy about diving in to section 2 of the Writing R Extensions documentation. --- 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 December 5, 2014 1:12:36 PM PST, PO SU rhelpmaill...@163.com wrote: Dear expeRts, I know we can build a vignette from .Rmd file, but i find a lot of r packages have R topic documented words then followed an index, then functions'document which are already described in .RD files. I mean that , i don't want to write a vignette , but rather using function documents from .Rd files, how can i do? TKS. -- PO SU mail: desolato...@163.com Majored in Statistics from SJTU __ R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see https://stat.ethz.ch/mailman/listinfo/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 -- To UNSUBSCRIBE and more, see https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
[R] How to build a vignette?
Dear expeRts, I know we can build a vignette from .Rmd file, but i find a lot of r packages have R topic documented words then followed an index, then functions'document which are already described in .RD files. I mean that , i don't want to write a vignette , but rather using function documents from .Rd files, how can i do? TKS. -- PO SU mail: desolato...@163.com Majored in Statistics from SJTU __ R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see https://stat.ethz.ch/mailman/listinfo/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 win task to run Rscript somepackages can't work in script mode
Dear expeRts, These days i want to run a .R file contained a package called gmailr to do something about processing gmail , it works well in interactive GUI ,that is ,Rstudio. But i want to run it by a windows task, so i need to run the .R file in Rscript mode, sadly, there seems different between the two ways, the gmailr package fails work in the script mode. So, what the difference? why Rscript can't run some codes which works well in Rstudio? How can i do something to make it suceess if there is some options to set ? -- PO SU mail: desolato...@163.com Majored in Statistics from SJTU __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
[R] problem when using gmailr
Dear expeRts, Hi, when i using gmailr through Rscript got the following error : oauth_listener() needs an interactive environment But when i using the Rstudio it worked. Does the function gmail_auth(filepath,full) support the Rscript way ?? I need run it in a windows schdual task. TKS -- PO SU mail: desolato...@163.com Majored in Statistics from SJTU __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
[R] how to use the rpart model to predict new data frame?
Dear expeRts, Now i have a train dataset a and test dataset b , i using the following codes: rp-rpart(y~.,data=a,method=class) plot(rp) text(rp) but how can i use the trained model to predict b? TKS. -- PO SU mail: desolato...@163.com Majored in Statistics from SJTU __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] how to use the rpart model to predict new data frame?
OK , i tried predict(rp,b) but showed me a result which i can't understand, now it's the argument type=vector worked. -- PO SU mail: desolato...@163.com Majored in Statistics from SJTU At 2014-11-12 11:55:08, Bharat Bargujar bharatbargu...@gmail.com wrote: HI, Try this: results - predict(rp,b,type = vector) Regards, Bharat On 12 November 2014 09:17, PO SU rhelpmaill...@163.com wrote: Dear expeRts, Now i have a train dataset a and test dataset b , i using the following codes: rp-rpart(y~.,data=a,method=class) plot(rp) text(rp) but how can i use the trained model to predict b? TKS. -- PO SU mail: desolato...@163.com Majored in Statistics from SJTU __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] how to calculate a numeric's digits count?
Ok, what i want is find how many numbers after . in a numeric ,and i don't know if there is already exists a function to do it( i wrote one by myself which will be showed later). e.g. 1.234 has 3 numbers after . 1 has 0 number 1.5342 has 4 numbers And i solved the above format using: find-function(x) { str-as.character(x) if(is.na(strsplit(str,\\.)[[1]][2])) return(0) else return(nchar(strsplit(str,\\.)[[1]][2])) } But when i find(1.340) i get 2 not 3. find(1.3400) will also get 2 not 4. So,my question is how to implement the above needing? TKS. -- PO SU mail: desolato...@163.com Majored in Statistics from SJTU At 2014-10-24 12:04:18, Jeff Newmiller jdnew...@dcn.davis.ca.us wrote: I am baffled. I think those were English words but they didn't make any sense to me. Not was there a reproducible example to turn to. Can you try again? --- 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 October 23, 2014 8:35:06 PM PDT, PO SU rhelpmaill...@163.com wrote: Dear usRers, Now i want to cal ,e.g. cal(1.234) will get 3 cal(1) will get 0 cal(1.3045) will get 4 But the difficult part is cal(1.3450) will get 4 not 3. So, is there anyone happen to know the solution to this problem, or it can't be solved in R, because 1.340 will always be transformed autolly to 1.34? -- PO SU mail: desolato...@163.com Majored in Statistics from SJTU __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
[R] how to calculate a numeric's digits count?
Dear usRers, Now i want to cal ,e.g. cal(1.234) will get 3 cal(1) will get 0 cal(1.3045) will get 4 But the difficult part is cal(1.3450) will get 4 not 3. So, is there anyone happen to know the solution to this problem, or it can't be solved in R, because 1.340 will always be transformed autolly to 1.34? -- PO SU mail: desolato...@163.com Majored in Statistics from SJTU __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] how to overwrite a Unary operator ?
TKS , but i still have a question that maybe i can write a new S3 method for +, but how can i create a new operator which can pass one param? becasue + is far away from ++ to let me know that 2 will be 3. So, it's still a question.. -- PO SU mail: desolato...@163.com Majored in Statistics from SJTU At 2014-10-18 01:40:50, David Winsemius dwinsem...@comcast.net wrote: On Oct 17, 2014, at 1:06 AM, PO SU wrote: Tks for your alternative way's details. but like you mentioned in graphics package, i still wonder how to overload an operator which can pass one param like +2 . There seems exists some examples for my needing. But i try to find them but without any results. can you show me some examples from it? I think this might be a case of if you don't know enough to do it, then you don't know why you shouldn't do it. (Or vice versa?) I did search for a relevant fortune to support my impression, but the various entries for fortune(parse) and fortune(eval) didn't seem to hit the mark. library(ggplot2) help(pack=ggplot2) # scroll to bottom of page ggplot2:::`+.gg` # this shows the S3 method of adding an operator based on the S3 method dispatch. I was able to emulate that example to create a C-like, unary `+` operator for a new class, but I'm not willing to put it in print for fear that my karmic account might be depleted. -- David. -- PO SU mail: desolato...@163.com Majored in Statistics from SJTU At 2014-10-17 15:16:47, David Winsemius dwinsem...@comcast.net wrote: On Oct 16, 2014, at 10:36 PM, PO SU wrote: Tks for your advice, let the ++ problem alone, how to write an Unary operator ? Is it permitted in R? suchasa-2 , a%+2% will let a be 4 . OK, that's just wrong. Oh, OK, just for fun, as it were: inc - function(x) { eval.parent(substitute(x - x + 1)) } inc(10) Error in 10 - 10 + 1 : invalid (do_set) left-hand side to assignment y=10 inc(y) y [1] 11 I just want to know it , i won't pollute r with it , because i know what is r . : ) It's certainly permitted. Just look at all the overloadings of the + operator in graphics packages. Look up the documentation on methods in R. Why not just use a well-behaved function, though? .inc - function(x) x+1 .inc(10) [1] 11 Then you won't be tempted to try 10 - .inc(10) because it just wouldn't make sense. -- David. -- PO SU mail: desolato...@163.com Majored in Statistics from SJTU At 2014-10-17 13:09:47, Rolf Turner r.tur...@auckland.ac.nz wrote: On 17/10/14 17:29, PO SU wrote: Dear expeRts, Now i want to know how to implement an Unary operator like i++ in cpp's synax form. e.g. 2++ will let 2 be 3 , a-2 ,a++ ,will let a be 3 I tried this : '%++%'-function(x){ x-x+1 } but it have problem, the biggest one is it seems the function need twoparams like a%++%b , how to write a function needing just one param? TKS ! Just ***DON'T***. The ++ operator is useful only for those wish to write code which is obscure to the point of incomprehensibility. It makes C and its offspring write only languages. If you are going to use R, use R and don't pollute it with such abominations. cheers, Rolf Turner -- Rolf Turner Technical Editor ANZJS __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. David Winsemius, MD Alameda, CA, USA David Winsemius Alameda, CA, USA __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] how to overwrite a Unary operator ?
It's a good way to use RF OOS, but it's not my needing, actually, i want is there exists a way to write a %++% form function that can pass one param to it? So i can use 1%++% to get 2 ,a-2 , a%++% to get a-3 . It seems that the operator overwrite system in R, must pass two params. Is it true? -- PO SU mail: desolato...@163.com Majored in Statistics from SJTU At 2014-10-18 00:54:40, Greg Snow 538...@gmail.com wrote: You may be interested in looking at Reference Classes/objects (see ?setRefClass). This is a form of OO programming that is more similar to C++ and Java. You could create a counter object that you could then increment with syntax like: x$inc() x$inc(5) The first would increment by the default (1), the second would then increment by 5. On Fri, Oct 17, 2014 at 2:06 AM, PO SU rhelpmaill...@163.com wrote: Tks for your alternative way's details. but like you mentioned in graphics package, i still wonder how to overload an operator which can pass one param like +2 . There seems exists some examples for my needing. But i try to find them but without any results. can you show me some examples from it? -- PO SU mail: desolato...@163.com Majored in Statistics from SJTU At 2014-10-17 15:16:47, David Winsemius dwinsem...@comcast.net wrote: On Oct 16, 2014, at 10:36 PM, PO SU wrote: Tks for your advice, let the ++ problem alone, how to write an Unary operator ? Is it permitted in R? suchasa-2 , a%+2% will let a be 4 . OK, that's just wrong. Oh, OK, just for fun, as it were: inc - function(x) { eval.parent(substitute(x - x + 1)) } inc(10) Error in 10 - 10 + 1 : invalid (do_set) left-hand side to assignment y=10 inc(y) y [1] 11 I just want to know it , i won't pollute r with it , because i know what is r . : ) It's certainly permitted. Just look at all the overloadings of the + operator in graphics packages. Look up the documentation on methods in R. Why not just use a well-behaved function, though? .inc - function(x) x+1 .inc(10) [1] 11 Then you won't be tempted to try 10 - .inc(10) because it just wouldn't make sense. -- David. -- PO SU mail: desolato...@163.com Majored in Statistics from SJTU At 2014-10-17 13:09:47, Rolf Turner r.tur...@auckland.ac.nz wrote: On 17/10/14 17:29, PO SU wrote: Dear expeRts, Now i want to know how to implement an Unary operator like i++ in cpp's synax form. e.g. 2++ will let 2 be 3 , a-2 ,a++ ,will let a be 3 I tried this : '%++%'-function(x){ x-x+1 } but it have problem, the biggest one is it seems the function need twoparams like a%++%b , how to write a function needing just one param? TKS ! Just ***DON'T***. The ++ operator is useful only for those wish to write code which is obscure to the point of incomprehensibility. It makes C and its offspring write only languages. If you are going to use R, use R and don't pollute it with such abominations. cheers, Rolf Turner -- Rolf Turner Technical Editor ANZJS __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. David Winsemius, MD Alameda, CA, USA __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. -- Gregory (Greg) L. Snow Ph.D. 538...@gmail.com __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
[R] How to read tif format file?
Dear expeRts, I want to read a a.tif file into R. When i try this: readGDAL(a.tif), i get the following error: a.tif has GDAL driver GTiff and has 7200 rows and 7200 columns error: can't allocate 395.5 mb vector but i can GDAL.open(a.tif) it. SO what's wrong with readGDAL? -- PO SU mail: desolato...@163.com Majored in Statistics from SJTU __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
[R] HOW to call R code from matlab?
Dear expeRts, I am fammilar with matlab , i want to call some r codes from it , what can i refer? I tried R.matlab. But it seems can't work well. so, do you have any other suggestions? -- PO SU mail: desolato...@163.com Majored in Statistics from SJTU __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
[R] how to judge a virable is a integer?
Dear usRers, I want to judge virable is or not a integer? e.g. is.integer(1) FALSE because it is a numeric, but i want it's true. as.integer may not be used. because i don't know a is 1 or 1.1. -- PO SU mail: desolato...@163.com Majored in Statistics from SJTU __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] how to judge a virable is a integer?
But i use a-10/b , b is some value ,may be 5, maybe 5.5 not in the form xxL ,so how can i do in the situation to judge a ? -- PO SU mail: desolato...@163.com Majored in Statistics from SJTU At 2014-10-18 18:58:48, Berend Hasselman b...@xs4all.nl wrote: On 18-10-2014, at 12:41, PO SU rhelpmaill...@163.com wrote: Dear usRers, I want to judge virable is or not a integer? e.g. is.integer(1) FALSE because it is a numeric, but i want it's true. as.integer may not be used. because i don't know a is 1 or 1.1. is.integer is surely what you need if you wish to test if a variable is integer. See this # a - 1 # b - 1L # is.integer(a) [1] FALSE # is.integer(b) [1] TRUE See the help for is.integer to see how you can test for a wholenumber, which might be what you want. Berend __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] how to judge a virable is a integer?
It's due to that, 1 is a numeric, 1.2 is a numeric, though it's true. but deeply, when i want to know 1 is an integer, there seems no easy way to get the answer. So, is there anyone happen to know it? -- PO SU mail: desolato...@163.com Majored in Statistics from SJTU At 2014-10-18 20:10:09, S Ellison s.elli...@lgcgroup.com wrote: But i use a-10/b , b is some value ,may be 5, maybe 5.5 If you do floating point arithmetic on integers you'll usually get floating point answers, including the 5.0. See FAQ 7.31 for the usual floating point problem, and ?all.equal for the usual answer to it. You could see if a result is close to an integer by,for example, using all.equal to compare it to itself after rounding. S *** This email and any attachments are confidential. Any use, copying or disclosure other than by the intended recipient is unauthorised. If you have received this message in error, please notify the sender immediately via +44(0)20 8943 7000 or notify postmas...@lgcgroup.com and delete this message and any copies from your computer and network. LGC Limited. Registered in England 2991879. Registered office: Queens Road, Teddington, Middlesex, TW11 0LY, UK __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] how to judge a virable is a integer?
Tks for your help, after investigate in your link, i find there seems three ways can be adoped: 1. is.wholenumber - function(x, tol = .Machine$double.eps^0.5) abs(x - round(x)) tol) e.g. is.wholenumber(1) 2. x%%1==0 3. all.equal(a, as.integer(a)) and also included your last suggestion using floor. and also tks for other helpers! -- PO SU mail: desolato...@163.com Majored in Statistics from SJTU At 2014-10-18 22:48:15, Sergio Fonda sergio.fond...@gmail.com wrote: Sorry for my previous hurry misunderstanding. Try this link: http://stackoverflow.com/questions/3476782/how-to-check-if-the-number-is-integer 2014-10-18 16:25 GMT+02:00 PO SU rhelpmaill...@163.com: It's due to that, 1 is a numeric, 1.2 is a numeric, though it's true. but deeply, when i want to know 1 is an integer, there seems no easy way to get the answer. So, is there anyone happen to know it? -- PO SU mail: desolato...@163.com Majored in Statistics from SJTU At 2014-10-18 20:10:09, S Ellison s.elli...@lgcgroup.com wrote: But i use a-10/b , b is some value ,may be 5, maybe 5.5 If you do floating point arithmetic on integers you'll usually get floating point answers, including the 5.0. See FAQ 7.31 for the usual floating point problem, and ?all.equal for the usual answer to it. You could see if a result is close to an integer by,for example, using all.equal to compare it to itself after rounding. S *** This email and any attachments are confidential. Any use, copying or disclosure other than by the intended recipient is unauthorised. If you have received this message in error, please notify the sender immediately via +44(0)20 8943 7000 or notify postmas...@lgcgroup.com and delete this message and any copies from your computer and network. LGC Limited. Registered in England 2991879. Registered office: Queens Road, Teddington, Middlesex, TW11 0LY, UK __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] how to overwrite a Unary operator ?
Tks for your alternative way's details. but like you mentioned in graphics package, i still wonder how to overload an operator which can pass one param like +2 . There seems exists some examples for my needing. But i try to find them but without any results. can you show me some examples from it? -- PO SU mail: desolato...@163.com Majored in Statistics from SJTU At 2014-10-17 15:16:47, David Winsemius dwinsem...@comcast.net wrote: On Oct 16, 2014, at 10:36 PM, PO SU wrote: Tks for your advice, let the ++ problem alone, how to write an Unary operator ? Is it permitted in R? suchasa-2 , a%+2% will let a be 4 . OK, that's just wrong. Oh, OK, just for fun, as it were: inc - function(x) { eval.parent(substitute(x - x + 1)) } inc(10) Error in 10 - 10 + 1 : invalid (do_set) left-hand side to assignment y=10 inc(y) y [1] 11 I just want to know it , i won't pollute r with it , because i know what is r . : ) It's certainly permitted. Just look at all the overloadings of the + operator in graphics packages. Look up the documentation on methods in R. Why not just use a well-behaved function, though? .inc - function(x) x+1 .inc(10) [1] 11 Then you won't be tempted to try 10 - .inc(10) because it just wouldn't make sense. -- David. -- PO SU mail: desolato...@163.com Majored in Statistics from SJTU At 2014-10-17 13:09:47, Rolf Turner r.tur...@auckland.ac.nz wrote: On 17/10/14 17:29, PO SU wrote: Dear expeRts, Now i want to know how to implement an Unary operator like i++ in cpp's synax form. e.g. 2++ will let 2 be 3 , a-2 ,a++ ,will let a be 3 I tried this : '%++%'-function(x){ x-x+1 } but it have problem, the biggest one is it seems the function need twoparams like a%++%b , how to write a function needing just one param? TKS ! Just ***DON'T***. The ++ operator is useful only for those wish to write code which is obscure to the point of incomprehensibility. It makes C and its offspring write only languages. If you are going to use R, use R and don't pollute it with such abominations. cheers, Rolf Turner -- Rolf Turner Technical Editor ANZJS __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. David Winsemius, MD Alameda, CA, USA __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
[R] how to overwrite a Unary operator ?
Dear expeRts, Now i want to know how to implement an Unary operator like i++ in cpp's synax form. e.g. 2++ will let 2 be 3 , a-2 ,a++ ,will let a be 3 I tried this : '%++%'-function(x){ x-x+1 } but it have problem, the biggest one is it seems the function need two params like a%++%b , how to write a function needing just one param? TKS ! -- PO SU mail: desolato...@163.com Majored in Statistics from SJTU __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] how to overwrite a Unary operator ?
Tks for your advice, let the ++ problem alone, how to write an Unary operator ? Is it permitted in R? suchas a-2 , a%+2% will let a be 4 . I just want to know it , i won't pollute r with it , because i know what is r . : ) -- PO SU mail: desolato...@163.com Majored in Statistics from SJTU At 2014-10-17 13:09:47, Rolf Turner r.tur...@auckland.ac.nz wrote: On 17/10/14 17:29, PO SU wrote: Dear expeRts, Now i want to know how to implement an Unary operator like i++ in cpp's synax form. e.g. 2++ will let 2 be 3 , a-2 ,a++ ,will let a be 3 I tried this : '%++%'-function(x){ x-x+1 } but it have problem, the biggest one is it seems the function need twoparams like a%++%b , how to write a function needing just one param? TKS ! Just ***DON'T***. The ++ operator is useful only for those wish to write code which is obscure to the point of incomprehensibility. It makes C and its offspring write only languages. If you are going to use R, use R and don't pollute it with such abominations. cheers, Rolf Turner -- Rolf Turner Technical Editor ANZJS __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
[R] how to ajust y-axis values in plot() ?
Dear helpeRs, I want to plot( 11:20 ) in a plot. if i just type the code above, the y value will be from 11 to 20, now i want the value from a given range like 0 to 40, how can i do it? I read ?plot for a while but still can't solve it. Actually, the qustion is founded when i already plot a plot like plot(11:20) , but when i abline(h=40), i found it will go out of the plot even after i used abline(h=40,xpd=T). SO, may you help me? -- PO SU mail: desolato...@163.com Majored in Statistics from SJTU __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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] Not related with R, but i want to jion in a statistics help maillist, can you tell me some ?
Dear usRers, I have some statistic problems, and i want to join a Professional maillist for it. can you tell me some maillists?TKS! -- PO SU mail: desolato...@163.com Majored in Statistics from SJTU __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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] complain about a[-integer(0)]
Dear helpeRs, let a - 1:10 let b - integer(0) first, then i will randomly write a integer differently in the range(1,10) or NULL into b. for supposed 5 times. then i want to get a[-b],that means i not want the values at index b. if any time of 5 times generate a integer, it works fine. but when all the 5 times generate NULL, it can't work! Because of the a[-integer(0)] =integer(0) . I ask the same question once before, now i encount it again, i think a[-integer(0)] should return a not integer(0) ! Is any one have the same idea with me ? or give me a oppisite case that a[-integer(0)] need to be integer(0) ? -- PO SU mail: desolato...@163.com Majored in Statistics from SJTU __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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] complain about a[-integer(0)]
Tks, i have to do it. -- PO SU mail: desolato...@163.com Majored in Statistics from SJTU At 2014-10-11 17:57:40, Jim Lemon j...@bitwrit.com.au wrote: On Sat, 11 Oct 2014 05:25:14 PM PO SU wrote: Dear helpeRs, let a - 1:10 let b - integer(0) first, then i will randomly write a integer differently in the range(1,10) or NULL into b. for supposed 5 times. then i want to get a[-b],that means i not want the values at index b. if any time of 5 times generate a integer, it works fine. but when all the 5 times generate NULL, it can't work! Because of the a[-integer(0)] =integer(0) . I ask the same question once before, now i encount it again, i think a[-integer(0)] should return a not integer(0) ! Is any one have the same idea with me ? or give me a oppisite case that a[-integer(0)] need to be integer(0) ? Hi PO SU, How about: if(length(b)) a-a[-b] Jim [[alternative HTML version deleted]] __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] how to break the loop using sapply?
Is that mean while may be more effient than for in R? as i know, while and for are all just functions in R. Tks for your suggestion to not use apply that way, but i want to know, if possible, is there any way to break it ? Actually, there is a additional question: x- c(3,4,5,6,9) sapply(x ,function(i){ foo(i) #do something to each value in x,how can i know the i's index in x? )} In my way , i always sapply(seq(x),function(i){ foo(x[i]) }) or Map( function(i,index){ foo(i) # through index to know the i's index in x },x ,seq(x)) How you solve the problem? I mean just use apply functions. -- PO SU mail: desolato...@163.com Majored in Statistics from SJTU At 2014-10-10 13:58:29, Jeff Newmiller jdnew...@dcn.davis.ca.us wrote: Don't use apply functions if you want to do what you describe. They don't work that way. Use a while control structure. --- 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 October 9, 2014 10:24:49 PM PDT, PO SU rhelpmaill...@163.com wrote: Dear expeRts, i use sapply for loop, and i want to break it when i needed, how to do that? e.g. sapply( 1:10, function(i) { if(i==5) break and jump out of the function sapply } ) I want to do it because i have to loop 100 times, but i don't know when it will break, that means, it may need break at i=5 or at i=5, for the possible of the last case, i don't use for loop, because it slow(is it right?). So,if you happen to know it ,may you help me? -- PO SU mail: desolato...@163.com Majored in Statistics from SJTU __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] how to break the loop using sapply?
OK, it seems that i misunderstand something, i forget how and when i pick up the monition in my mind that as possible as avoid using for loop. TKS for all your suggestions! But i still want the way to break sapply, if not exsits now, create it . such as: sapply-function(...){ out-FALSE . if(out==TRUE) return } sapply(1:10, function(i){ if(i=5) out-TRUE } ) That means to rewrite sapply, and create a virable in it , let called OUT, then mayebe in sapply(1:10,FUN) FUN can use OUT. because i think in sapply, FUN is an inner function,so it can use OUT. when it let OUT=TRUE. sapply should be break.. -- PO SU mail: desolato...@163.com Majored in Statistics from SJTU At 2014-10-10 14:44:47, Hervé Pagès hpa...@fhcrc.org wrote: Hi, On 10/09/2014 11:12 PM, PO SU wrote: Is that mean while may be more effient than for in R? as i know, while and for are all just functions in R. Tks for your suggestion to not use apply that way, but i want to know, if possible, is there any way to break it ? As Jeff said, you cannot break the loop that happens inside the sapply() call. Also it is *not* true that for or while are less efficient than sapply() or lapply(): a - numeric(10) system.time(for (i in 1:10) {a[i] - i * (i - 1) / 2}) user system elapsed 0.148 0.000 0.147 system.time(b - sapply(1:10, function(i) {i * (i - 1) / 2})) user system elapsed 0.194 0.007 0.201 identical(a, b) [1] TRUE system.time(c - unlist(lapply(1:10, function(i) {i * (i - 1) / 2}))) user system elapsed 0.116 0.000 0.119 identical(a, c) [1] TRUE OK lapply() is maybe slightly faster but not significantly. And the more work you need to do inside the loop, the less significant this difference will be. Actually, there is a additional question: x- c(3,4,5,6,9) sapply(x ,function(i){ foo(i) #do something to each value in x,how can i know the i's index in x? )} You can't. Inside the anonymous function, you only have access to 'i' which is an element of 'x', not its index in 'x'. In my way , i always sapply(seq(x),function(i){ foo(x[i]) }) Yes, if you want to loop on the index instead of the elements, you need to do something like that. Using seq_along(x) is probably cleaner than seq(x) for this. Cheers, H. or Map( function(i,index){ foo(i) # through index to know the i's index in x },x ,seq(x)) How you solve the problem? I mean just use apply functions. -- PO SU mail: desolato...@163.com Majored in Statistics from SJTU At 2014-10-10 13:58:29, Jeff Newmiller jdnew...@dcn.davis.ca.us wrote: Don't use apply functions if you want to do what you describe. They don't work that way. Use a while control structure. --- 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 October 9, 2014 10:24:49 PM PDT, PO SU rhelpmaill...@163.com wrote: Dear expeRts, i use sapply for loop, and i want to break it when i needed, how to do that? e.g. sapply( 1:10, function(i) { if(i==5) break and jump out of the function sapply } ) I want to do it because i have to loop 100 times, but i don't know when it will break, that means, it may need break at i=5 or at i=5, for the possible of the last case, i don't use for loop, because it slow(is it right?). So,if you happen to know it ,may you help me? -- PO SU mail: desolato...@163.com Majored in Statistics from SJTU __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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. -- Hervé Pagès Program in Computational Biology Division of Public Health Sciences Fred Hutchinson Cancer Research Center 1100 Fairview Ave. N, M1-B514 P.O. Box 19024 Seattle, WA 98109-1024 E-mail: hpa...@fhcrc.org Phone: (206) 667-5791 Fax:(206) 667-1319 __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide
Re: [R] Count number of Fridays in a month
In my Impression, there seems exsits a function (let just call weekday) which can return a POSIXlt format date 's weekday. That means, weekday( 31-may-2014 ) may return the right weekday maybe 5, so a clumsy method is start to judge from 1-may-2014 to 31-may-2014 , you get a vector x, sum(which(x==5)) should return the right number. so do the April-2014. FOR MORE EFFICIENT, may be you should look into the function weekday ( not the true name) to get how it work ,it may help you do less things to get what you want. FOR weekday,sorry for my forgot of where it located, it may in ?POSIXlt ?format ? strptime and other related keywords's document. -- PO SU mail: desolato...@163.com Majored in Statistics from SJTU At 2014-10-10 19:44:17, Duncan Murdoch murdoch.dun...@gmail.com wrote: On 10/10/2014, 7:28 AM, Abhinaba Roy wrote: Hi R helpers, I want to write a function which will 1. Count the number of fridays in the current month ( to extract month from given date) and also the number of fridays in the preceeding month 2. Calculate the ratio of the number of fridays in current month to the number of fridays in the precceding month 3. Return a integer value calculated as ifelse(ratio1,1,ifesle(ration1,-1),0) The date which is passed is in the format *'31-may-2014'* So, given the date '31-may-2014' Number of fridays in May2014 = 5 Number of fridays in Apr2014 = 4 Ratio = 5/4 1 Hence, the function will return a value 1 I want to call the function by passing '31-may-2014' as an argument How can this be done in R? Any help will be appreciated Convert your string to a POSIXlt object using as.POSIXlt. Then you can extract year, month and weekday from the result, and go from there. (The only unobvious part is figuring out how many days are in each month, but there are questions online giving various ways to do this.) 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-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
[R] how to break the loop using sapply?
Dear expeRts, i use sapply for loop, and i want to break it when i needed, how to do that? e.g. sapply( 1:10, function(i) { if(i==5) break and jump out of the function sapply } ) I want to do it because i have to loop 100 times, but i don't know when it will break, that means, it may need break at i=5 or at i=5, for the possible of the last case, i don't use for loop, because it slow(is it right?). So,if you happen to know it ,may you help me? -- PO SU mail: desolato...@163.com Majored in Statistics from SJTU __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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] simulation data in SEM
PLZ mke sure the package installed which contains mvrnorm function. -- PO SU mail: desolato...@163.com Majored in Statistics from SJTU At 2014-09-14 09:56:34, thanoon younis thanoon.youni...@gmail.com wrote: Dear R members I want to simulate data depending on SEM and when i applied the code below i found some errors and i still cannot run it. many thanks in advance Thanoon #Do simulation for 100 replications N-1000; P-10 phi-matrix(data=c(1.0,0.3,0.3,1.0),ncol=2) #The covariance matrix of xi Ro-matrix(data=c(7.0,2.1,2.1,7.0), ncol=2) yo-matrix(data=NA,nrow=N,ncol=P) p-numeric(P); v-numeric(P) for (t in 1:100) { #Generate the data for the simulation study for (i in 1:N) { #Generate xi xi-mvrnorm(1,mu=c(0,0),phi) #Generate the fixed covariates co-rnorm(1,0,1) #Generate error term is structural equation delta-rnorm(1,0,sqrt(0.3)) #Generate eta1 according to the structural equation eta-0.8*co[i]+0.6*xi[1]+0.6*xi[2]+0.8*xi[1]*xi[2]+delta #Generate error terms in measurement equations eps-rnorm(3,0,1) #Generate theta according to measurement equations v1[1]-1.0+eta+eps[1]; v1[2]-1.0+0.7*eta+eps[2] v1[3]-1.0+0.7*eta+eps[3] v1[4]-1.0+xi[1]; v1[5]-1.0+0.8*xi[1]; v1[6]-1.0+0.8*xi[1] v1[7]-1.0+xi[2]; v1[8]-1.0+0.7*xi[2]; v1[9]-1.0+0.7*xi[2]; v1[10]-1.0+0.7*xi1[2] #transform theta to orinal variables for (j in 1:10) { if (v[j]0) yo[i,j]-1 else yo[i,j]-0 } #Input data set for WinBUGS data-list(N=200,P=10,R=Ro,z=yo) } #end [[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 pdf(file=) encount a Chinese garbled
Tks, it works now , just needing some extra ajustment. -- PO SU mail: desolato...@163.com Majored in Statistics from SJTU At 2014-09-12 12:33:19, Jinsong Zhao jsz...@yeah.net wrote: On 2014/9/11 21:10, PO SU wrote: Dear expeRts, When i use the following codes: pdf(file=1.pdf,width=15) plot(1:3,main=你好) dev.off() #There were 12 warnings (use warnings() to see them) I find that 你好 can't show correctly in pdf file, but i just plot(1:3,main=你好) to R plot viewer, it's ok . Is there anyone happen to know the solution? BTW, i explore the encoding argument in ?pdf ,but still can't solve the problem. please refer to: Paul Murrell and Brian Ripley (2006) Non-standard fonts in PostScript and PDF graphics. R News, 6(2):41–47. http://cran.r-project.org/doc/Rnews/Rnews_2006-2.pdf if you can read Chinese, you also can refer to: http://www.newsmth.net/bbscon.php?bid=1039id=3924 HTH, Jinsong -- PO SU mail: desolato...@163.com Majored in Statistics from SJTU __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
[R] unable to move temporary installation when install some packages
Dear expeRts, These days i and some of my friends often encount the same problem when installing packages, e.g. when i try to install.packages(stringi), i will get : package ‘stringi’ successfully unpacked and MD5 sums checked Warning in install.packages : unable to move temporary installation ‘C:\Program Files\R\library\file28744050180\stringi’ to ‘C:\Program Files\R\library\stringi’ The downloaded binary packages are in C:\Users\po.su\AppData\Local\Temp\RtmpeobZut\downloaded_packages But when i try to install some other packages, it is ok,like ggplot2,but my friends encount the same problem with ggplot2 like stringi for me. we all use windows 7, and the latest version of Rstudio with R 3.1.1. We investgate it, open the path dir 's modify permissions, it works for some packages,but for packages like Rcpp, the problem still come! Is there some one happen to know the solution? -- PO SU mail: desolato...@163.com Majored in Statistics from SJTU __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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] some question about vector[-NULL]
It really suprise me that a[-c(0,1,2)] works as a[-c(1,2)]. But, unfortunately, a[-0] still can't work . That 's mean: i want: a-1:3 a[-0] 1 2 3 or a[-NULL] 1 2 3 -- PO SU mail: desolato...@163.com Majored in Statistics from SJTU At 2014-09-11 02:24:25, PIKAL Petr petr.pi...@precheza.cz wrote: Hi You still do not disclose important info about details of your functions. However, when you want to perform indexing like you show, you maybe can get rid of NULL and use zero instead. a-1:5 a[-c(1,3)] [1] 2 4 5 a[-c(0,1,3)] [1] 2 4 5 a[-c(1,0,3)] [1] 2 4 5 a[-c(0,1,0,3,0)] [1] 2 4 5 However I am almost sure that you are fishing in murky waters and what you do by cycle and fiddling with NULL elements can be achieved by more efficiently. Regards Petr -Original Message- From: r-help-boun...@r-project.org [mailto:r-help-bounces@r- project.org] On Behalf Of PO SU Sent: Thursday, September 11, 2014 3:54 AM To: Duncan Murdoch Cc: R. Help Subject: Re: [R] some question about vector[-NULL] Tks, i think using logical index is a way, but to do that, i have to keep a vector as long as the original vector. that's, to exclude position 1 and 3 from a-1:5 I have to let b-c(F,T,F,T,T) and exec a[b], not a[-c(1,3)]. which c(1,3) is much shorter than b if a is a long vector. that's, b would be c(F,T,F,T,T,T,T,..,T) I thought a way , let d-c(a,1) that d-c(1,2,3,4,5,1) and initialize the index vector iv to length(d). that is iv-6. then, d[-iv] is always equal a[- i ] , whether i is NULL or not. Because if i is NULL ,then iv is 6, if i is 2.then iv is c(2,6) and so on... -- PO SU mail: desolato...@163.com Majored in Statistics from SJTU At 2014-09-11 01:58:46, Duncan Murdoch murdoch.dun...@gmail.com wrote: On 10/09/2014 12:20 PM, William Dunlap wrote: Can you make your example a bit more concrete? E.g., is your 'index vector' A an integer vector? If so, integer(0), an integer vector with no elements, would be a more reasonable return value than NULL, an object of class NULL with length 0, for the 'not found' case and you could check for that case by asking if length(A)==0. Show us typical inputs and expected outputs for your function (i.e., the problem you want to solve). I think the problem with integer(0) and NULL is the same: a[-i] doesn't act as expected (leaving out all the elements of i, i.e. nothing) if i is either of those. The solution is to use logical indexing, not negative numerical indexing. Duncan Murdoch Bill Dunlap TIBCO Software wdunlap tibco.com On Wed, Sep 10, 2014 at 8:53 AM, PO SU rhelpmaill...@163.com wrote: Tks for your a - list(ress = 1, res = NULL) And in my second question, let me explain it : Actually i have two vectors in global enviroment, called A and B .A is initialized to NULL which used to record some index in B. Then i would run a function F, and each time, i would get a index value or NULL. that's, D-F(B). D would be NULL or some index position in B. But in the function F, though input is B, i would exclude the index value from B recorded in A. That's : F-function( B ) { B-B[-A] some processing... res-NULL or some new index not included in A return(res) } so in a loop, A-NULL for( i in 1:10) { D-F(B) A-c(A,D) } I never know whether D is a NULL or a different index compared with indexes already recorded in A. Actually, A-c(A,D) work well, i never worry about whether D is NULL or a real index, but in the function F, B-B[-A] won't work. so i hope that, e.g. a-1:3 a[-NULL] wouldn't trigger an error but return a. Because, if i wrote function like the following: F-function( B ) { if( is.null(A)) B-B else B-B[-A] some processing... res-NULL or some new index not included in A return(res) } May be after 5 or 10 loops, A would already not NULL, so the added if ..else statement would be repeated in left loops which i would not like to see. -- PO SU mail: desolato...@163.com Majored in Statistics from SJTU At 2014-09-10 06:45:59, Duncan Murdoch murdoch.dun...@gmail.com wrote: On 10/09/2014, 3:21 AM, PO SU wrote: Dear expeRts, I have some programming questions about NULL in R.There are listed as follows: 1. I find i can't let a list have a element NULL: a-list() a$ress-1 a$res-NULL a str(a) You can do it using a - list(ress = 1, res = NULL) How can i know i have a named element but it is NULL, not just get a$,a$,a$ there all get NULL That's a little harder. There are a few ways: res %in% names(a) is.null(a[[res]]) or identical(a[res], list(res = NULL)) or is.null(a[[2]]) should all work. Generally because of the special handling needed, it's a bad idea to try to store NULL in a list. 2
Re: [R] some question about vector[-NULL]
Orignally i don't want to do the if ( length) check because i know that in a 1 loops, after may be 10 or 20 or 100 loops , i will not be empty. so i mean , in the left loops, i would always check something not needed to check which i would not like to do. -- PO SU mail: desolato...@163.com Majored in Statistics from SJTU At 2014-09-11 05:38:12, Duncan Murdoch murdoch.dun...@gmail.com wrote: On 10/09/2014, 9:53 PM, PO SU wrote: Tks, i think using logical index is a way, but to do that, i have to keep a vector as long as the original vector. that's, to exclude position 1 and 3 from a-1:5 I have to let b-c(F,T,F,T,T) and exec a[b], not a[-c(1,3)]. which c(1,3) is much shorter than b if a is a long vector. that's, b would be c(F,T,F,T,T,T,T,..,T) If you know that you want to omit elements 1 and 3, then negative integer indexing is safe. You'll never need to explicitly type out the whole logical vector. The only problem with it is when you construct the indices by tests, and sometimes nothing matches the tests, so you end up with an empty vector or NULL. In that case you can just as easily construct the logical vector. If your vectors are so long that you are worried about the cost of constructing a logical vector that long, then it's probably worthwhile checking the length of the integer index explicitly, i.e. instead of a - a[ -i ] use if (any(i 0)) a - a[ -i ] Duncan Murdoch I thought a way , let d-c(a,1) that d-c(1,2,3,4,5,1) and initialize the index vector iv to length(d). that is iv-6. then, d[-iv] is always equal a[- i ] , whether i is NULL or not. Because if i is NULL ,then iv is 6, if i is 2.then iv is c(2,6) and so on... -- PO SU mail: desolato...@163.com Majored in Statistics from SJTU At 2014-09-11 01:58:46, Duncan Murdoch murdoch.dun...@gmail.com wrote: On 10/09/2014 12:20 PM, William Dunlap wrote: Can you make your example a bit more concrete? E.g., is your 'index vector' A an integer vector? If so, integer(0), an integer vector with no elements, would be a more reasonable return value than NULL, an object of class NULL with length 0, for the 'not found' case and you could check for that case by asking if length(A)==0. Show us typical inputs and expected outputs for your function (i.e., the problem you want to solve). I think the problem with integer(0) and NULL is the same: a[-i] doesn't act as expected (leaving out all the elements of i, i.e. nothing) if i is either of those. The solution is to use logical indexing, not negative numerical indexing. Duncan Murdoch Bill Dunlap TIBCO Software wdunlap tibco.com On Wed, Sep 10, 2014 at 8:53 AM, PO SU rhelpmaill...@163.com wrote: Tks for your a - list(ress = 1, res = NULL) And in my second question, let me explain it : Actually i have two vectors in global enviroment, called A and B .A is initialized to NULL which used to record some index in B. Then i would run a function F, and each time, i would get a index value or NULL. that's, D-F(B). D would be NULL or some index position in B. But in the function F, though input is B, i would exclude the index value from B recorded in A. That's : F-function( B ) { B-B[-A] some processing... res-NULL or some new index not included in A return(res) } so in a loop, A-NULL for( i in 1:10) { D-F(B) A-c(A,D) } I never know whether D is a NULL or a different index compared with indexes already recorded in A. Actually, A-c(A,D) work well, i never worry about whether D is NULL or a real index, but in the function F, B-B[-A] won't work. so i hope that, e.g. a-1:3 a[-NULL] wouldn't trigger an error but return a. Because, if i wrote function like the following: F-function( B ) { if( is.null(A)) B-B else B-B[-A] some processing... res-NULL or some new index not included in A return(res) } May be after 5 or 10 loops, A would already not NULL, so the added if ..else statement would be repeated in left loops which i would not like to see. -- PO SU mail: desolato...@163.com Majored in Statistics from SJTU At 2014-09-10 06:45:59, Duncan Murdoch murdoch.dun...@gmail.com wrote: On 10/09/2014, 3:21 AM, PO SU wrote: Dear expeRts, I have some programming questions about NULL in R.There are listed as follows: 1. I find i can't let a list have a element NULL: a-list() a$ress-1 a$res-NULL a str(a) You can do it using a - list(ress = 1, res = NULL) How can i know i have a named element but it is NULL, not just get a$,a$,a$ there all get NULL That's a little harder. There are a few ways: res %in% names(a) is.null(a[[res]]) or identical(a[res], list(res = NULL)) or is.null(a[[2]]) should all work. Generally because of the special handling needed, it's a bad idea to try to store NULL in a list. 2.The most important thing: a-1:10 b-NULL or 1 a-c(a,b) will work so i don't
Re: [R] some question about vector[-NULL]
Actually, i thought the way: a-1:3 b-NULL or 2 a[-b] will not work if b is NULL A-c(a,1) B-c(b,length(A)) A[-B] will get the same result as if b is NULL get a, if b is 2 get a[-2] I think it works well in considering memory use or efficiency or code tidy. -- PO SU mail: desolato...@163.com Majored in Statistics from SJTU At 2014-09-11 05:59:42, PO SU rhelpmaill...@163.com wrote: Orignally i don't want to do the if ( length) check because i know that in a 1 loops, after may be 10 or 20 or 100 loops , i will not be empty. so i mean , in the left loops, i would always check something not needed to check which i would not like to do. -- PO SU mail: desolato...@163.com Majored in Statistics from SJTU At 2014-09-11 05:38:12, Duncan Murdoch murdoch.dun...@gmail.com wrote: On 10/09/2014, 9:53 PM, PO SU wrote: Tks, i think using logical index is a way, but to do that, i have to keep a vector as long as the original vector. that's, to exclude position 1 and 3 from a-1:5 I have to let b-c(F,T,F,T,T) and exec a[b], not a[-c(1,3)]. which c(1,3) is much shorter than b if a is a long vector. that's, b would be c(F,T,F,T,T,T,T,..,T) If you know that you want to omit elements 1 and 3, then negative integer indexing is safe. You'll never need to explicitly type out the whole logical vector. The only problem with it is when you construct the indices by tests, and sometimes nothing matches the tests, so you end up with an empty vector or NULL. In that case you can just as easily construct the logical vector. If your vectors are so long that you are worried about the cost of constructing a logical vector that long, then it's probably worthwhile checking the length of the integer index explicitly, i.e. instead of a - a[ -i ] use if (any(i 0)) a - a[ -i ] Duncan Murdoch I thought a way , let d-c(a,1) that d-c(1,2,3,4,5,1) and initialize the index vector iv to length(d). that is iv-6. then, d[-iv] is always equal a[- i ] , whether i is NULL or not. Because if i is NULL ,then iv is 6, if i is 2.then iv is c(2,6) and so on... -- PO SU mail: desolato...@163.com Majored in Statistics from SJTU At 2014-09-11 01:58:46, Duncan Murdoch murdoch.dun...@gmail.com wrote: On 10/09/2014 12:20 PM, William Dunlap wrote: Can you make your example a bit more concrete? E.g., is your 'index vector' A an integer vector? If so, integer(0), an integer vector with no elements, would be a more reasonable return value than NULL, an object of class NULL with length 0, for the 'not found' case and you could check for that case by asking if length(A)==0. Show us typical inputs and expected outputs for your function (i.e., the problem you want to solve). I think the problem with integer(0) and NULL is the same: a[-i] doesn't act as expected (leaving out all the elements of i, i.e. nothing) if i is either of those. The solution is to use logical indexing, not negative numerical indexing. Duncan Murdoch Bill Dunlap TIBCO Software wdunlap tibco.com On Wed, Sep 10, 2014 at 8:53 AM, PO SU rhelpmaill...@163.com wrote: Tks for your a - list(ress = 1, res = NULL) And in my second question, let me explain it : Actually i have two vectors in global enviroment, called A and B .A is initialized to NULL which used to record some index in B. Then i would run a function F, and each time, i would get a index value or NULL. that's, D-F(B). D would be NULL or some index position in B. But in the function F, though input is B, i would exclude the index value from B recorded in A. That's : F-function( B ) { B-B[-A] some processing... res-NULL or some new index not included in A return(res) } so in a loop, A-NULL for( i in 1:10) { D-F(B) A-c(A,D) } I never know whether D is a NULL or a different index compared with indexes already recorded in A. Actually, A-c(A,D) work well, i never worry about whether D is NULL or a real index, but in the function F, B-B[-A] won't work. so i hope that, e.g. a-1:3 a[-NULL] wouldn't trigger an error but return a. Because, if i wrote function like the following: F-function( B ) { if( is.null(A)) B-B else B-B[-A] some processing... res-NULL or some new index not included in A return(res) } May be after 5 or 10 loops, A would already not NULL, so the added if ..else statement would be repeated in left loops which i would not like to see. -- PO SU mail: desolato...@163.com Majored in Statistics from SJTU At 2014-09-10 06:45:59, Duncan Murdoch murdoch.dun...@gmail.com wrote: On 10/09/2014, 3:21 AM, PO SU wrote: Dear expeRts, I have some programming questions about NULL in R.There are listed as follows: 1. I find i can't let a list have a element NULL: a-list() a$ress-1 a$res-NULL a str(a) You can do it using a - list(ress = 1, res = NULL) How can i know i have a named element but it is NULL, not just
[R] using pdf(file=) encount a Chinese garbled
Dear expeRts, When i use the following codes: pdf(file=1.pdf,width=15) plot(1:3,main=你好) dev.off() #There were 12 warnings (use warnings() to see them) I find that 你好 can't show correctly in pdf file, but i just plot(1:3,main=你好) to R plot viewer, it's ok . Is there anyone happen to know the solution? BTW, i explore the encoding argument in ?pdf ,but still can't solve the problem. -- PO SU mail: desolato...@163.com Majored in Statistics from SJTU __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] How to use multi paragraph comment like /* and */ in cpp?
Tks for all your help, finally i choose the way in Rstudio ctrl+shift+C, and do twice to cancel those comments. It's enough for me now. BTW, I also like the way: if(FALSE) {} :) -- PO SU mail: desolato...@163.com Majored in Statistics from SJTU At 2014-09-10 02:15:49, Gjalt-Jorn Peters gjalt-j...@behaviorchange.eu wrote: In R-studio, you can also select whatever you want to comment out, and press CTRL-SHIFT-C to comment the selection in one go. To uncomment it all in one go again, you can select it again and press CTRL-SHIFT-C again. Gjalt-Jorn On 2014-09-09 5:51, Pascal Oettli wrote: A workaround is to escape the evaluation of the lines. For example: tt - 0 while(tt 0){ cat('rr\n') } Regards, Pascal On Tue, Sep 9, 2014 at 11:49 AM, PO SU rhelpmaill...@163.com wrote: Dear expeRts, I find it's terrible when i want to comment multi paragraph (e.g. a 30 lines function) , i have to comment each line with #, is there any good way to do that ? I investgate it, but found no easy way, may you help me ? -- PO SU mail: desolato...@163.com Majored in Statistics from SJTU __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
[R] some question about vector[-NULL]
Dear expeRts, I have some programming questions about NULL in R.There are listed as follows: 1. I find i can't let a list have a element NULL: a-list() a$ress-1 a$res-NULL a str(a) How can i know i have a named element but it is NULL, not just get a$,a$,a$ there all get NULL 2.The most important thing: a-1:10 b-NULL or 1 a-c(a,b) will work so i don't need to know whether b is null or not,but: a[-NULL] can't work!! i just need a[-NULL]==a , how can i reach this purpose? -- PO SU mail: desolato...@163.com Majored in Statistics from SJTU __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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] some question about vector[-NULL]
Tks for your a - list(ress = 1, res = NULL) And in my second question, let me explain it : Actually i have two vectors in global enviroment, called A and B .A is initialized to NULL which used to record some index in B. Then i would run a function F, and each time, i would get a index value or NULL. that's, D-F(B). D would be NULL or some index position in B. But in the function F, though input is B, i would exclude the index value from B recorded in A. That's : F-function( B ) { B-B[-A] some processing... res-NULL or some new index not included in A return(res) } so in a loop, A-NULL for( i in 1:10) { D-F(B) A-c(A,D) } I never know whether D is a NULL or a different index compared with indexes already recorded in A. Actually, A-c(A,D) work well, i never worry about whether D is NULL or a real index, but in the function F, B-B[-A] won't work. so i hope that, e.g. a-1:3 a[-NULL] wouldn't trigger an error but return a. Because, if i wrote function like the following: F-function( B ) { if( is.null(A)) B-B else B-B[-A] some processing... res-NULL or some new index not included in A return(res) } May be after 5 or 10 loops, A would already not NULL, so the added if ..else statement would be repeated in left loops which i would not like to see. -- PO SU mail: desolato...@163.com Majored in Statistics from SJTU At 2014-09-10 06:45:59, Duncan Murdoch murdoch.dun...@gmail.com wrote: On 10/09/2014, 3:21 AM, PO SU wrote: Dear expeRts, I have some programming questions about NULL in R.There are listed as follows: 1. I find i can't let a list have a element NULL: a-list() a$ress-1 a$res-NULL a str(a) You can do it using a - list(ress = 1, res = NULL) How can i know i have a named element but it is NULL, not just get a$,a$,a$ there all get NULL That's a little harder. There are a few ways: res %in% names(a) is.null(a[[res]]) or identical(a[res], list(res = NULL)) or is.null(a[[2]]) should all work. Generally because of the special handling needed, it's a bad idea to try to store NULL in a list. 2.The most important thing: a-1:10 b-NULL or 1 a-c(a,b) will work so i don't need to know whether b is null or not,but: a[-NULL] can't work!! i just need a[-NULL]==a , how can i reach this purpose? Using !, and a logical test, e.g. a[!nullentry(a)] where nullentry() is a function based on one of the tests above, but applied to all entries. 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] some question about vector[-NULL]
May be i could add a extra elment to B,that's: F-function( C ) { C-C[-A] some processing... res-NULL or some new index not included in A return(res) } so in a loop, C-c(B,1) tmpindex-length(C) A-tmpindex for( i in 1:10) { D-F(C) A-c(A,D) } -- PO SU mail: desolato...@163.com Majored in Statistics from SJTU At 2014-09-10 11:53:01, PO SU rhelpmaill...@163.com wrote: Tks for your a - list(ress = 1, res = NULL) And in my second question, let me explain it : Actually i have two vectors in global enviroment, called A and B .A is initialized to NULL which used to record some index in B. Then i would run a function F, and each time, i would get a index value or NULL. that's, D-F(B). D would be NULL or some index position in B. But in the function F, though input is B, i would exclude the index value from B recorded in A. That's : F-function( B ) { B-B[-A] some processing... res-NULL or some new index not included in A return(res) } so in a loop, A-NULL for( i in 1:10) { D-F(B) A-c(A,D) } I never know whether D is a NULL or a different index compared with indexes already recorded in A. Actually, A-c(A,D) work well, i never worry about whether D is NULL or a real index, but in the function F, B-B[-A] won't work. so i hope that, e.g. a-1:3 a[-NULL] wouldn't trigger an error but return a. Because, if i wrote function like the following: F-function( B ) { if( is.null(A)) B-B else B-B[-A] some processing... res-NULL or some new index not included in A return(res) } May be after 5 or 10 loops, A would already not NULL, so the added if ..else statement would be repeated in left loops which i would not like to see. -- PO SU mail: desolato...@163.com Majored in Statistics from SJTU At 2014-09-10 06:45:59, Duncan Murdoch murdoch.dun...@gmail.com wrote: On 10/09/2014, 3:21 AM, PO SU wrote: Dear expeRts, I have some programming questions about NULL in R.There are listed as follows: 1. I find i can't let a list have a element NULL: a-list() a$ress-1 a$res-NULL a str(a) You can do it using a - list(ress = 1, res = NULL) How can i know i have a named element but it is NULL, not just get a$,a$,a$ there all get NULL That's a little harder. There are a few ways: res %in% names(a) is.null(a[[res]]) or identical(a[res], list(res = NULL)) or is.null(a[[2]]) should all work. Generally because of the special handling needed, it's a bad idea to try to store NULL in a list. 2.The most important thing: a-1:10 b-NULL or 1 a-c(a,b) will work so i don't need to know whether b is null or not,but: a[-NULL] can't work!! i just need a[-NULL]==a , how can i reach this purpose? Using !, and a logical test, e.g. a[!nullentry(a)] where nullentry() is a function based on one of the tests above, but applied to all entries. 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-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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] some question about vector[-NULL]
Tks, i think using logical index is a way, but to do that, i have to keep a vector as long as the original vector. that's, to exclude position 1 and 3 from a-1:5 I have to let b-c(F,T,F,T,T) and exec a[b], not a[-c(1,3)]. which c(1,3) is much shorter than b if a is a long vector. that's, b would be c(F,T,F,T,T,T,T,..,T) I thought a way , let d-c(a,1) that d-c(1,2,3,4,5,1) and initialize the index vector iv to length(d). that is iv-6. then, d[-iv] is always equal a[- i ] , whether i is NULL or not. Because if i is NULL ,then iv is 6, if i is 2.then iv is c(2,6) and so on... -- PO SU mail: desolato...@163.com Majored in Statistics from SJTU At 2014-09-11 01:58:46, Duncan Murdoch murdoch.dun...@gmail.com wrote: On 10/09/2014 12:20 PM, William Dunlap wrote: Can you make your example a bit more concrete? E.g., is your 'index vector' A an integer vector? If so, integer(0), an integer vector with no elements, would be a more reasonable return value than NULL, an object of class NULL with length 0, for the 'not found' case and you could check for that case by asking if length(A)==0. Show us typical inputs and expected outputs for your function (i.e., the problem you want to solve). I think the problem with integer(0) and NULL is the same: a[-i] doesn't act as expected (leaving out all the elements of i, i.e. nothing) if i is either of those. The solution is to use logical indexing, not negative numerical indexing. Duncan Murdoch Bill Dunlap TIBCO Software wdunlap tibco.com On Wed, Sep 10, 2014 at 8:53 AM, PO SU rhelpmaill...@163.com wrote: Tks for your a - list(ress = 1, res = NULL) And in my second question, let me explain it : Actually i have two vectors in global enviroment, called A and B .A is initialized to NULL which used to record some index in B. Then i would run a function F, and each time, i would get a index value or NULL. that's, D-F(B). D would be NULL or some index position in B. But in the function F, though input is B, i would exclude the index value from B recorded in A. That's : F-function( B ) { B-B[-A] some processing... res-NULL or some new index not included in A return(res) } so in a loop, A-NULL for( i in 1:10) { D-F(B) A-c(A,D) } I never know whether D is a NULL or a different index compared with indexes already recorded in A. Actually, A-c(A,D) work well, i never worry about whether D is NULL or a real index, but in the function F, B-B[-A] won't work. so i hope that, e.g. a-1:3 a[-NULL] wouldn't trigger an error but return a. Because, if i wrote function like the following: F-function( B ) { if( is.null(A)) B-B else B-B[-A] some processing... res-NULL or some new index not included in A return(res) } May be after 5 or 10 loops, A would already not NULL, so the added if ..else statement would be repeated in left loops which i would not like to see. -- PO SU mail: desolato...@163.com Majored in Statistics from SJTU At 2014-09-10 06:45:59, Duncan Murdoch murdoch.dun...@gmail.com wrote: On 10/09/2014, 3:21 AM, PO SU wrote: Dear expeRts, I have some programming questions about NULL in R.There are listed as follows: 1. I find i can't let a list have a element NULL: a-list() a$ress-1 a$res-NULL a str(a) You can do it using a - list(ress = 1, res = NULL) How can i know i have a named element but it is NULL, not just get a$,a$,a$ there all get NULL That's a little harder. There are a few ways: res %in% names(a) is.null(a[[res]]) or identical(a[res], list(res = NULL)) or is.null(a[[2]]) should all work. Generally because of the special handling needed, it's a bad idea to try to store NULL in a list. 2.The most important thing: a-1:10 b-NULL or 1 a-c(a,b) will work so i don't need to know whether b is null or not,but: a[-NULL] can't work!! i just need a[-NULL]==a , how can i reach this purpose? Using !, and a logical test, e.g. a[!nullentry(a)] where nullentry() is a function based on one of the tests above, but applied to all entries. 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-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] How to use multi paragraph comment like /* and */ in cpp?
I don't understand what's your meaning, do you mean that i should do some file processing,(like writing a script) ,so that i could add # in any line i wanted. I think it is not convenient. And, it does seems that there is no way to multi line comment in R. But when i turn to using Rstudio, after lots trying, i find that ctrl+shift+C can do the thing. Also i investgate roxygen, but it seems needing to learn the whole package , if some one happen to know how to do in roxygen, may you give me a quick reference? -- PO SU mail: desolato...@163.com Majored in Statistics from SJTU At 2014-09-09 11:51:21, Pascal Oettli kri...@ymail.com wrote: A workaround is to escape the evaluation of the lines. For example: tt - 0 while(tt 0){ cat('rr\n') } Regards, Pascal On Tue, Sep 9, 2014 at 11:49 AM, PO SU rhelpmaill...@163.com wrote: Dear expeRts, I find it's terrible when i want to comment multi paragraph (e.g. a 30 lines function) , i have to comment each line with #, is there any good way to do that ? I investgate it, but found no easy way, may you help me ? -- PO SU mail: desolato...@163.com Majored in Statistics from SJTU __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. -- Pascal Oettli Project Scientist JAMSTEC Yokohama, Japan __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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 edit to extract codes from vignette failed
Tks for correcting me not using the file argument, but the codes you supply seem still not work. edit(vignette(grobs,package = grid)) can't work. I am using win7, the latest version of Rstudio which using R.3.1.1.The error is: Error in editor(file = file, title = title) : argument name is missing, with no default -- PO SU mail: desolato...@163.com Majored in Statistics from SJTU At 2014-09-08 05:46:39, Karl Ropkins k.ropk...@its.leeds.ac.uk wrote: Try: edit(vignette(grobs,package = grid)) (edit is a method. It looks at the class of the first entry, name, to identify which method to use. See ?edit. You want it to use edit.vignette, so you need to drop 'file=' so you pass the vignette to edit as the first argument or name=. Then edit will pass it to edit.vignette and it'll work. Or go direct: edit.vignette(vignette(grobs,package = grid)). See ?vignette. Maybe the use of name as the first argument of a method is a little misleading? But you can work out what is going if you work through the help documentation.) Karl Message: 9 Date: Sun, 7 Sep 2014 17:06:44 +0800 (CST) From: PO SU rhelpmaill...@163.com To: R. Help r-help@r-project.org Subject: [R] using edit to extract codes from vignette failed Message-ID: 4d3c1c8a.1c96.1484f5d8d31.coremail.rhelpmaill...@163.com Content-Type: text/plain; charset=UTF-8 Dear expeRts, ? ? When i using the following code, i get a error as follows: ?edit(file=vignette(grobs,package = grid)) Error in edit.vignette(file = vignette(grobs, package = grid)) :? ? argument name is missing, with no default I investigated edit function, but still can't ?get codes from a vignette, May you help me? -- PO SU mail: desolato...@163.com Majored in Statistics from SJTU __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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 edit to extract codes from vignette failed
OK, i get it, i should set the editor argument , i don't know how to report a bug to Rstudio, may you do that ? -- PO SU mail: desolato...@163.com Majored in Statistics from SJTU At 2014-09-09 00:41:33, William Dunlap wdun...@tibco.com wrote: Complain to the RStudio people - RStudio defines its own options(editor) which is not completely compatible with R's option(editor=internal). If you set options(editor=internal) in RStudio then you can look at the code in the vignette. (I tried with last year's RStudio 0.98.501 and this may have been fixed by now.) Bill Dunlap TIBCO Software wdunlap tibco.com On Mon, Sep 8, 2014 at 9:21 AM, PO SU rhelpmaill...@163.com wrote: Tks for correcting me not using the file argument, but the codes you supply seem still not work. edit(vignette(grobs,package = grid)) can't work. I am using win7, the latest version of Rstudio which using R.3.1.1.The error is: Error in editor(file = file, title = title) : argument name is missing, with no default -- PO SU mail: desolato...@163.com Majored in Statistics from SJTU At 2014-09-08 05:46:39, Karl Ropkins k.ropk...@its.leeds.ac.uk wrote: Try: edit(vignette(grobs,package = grid)) (edit is a method. It looks at the class of the first entry, name, to identify which method to use. See ?edit. You want it to use edit.vignette, so you need to drop 'file=' so you pass the vignette to edit as the first argument or name=. Then edit will pass it to edit.vignette and it'll work. Or go direct: edit.vignette(vignette(grobs,package = grid)). See ?vignette. Maybe the use of name as the first argument of a method is a little misleading? But you can work out what is going if you work through the help documentation.) Karl Message: 9 Date: Sun, 7 Sep 2014 17:06:44 +0800 (CST) From: PO SU rhelpmaill...@163.com To: R. Help r-help@r-project.org Subject: [R] using edit to extract codes from vignette failed Message-ID: 4d3c1c8a.1c96.1484f5d8d31.coremail.rhelpmaill...@163.com Content-Type: text/plain; charset=UTF-8 Dear expeRts, ? ? When i using the following code, i get a error as follows: ?edit(file=vignette(grobs,package = grid)) Error in edit.vignette(file = vignette(grobs, package = grid)) :? ? argument name is missing, with no default I investigated edit function, but still can't ?get codes from a vignette, May you help me? -- PO SU mail: desolato...@163.com Majored in Statistics from SJTU __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
[R] How to use multi paragraph comment like /* and */ in cpp?
Dear expeRts, I find it's terrible when i want to comment multi paragraph (e.g. a 30 lines function) , i have to comment each line with #, is there any good way to do that ? I investgate it, but found no easy way, may you help me ? -- PO SU mail: desolato...@163.com Majored in Statistics from SJTU __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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 edit to extract codes from vignette failed
Dear expeRts, When i using the following code, i get a error as follows: edit(file=vignette(grobs,package = grid)) Error in edit.vignette(file = vignette(grobs, package = grid)) : argument name is missing, with no default I investigated edit function, but still can't get codes from a vignette, May you help me? -- PO SU mail: desolato...@163.com Majored in Statistics from SJTU __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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] The newest version of Rstudio Desktop v0.98.1049 couldn't be installed
Dear expeRts, I find the newest Rstudio Desktop v0.98.1049 for windows is not newest, after i installed, it was a old version. -- PO SU mail: desolato...@163.com Majored in Statistics from SJTU __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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] what happened when copying a function definition into R prompt then press Enter?
Dear expeRts, That's to say,what happened when loading source code into memory? what's the difference between it and loading installed code into memory? Do they related with .Rdata? -- PO SU mail: desolato...@163.com Majored in Statistics from SJTU __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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] what 's meaning of setting options() through .onLoad() funtion in making a package?
Dear expeRts, I am now reading a book which teaching how to make a r package, i investigated from ?options but nothing said about in making a package. The help document only just introduce some option keys to me in some basic r packages. But i want to know, why need to set some options in make a r package, e.g. If i use options(a=3) in my package, what's usage of a ? The following code is from Hadley wickham's book , i attach it for your better understanding my quesion: .onLoad - function(libname, pkgname) { op - options() op.devtools - list( devtools.path = ~/R-dev, devtools.install.args = , devtools.name = Your name goes here, devtools.desc.author = 'First Last first.l...@example.com [aut, cre]', devtools.desc.license = What license is it under?, devtools.desc.suggests = NULL, devtools.desc = list() ) toset - !(names(op.devtools) %in% names(op)) if(any(toset)) options(op.devtools[toset]) invisible() } -- PO SU mail: desolato...@163.com Majored in Statistics from SJTU __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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] 21 R navigation tools
I think the article from burns-stat is very worth reading , You can google it ,and hope you find it useful. -- PO SU mail: desolato...@163.com Majored in Statistics from SJTU __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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] What the difference between .Golbalenv and package:base?
So, the decisive factor is whether the input string be on the search() name list, and not related with the envir's name attribute. When we using attach, it is becasue the name attribute just match the search() name list(or say,search() name list just use the name attribute), so as.environment() can work well. Tks! -- PO SU mail: desolato...@163.com Majored in Statistics from SJTU At 2014-08-27 00:02:07, William Dunlap wdun...@tibco.com wrote: as.environment(characterString) maps an entry from the output of search() to the environment at the named position in the search list. as.environment(number) maps an index into the output of search() to the the environment at that position in the search list. If 'characterString' is not in the output of search() or 'number' is not in seq_along(search()) then as.environment throws an error. As far as I can tell, as.environment does not deal with the name of the environment at all. (When you attach an environment, attach will add a name attribute to the copied environment so the attached environment's name matches the name on the output of search(), but I don't think as.environment ever looks at that attribute.) Bill Dunlap TIBCO Software wdunlap tibco.com On Mon, Aug 25, 2014 at 9:07 PM, PO SU rhelpmaill...@163.com wrote: First, sorry for my pool english expression which make you misunderstanding of my original purpose. Sometimes, suppose a object in both stats and base, then i type the object name, then after R search the search() list, R will use the object in stats, is it right?( I just suppose, stats can be any package which libraried into R.) Then i know that, .GlobalEnv or globalenv() is the global environment object, baseenv() returns the base environment object. I also know that, i can convert the environment name into the real environment object by using stats-as.environment(package:stats), And the stats environment's name can be obtained using environmentName(stats), but it returns . (why?) Then i use environmentName(.GlobalEnv) then i get R_GlobalEnv, then i use as.environment(R_GlobalEnv), it does't work.(why?) In one word, as.environment(x), x is somthing not the environment's name. But, when i add a environment into the search() list, after i attr(newenvir,name)-new_name I can use the as.environment(new_name) to obtain the added environment. (why?) Hope you understand my meaning :) -- PO SU mail: desolato...@163.com Majored in Statistics from SJTU At 2014-08-26 02:51:54, MacQueen, Don macque...@llnl.gov wrote: Put simply, .GlobalEnvstores objects you create package:base contains functions and objects provided by R itself You don¹t need to use .GlobalEnv$a to use the variable named a. Just is ³a² by itself. a - 4 b - 2*a print(a) print(b) Not necessary to use print(.GlobalEnv$a) Similarly, to find an object in the base package, just type its name. I don¹t know what you are trying to do, or why you think you have to use .GlobalEnv$a But in more than 20 years of using R for many different tasks, I have never had to do that. Furthermore, if you are new to R (which I would guess is the case), it seems unlikely to me that you need to work with environments or use attach() or assign(). In the vast majority of cases there are simpler ways that are easier to understand. You are aware, I hope, that ls('.GlobalEnv') ls(1) ls() all return the same result? -- Don MacQueen Lawrence Livermore National Laboratory 7000 East Ave., L-627 Livermore, CA 94550 925-423-1062 On 8/24/14, 11:07 PM, PO SU rhelpmaill...@163.com wrote: Dear rusers, As we know, there are a lot of environments in the search() path, such as .Golbalenv and package:base . And i can just use .Golbalenv$a ,.Golbalenv$b to use the virable, but i must use as.envrionment(package:base) to find virable, i feel it not very convenient. For example, when i use the following codes to add a new env into the search() path. tmp-attach(NULL,name=new_name) assign(a,2,envir=as.environment(new_name)) a [1] 2 as.environment(new_name)$a [1] 2 I must always convert the name to the environment, How can i just use the following form: tmp-attach(NULL,name=new_name) assign(a,2,envir=new_name) #like using .GlobalEnv a [1] 2 new_name$a [1] 2 -- PO SU mail: desolato...@163.com Majored in Statistics from SJTU __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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. [[alternative
[R] What the difference between .Golbalenv and package:base?
Dear rusers, As we know, there are a lot of environments in the search() path, such as .Golbalenv and package:base . And i can just use .Golbalenv$a ,.Golbalenv$b to use the virable, but i must use as.envrionment(package:base) to find virable, i feel it not very convenient. For example, when i use the following codes to add a new env into the search() path. tmp-attach(NULL,name=new_name) assign(a,2,envir=as.environment(new_name)) a [1] 2 as.environment(new_name)$a [1] 2 I must always convert the name to the environment, How can i just use the following form: tmp-attach(NULL,name=new_name) assign(a,2,envir=new_name) #like using .GlobalEnv a [1] 2 new_name$a [1] 2 -- PO SU mail: desolato...@163.com Majored in Statistics from SJTU __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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] What the difference between .Golbalenv and package:base?
As you know, in the search path, there is .GlobalEnv, package:stats and so on, why do we need to convert the character package:stats to the stats environment. I mean, why don't let package:stats be a environment type object like .GlobalEnv,but let it be a string ? Hope you understand my meaning for my pool english expression way. -- PO SU mail: desolato...@163.com Majored in Statistics from SJTU At 2014-08-25 09:53:37, John McKown john.archie.mck...@gmail.com wrote: On Mon, Aug 25, 2014 at 1:07 AM, PO SU rhelpmaill...@163.com wrote: Dear rusers, As we know, there are a lot of environments in the search() path, such as .Golbalenv and package:base . And i can just use .Golbalenv$a ,.Golbalenv$b to use the virable, but i must use as.envrionment(package:base) to find virable, i feel it not very convenient. For example, when i use the following codes to add a new env into the search() path. tmp-attach(NULL,name=new_name) assign(a,2,envir=as.environment(new_name)) a [1] 2 as.environment(new_name)$a [1] 2 I must always convert the name to the environment, How can i just use the following form: tmp-attach(NULL,name=new_name) assign(a,2,envir=new_name) #like using .GlobalEnv a [1] 2 new_name$a [1] 2 -- PO SU mail: desolato...@163.com Majored in Statistics from SJTU You might want to try: new_name - new.env(); # or if you prefer (such as in a function) assign(new_name,new.env(),envir=.GlobalEnv); # # You may now assign variable into this similar to: new_name$a - 2; gvar - new_name$a; # get the variable a from environment new_name gvar - get(a,envir=new_name); #same thing, but wordy attach(new_name); a gvar - a; -- There is nothing more pleasant than traveling and meeting new people! Genghis Khan Maranatha! John McKown [[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] What the difference between .Golbalenv and package:base?
Tks for all your details, after your introduction, i really read the ?attach carefully, and i now understand the argument pos now, but in my opnion, the details in the function attach may do the as.environment(pos) for me. And i also understand that, attach will copy the attached envir,and add the copied envir into the search path list as you showed the examples to me. After all, i want to ask a last question: I notice that, environmentName(.GlobalEnv) [1] R_GlobalEnv as.environment(.GlobalEnv) environment: R_GlobalEnv as.environment(R_GlobalEnv) Error in as.environment(R_GlobalEnv) : no item called R_GlobalEnv on the search list .GlobalEnv environment: R_GlobalEnv environmentName(package:stats) [1] as.environment(package:stats) environment: package:stats attr(,name) [1] package:stats attr(,path) [1] C:/Program Files/R/R-3.1.1/library/stats I am really confused now, while as.environment(package:stats) can be work by convert the name of the environment stats, the environmentName returns ! And get the .GlobalEnv from .GlobalEnv ,but can't form R_GlobalEnv which is actually the name of the environment. -- PO SU mail: desolato...@163.com Majored in Statistics from SJTU At 2014-08-26 01:26:28, John McKown john.archie.mck...@gmail.com wrote: On Mon, Aug 25, 2014 at 11:19 AM, PO SU rhelpmaill...@163.com wrote: As you know, in the search path, there is .GlobalEnv, package:stats and so on, why do we need to convert the character package:stats to the stats environment. I mean, why don't let package:stats be a environment type object like .GlobalEnv,but let it be a string ? Hope you understand my meaning for my pool english expression way. Yes, you have Sorry for my misunderstanding of what were originally saying. I _think_ that I now understand. The fault is likely my concentrating on the wrong part of your original email. To test my ability to understand, I submit the following possibility: new_name-new.env(); attach(new_name) search() [1] .GlobalEnvnew_name new_name tools:rstudio [5] package:graphics package:grDevices package:utils package:datasets [9] package:methods Autoloads package:base assign(a,2,pos=new_name) a [1] 2 ls() [1] new_name ls(pos=new_name) [1] a Note the use of pos= instead of envir=. That seems to be the key here. I hope this was of more use to you. One problem that I have noticed is that you can not get to the value of a by using new_name$a, but must use the get() function like: get('a',pos='new_name'); Please be very aware of the following, very confusing fact: Referencing a variable can not have the expected results. new_name - new.env() attach(new_name) search() [1] .GlobalEnvnew_name tools:rstudio package:stats [5] package:graphics package:grDevices package:utils package:datasets [9] package:methods Autoloads package:base assign(a,2,new_name) ls() [1] new_name new_name$a NULL get(a,pos=new_name) [1] 2 new_name$a - 'x' new_name$a; [1] x get(a,pos=new_name) [1] 2 If you wanted to use string values in the first two commands above, then perhaps: attach(NULL,name=new_name) search() [1] .GlobalEnvnew_name tools:rstudio package:graphics [5] package:grDevices package:utils package:datasets package:methods [9] Autoloads package:base assign(a,2,pos=new_name) ls() character(0) ls(pos=new_name) [1] a a [1] 2 # or even ls(new_name) [1] a Likewise you can do: search() [1] .GlobalEnvtools:rstudio package:stats package:graphics [5] package:grDevices package:utils package:datasets package:methods [9] Autoloads package:base ls(pos=package:stats) [1] acf acf2AR add.scope [4] add1 addmargins aggregate [7] aggregate.data.frame aggregate.ts AIC [10] aliasanovaansari.test ... [436] variable.names varimax vcov [439] weighted.meanweighted.residuals weights [442] wilcox.test window window- [445] write.ftable xtabs get(time,pos=package:stats) function (x, ...) UseMethod(time) bytecode: 0x0a4e8b00 environment: namespace:stats x-get(time,pos=package:stats) x function (x, ...) UseMethod(time) bytecode: 0x0a4e8b00 environment: namespace:stats # note that the get() basically created a variable in the global environment whose value was # the same as in the package. But you can change the value of x in the global environment # and it won't affect the value in the package. And vice versa, if you could update x in # the package, but that can't be done because packages seem to be locked and read-only. -- PO SU mail: desolato...@163.com Majored in Statistics from SJTU -- There is nothing more pleasant than traveling and meeting new people! Genghis Khan Maranatha! John McKown
Re: [R] What the difference between .Golbalenv and package:base?
First, sorry for my pool english expression which make you misunderstanding of my original purpose. Sometimes, suppose a object in both stats and base, then i type the object name, then after R search the search() list, R will use the object in stats, is it right?( I just suppose, stats can be any package which libraried into R.) Then i know that, .GlobalEnv or globalenv() is the global environment object, baseenv() returns the base environment object. I also know that, i can convert the environment name into the real environment object by using stats-as.environment(package:stats), And the stats environment's name can be obtained using environmentName(stats), but it returns . (why?) Then i use environmentName(.GlobalEnv) then i get R_GlobalEnv, then i use as.environment(R_GlobalEnv), it does't work.(why?) In one word, as.environment(x), x is somthing not the environment's name. But, when i add a environment into the search() list, after i attr(newenvir,name)-new_name I can use the as.environment(new_name) to obtain the added environment. (why?) Hope you understand my meaning :) -- PO SU mail: desolato...@163.com Majored in Statistics from SJTU At 2014-08-26 02:51:54, MacQueen, Don macque...@llnl.gov wrote: Put simply, .GlobalEnvstores objects you create package:base contains functions and objects provided by R itself You don¹t need to use .GlobalEnv$a to use the variable named a. Just is ³a² by itself. a - 4 b - 2*a print(a) print(b) Not necessary to use print(.GlobalEnv$a) Similarly, to find an object in the base package, just type its name. I don¹t know what you are trying to do, or why you think you have to use .GlobalEnv$a But in more than 20 years of using R for many different tasks, I have never had to do that. Furthermore, if you are new to R (which I would guess is the case), it seems unlikely to me that you need to work with environments or use attach() or assign(). In the vast majority of cases there are simpler ways that are easier to understand. You are aware, I hope, that ls('.GlobalEnv') ls(1) ls() all return the same result? -- Don MacQueen Lawrence Livermore National Laboratory 7000 East Ave., L-627 Livermore, CA 94550 925-423-1062 On 8/24/14, 11:07 PM, PO SU rhelpmaill...@163.com wrote: Dear rusers, As we know, there are a lot of environments in the search() path, such as .Golbalenv and package:base . And i can just use .Golbalenv$a ,.Golbalenv$b to use the virable, but i must use as.envrionment(package:base) to find virable, i feel it not very convenient. For example, when i use the following codes to add a new env into the search() path. tmp-attach(NULL,name=new_name) assign(a,2,envir=as.environment(new_name)) a [1] 2 as.environment(new_name)$a [1] 2 I must always convert the name to the environment, How can i just use the following form: tmp-attach(NULL,name=new_name) assign(a,2,envir=new_name) #like using .GlobalEnv a [1] 2 new_name$a [1] 2 -- PO SU mail: desolato...@163.com Majored in Statistics from SJTU __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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] file.show() may have some bug?
Sorry for my bad typing, file.show(xxx.h) still not work. -- PO SU mail: desolato...@163.com Majored in Statistics from SJTU At 2014-08-21 03:12:06, Berend Hasselman b...@xs4all.nl wrote: On 21-08-2014, at 05:19, PO SU rhelpmaill...@163.com wrote: Dear Rusers, when i try file.show( xxx.h) in Rstudio which using R3.0.2, it doesn't show anything. But when i use file.edit(xxx.h),it shows the right file, It is the same thing happen to xxx.c file. May you explain it to me? How about leaving out the space in file.show( xxx.h”)? Use file.show(xxx.h”) Berend __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] file.show() may have some bug?
Because the update of R is rather a trouble thing, i mean that you should have to install every package you have installed. So i do not follow the newest version. -- PO SU mail: desolato...@163.com Majored in Statistics from SJTU At 2014-08-21 04:40:10, peter dalgaard pda...@gmail.com wrote: On 21 Aug 2014, at 10:13 , Prof Brian Ripley rip...@stats.ox.ac.uk wrote: On 21/08/2014 08:50, PO SU wrote: Sorry for my bad typing, file.show(xxx.h) still not work. But note that file.show() uses facilities of the front-end, so report RStudio problems to them not the R community. Also note that the posting guide asked you to update before posting: your R is 3 versions old. And it does seem to work in R-3.1.1/Rstudio 0.98.939 (the latter is in for an update, but hey, preachers can't be practitioners...). -pd -- PO SU mail: desolato...@163.com Majored in Statistics from SJTU At 2014-08-21 03:12:06, Berend Hasselman b...@xs4all.nl wrote: On 21-08-2014, at 05:19, PO SU rhelpmaill...@163.com wrote: Dear Rusers, when i try file.show( xxx.h) in Rstudio which using R3.0.2, it doesn't show anything. But when i use file.edit(xxx.h),it shows the right file, It is the same thing happen to xxx.c file. May you explain it to me? How about leaving out the space in file.show( xxx.h��)? Use file.show(xxx.h��) Berend __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. -- Brian D. Ripley, rip...@stats.ox.ac.uk Emeritus Professor of Applied Statistics, University of Oxford 1 South Parks Road, Oxford OX1 3TG, UK __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. -- Peter Dalgaard, Professor, Center for Statistics, Copenhagen Business School Solbjerg Plads 3, 2000 Frederiksberg, Denmark Phone: (+45)38153501 Email: pd@cbs.dk Priv: pda...@gmail.com __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. [[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] hadley's book
Haha, i have already read the advanced r programming part of the book. As you said, it will be quite popular in future years. -- PO SU mail: desolato...@163.com Majored in Statistics from SJTU At 2014-08-22 04:57:01, Mark Leeds marklee...@gmail.com wrote: I have a feeling hadley's book will be quite popular so just a heads up that it can now be pre-ordered on amazon. [[alternative HTML version deleted]] __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. [[alternative HTML version deleted]] __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
[R] file.show() may have some bug?
Dear Rusers, when i try file.show( xxx.h) in Rstudio which using R3.0.2, it doesn't show anything. But when i use file.edit(xxx.h),it shows the right file, It is the same thing happen to xxx.c file. May you explain it to me? -- PO SU mail: desolato...@163.com Majored in Statistics from SJTU [[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] A question in Rinternals.h
Dear Rusers, when i am reading Rinternals.h file, i can't understand the following codes in lines 395-407: #define CHAR(x)R_CHAR(x) const char *(R_CHAR)(SEXP x); /* Various tests with macro versions below */ Rboolean (Rf_isNull)(SEXP s); Rboolean (Rf_isSymbol)(SEXP s); Rboolean (Rf_isLogical)(SEXP s); Rboolean (Rf_isReal)(SEXP s); Rboolean (Rf_isComplex)(SEXP s); Rboolean (Rf_isExpression)(SEXP s); Rboolean (Rf_isEnvironment)(SEXP s); Rboolean (Rf_isString)(SEXP s); Rboolean (Rf_isObject)(SEXP s); I can't figure out what are R_CHAR,Rf_isNullRf_isObject meaning, they seem like function declarations, Rf_XXX maybe function pointers? I need your help. -- PO SU mail: desolato...@163.com Majored in Statistics from SJTU [[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] A question in Rinternals.h
Tks for your guide, but before i know which maillist should i ask the question, i could only ask it here. 'figure out' i mean 'understand'. Forgive my pool english :). -- PO SU mail: desolato...@163.com Majored in Statistics from SJTU At 2014-08-19 06:28:06, Prof Brian Ripley rip...@stats.ox.ac.uk wrote: Please do read the posting guide (clearly you have not as you sent HTML). - This is the wrong list: it is a question about C code. - In any case, it is about C. The R Internals manual may help you, otherwise you need to talk to a local C adviser. (Even if this were not off-topic here, we do not know what it is you cannot 'figure out' and you need to interact with someone.) On 19/08/2014 11:14, PO SU wrote: Dear Rusers, when i am reading Rinternals.h file, i can't understand the following codes in lines 395-407: #define CHAR(x)R_CHAR(x) const char *(R_CHAR)(SEXP x); /* Various tests with macro versions below */ Rboolean (Rf_isNull)(SEXP s); Rboolean (Rf_isSymbol)(SEXP s); Rboolean (Rf_isLogical)(SEXP s); Rboolean (Rf_isReal)(SEXP s); Rboolean (Rf_isComplex)(SEXP s); Rboolean (Rf_isExpression)(SEXP s); Rboolean (Rf_isEnvironment)(SEXP s); Rboolean (Rf_isString)(SEXP s); Rboolean (Rf_isObject)(SEXP s); I can't figure out what are R_CHAR,Rf_isNullRf_isObject meaning, they seem like function declarations, Rf_XXX maybe function pointers? I need your help. -- PO SU mail: desolato...@163.com Majored in Statistics from SJTU [[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. -- Brian D. Ripley, rip...@stats.ox.ac.uk Emeritus Professor of Applied Statistics, University of Oxford 1 South Parks Road, Oxford OX1 3TG, UK [[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] A question in Rinternals.h
BTW, you say i always send html format email, finally i find that it is my mail server which send mail in html format by default., i should change the format eveytime before sending a mail... -- PO SU mail: desolato...@163.com Majored in Statistics from SJTU At 2014-08-19 06:28:06, Prof Brian Ripley rip...@stats.ox.ac.uk wrote: Please do read the posting guide (clearly you have not as you sent HTML). - This is the wrong list: it is a question about C code. - In any case, it is about C. The R Internals manual may help you, otherwise you need to talk to a local C adviser. (Even if this were not off-topic here, we do not know what it is you cannot 'figure out' and you need to interact with someone.) On 19/08/2014 11:14, PO SU wrote: Dear Rusers, when i am reading Rinternals.h file, i can't understand the following codes in lines 395-407: #define CHAR(x)R_CHAR(x) const char *(R_CHAR)(SEXP x); /* Various tests with macro versions below */ Rboolean (Rf_isNull)(SEXP s); Rboolean (Rf_isSymbol)(SEXP s); Rboolean (Rf_isLogical)(SEXP s); Rboolean (Rf_isReal)(SEXP s); Rboolean (Rf_isComplex)(SEXP s); Rboolean (Rf_isExpression)(SEXP s); Rboolean (Rf_isEnvironment)(SEXP s); Rboolean (Rf_isString)(SEXP s); Rboolean (Rf_isObject)(SEXP s); I can't figure out what are R_CHAR,Rf_isNullRf_isObject meaning, they seem like function declarations, Rf_XXX maybe function pointers? I need your help. -- PO SU mail: desolato...@163.com Majored in Statistics from SJTU [[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. -- Brian D. Ripley, rip...@stats.ox.ac.uk Emeritus Professor of Applied Statistics, University of Oxford 1 South Parks Road, Oxford OX1 3TG, UK __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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] loops with assign() and get()
It's a great method, but there is a memory problem, DFS would occupy a large memory. So from this point of view, i prefer the loop. for (i in 1 : nrow(unique)){ tmp=get(past0(DF,i))[1,] assign(paste0(df,i),tmp) dfi=dfi[,1:3] names(dfi)=names(tmp[c(1,4,5)]) dfi=rbind(dfi,tmp[c(1,4,5)]) names(dfi)=c(UID,Date,Location) } NB: The code above without any test! -- PO SU mail: desolato...@163.com Majored in Statistics from SJTU At 2014-08-10 06:32:38, William Dunlap wdun...@tibco.com wrote: I was able to create 102 distinct dataframes (DFs1, DFs2, DFs3, etc) using the assign() in a loop. The first step to making things easier to do is to put those data.frames into a list. I'll call it DFS and your data.frames will now be DFs[[1]], DFs[[2]], ..., DFs[[length(DFs)]]. DFs - lapply(paste0(DFs, 1:102), get) In the future, I think it would be easier if you skipped the 'assign()' and just put the data into a list from the start. Now use lapply to process that list, creating a new list called 'df', where df[[i]] is the result of processing DFs[[i]]: df - lapply(DFs, FUN=function(DFsi) { # your code from the for loop you supplied dfi=DFsi[1,] dfi=dfi[,1:3] names(dfi)=names(DFsi[c(1,4,5)]) dfi=rbind(dfi,DFsi[c(1,4,5)]) names(dfi)=c(UID,Date,Location) dfi # return this to put in list that lapply is making }) (You didn't supply sample data so I did not run this - there may be typos.) Bill Dunlap TIBCO Software wdunlap tibco.com On Sat, Aug 9, 2014 at 1:39 PM, Laura Villegas Ortiz lvil...@ncsu.edu wrote: Dear all, I was able to create 102 distinct dataframes (DFs1, DFs2, DFs3, etc) using the assign() in a loop. Now, I would like to perform the following transformation for each one of these dataframes: df1=DFs1[1,] df1=df1[,1:3] names(df1)=names(DFs1[c(1,4,5)]) df1=rbind(df1,DFs1[c(1,4,5)]) names(df1)=c(UID,Date,Location) something like this: for (i in 1 : nrow(unique)){ dfi=DFsi[1,] dfi=dfi[,1:3] names(dfi)=names(DFsi[c(1,4,5)]) dfi=rbind(dfi,DFsi[c(1,4,5)]) names(dfi)=c(UID,Date,Location) } I thought it could be straightforward but has proven the opposite Many thanks Laura [[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. [[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] Need help in using Rcpp
Dear Rcppusers, I can't figure out what the following codes do: int f4(Function pred, List x) { int n = x.size(); for(int i = 0; i n; ++i) { LogicalVector res = pred(x[i]); if (res[0]) return i + 1; } return 0; } I investigated it, and understand applying a function to everypart of a list then return a LogicalVector, but i can't understand if the first element of the LogicalVector is true then return the row index of the list. Tks! -- PO SU mail: desolato...@163.com Majored in Statistics from SJTU [[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] Just stumbled across this: Advanced R programming text code - from Hadley
The book is absolutely helpful to me. Any R newusers should read the book. Now I am reading the Section Rcpp. -- PO SU mail: desolato...@163.com Majored in Statistics from SJTU At 2014-08-11 09:02:53, Mitchell Maltenfort mmal...@gmail.com wrote: Ah, what do you know anyway? -- as the book critic said to the author. Ersatzistician and Chutzpahthologist I can answer any question. I don't know is an answer. I don't know yet is a better answer. I can write better than anybody who can write faster, and I can write faster than anybody who can write better AJ Leibling On Mon, Aug 11, 2014 at 8:38 AM, Hadley Wickham h.wick...@gmail.com wrote: Or just go to http://adv-r.had.co.nz/ ... Hadley On Sun, Aug 10, 2014 at 9:34 PM, John McKown john.archie.mck...@gmail.com wrote: Well, it says that it's from Hadley Wickham. https://github.com/hadley/adv-r quote This is code and text behind the Advanced R programming book. The site is built using jekyll, with a custom plugin to render .rmd files with knitr and pandoc. To create the site, you need: jekyll and s3_websiter gems: gem install jekyll s3_website pandoc knitr: install.packages(knitr) /quote This contains a Rstudio project file. I know because I've done a git clone on it and loaded it into Rstudio, on Linux. If you don't have git, there is a download zip option on the site too. -- 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. -- http://had.co.nz/ __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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. [[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.