Basic operations in R

Basic operations in R

Here are some basic operations in R, you may try it in R console.
 
# this is a comment 
# comment starts with # mark
> 32*4 
[1] 128 
 
> 10/21
[1] 0.4761905
 
> b<-4.5      # to write b=4.5, b<-4.5 or b=4.5 can be used
> b
[1] 4.5
 
> a=10
> print(a)    # prints object
[1] 10
 
> cat(a)      # this also can be used to print
10
> pi          # pi 
[1] 3.141593
 
 
Installing packages
 
To use a library in R, first we need to install it. Below command shows how to install 'tidyr' library.    
 
> install.packages("tidyr")
 
The target library needs to be included in the script. To load library 'library' or 'require' command can be used. 
 
library(tidyr)    # loads tidyr package
requare(dplyr)    # loads dplyr package
 
 
Getting a help
 
>help(dir)        # shows help page for dir command 
>?dir             # shows the same
 
>example(file)    # shows file command examples

 





No comments:

Post a Comment