Showing posts with label R Gui. Show all posts
Showing posts with label R Gui. Show all posts

Saturday, December 30, 2017

Show me how to write R Code for Hello World web page?

 R language is open source with a huge number of developers. It has a great arsenal of great stuff already accomplished. It is a language that you should get exposed to yourself. You just install R Gui and you are ready.


Shiny is an enterprise-grade web application framework targeted for those who want to develop with R using the familiar HTML5, CSS and JavaScript. Using R you can turn terrific analytic solutions you have developed/developing into interactive web applications.

Go to this site (https://shiny.rstudio.com/) directly and learn more.

 
Rshiny-00

If you have R Studio you have Shiny because Shiny is a package that you can download.

In this first part we only talk about the very basics.

I assume you have read my previous hands-on R examples in my blogs.


Here I just show a very basic (aka Hello World) example of creating content for a web page using R GUI. More will come later in my blogs.

Launch R Gui as shown and provide reference to the shiny "library" as shown by typing in the three lines of code (The four lines of code in red).


 HelloWorld_00

When you hit Enter after the third line where you define the shiny app, a browser window will open as shown displaying the apps output as shown at a port of the local host.



HelloWorld_01

You also get a response (the last line) in the R GUI as shown.




HelloWorld_02
That is all there is to create a content.

The ui summarizes your user interface, the server is something like a web server and shinyApp is your web response. No fuss, very simple.

Friday, May 27, 2016

What is the difference between factorial and lfactorial in R programming?

Factorial computes the factorial of a number. Given a number n it computes n! (n factorial). You can follow this after launching the R Gui. 5! is same as 5x4x3x2x1
---------------
> factorial(5)
[1] 120
---------------
factorial in R programming is also applicable to non-integers.
------
> factorial(5.5)
[1] 287.8853
-------------
How does R programming calculates factorial. It is calculated in the most efficient manner using the Gamma function.
factorial(x)=gamma(x+1)

In implementation to calculate factorial R calculates the gamma
factorial(5)=gamma(5+1)
------
> gamma(5+1)
[1] 120  - This is same as factorial(5)
----
What about lfactorial in R programming?

The definition of lfactorial (http://www.stata.com/manuals13/m-5factorial.pdf) is ;
lfactorial(n) is log(factorial(n))
-----
> lfactorial(5)
[1] 4.787492
> log(factorial(5))
[1] 4.787492
------------
Another interesting tip is you can use factorial function presenting it with a list like factorial(c(5,4,3)) and not a number. It would then compute the factorial for each of the numbers. For example:
----
> factorial(c(5,4,3))
[1] 120  24   6
> factorial(c(5,4.3,2))
[1] 120.00000  38.07798   2.00000
> lfactorial(c(5,4,3))
[1] 4.787492 3.178054 1.791759
----------