Skip to main content

Posts

Showing posts from July, 2017

Ggplot2 package (part1)

It is a graphic package implemented in R, it allows to make graphs in a very flexible way because it contains many different commands to perform specific functions when creating and manipulating graphs. In addition, this graphic package has an underlying grammar in layers, so that it is composed of independent components. These independent components can be combined in many different ways to make or modify the graphs. Each graph is made up of a few equal components: data, visual marks that represent data points (geoms), and a coordinate system. The necessary variables for the ggplot command are the data to use in data frame format and know which variables we will use as x and y:         ggplot (df, aes (x, y,  )) You can add more layers to the previous ggplot using the  +  operator, so the code is explicit as to which layers were added and in the order they were added. here we will use the dataset  iris : head ( iris ) ## Sepal.Length Sepal.Width Petal.Length Petal.Width Spe

Initial data analysis functions

Create a function in R: Function  function()  allows us to create specific functions. Between parenthesis we put the name of the parameters we want to create to be used in our function.     Function(parameter1, parameter2, ...){         statements         return(object) } NameFunction0 = function ( x , y ) { return ( ( x + y ) / 2 ) } NameFunction0 ( 4 , 5 ) ## [1] 4.5 If we want use a parameter that may or may not be specified we use  parameter = NULL : NameFunction1 = function ( x , y = NULL ) { if ( ! is.null ( y ) ) x = x + y return ( x ) } NameFunction1 ( 5 , 10 ) #with 2 paramers (x,y) ## [1] 15 NameFunction1 ( 5 ) #with only only parameter (x) ## [1] 5 Initial Data Analysis Functions Here we have created some basic functions that can be used for initial data analysis of our data: INLIERS  returns the values of a vector that are between the vales  start  and  end : INLIERS = function ( x , start , end ) { x1 =