Thursday, April 1, 2021

Generic Summary Command for DataFrames / Matrices in R language

 


        Generic Summary Command for Data Frames

 

* Below is a short guide to the results expected for the generic software commands in R

 

* Descriptive Summary Commands that can be applied to Dataframes are :


00) mat01

     [,1] [,2] [,3] [,4]

[1,]    1    2    3    4

[2,]    5    6    7    8

[3,]    9   10   11   12

[4,]   13   14   15   16

 

01) max(mat01)

[1] 16

- The largest value in the entire dataframe

 

02) min(mat01)

[1] 1

- The smallest value in the entire dataframe

 

03) sum(mat01)

[1] 136

- The sum of all the values in the entire dataframe

 

04) fivenum(mat01)

[1]  1.0  4.5  8.5 12.5 16.0

- The summary values for the entire dataframe can be found out by using the "fivenum" command over a dataframe taken in as parameter

 

05) length(mat01)

[1] 16

- The length of all the columns within a dataframe can be found by using the length command over a dataframe

 

06) summary(mat01)

                   V1                   V2                       V3                    V4    

 Min.   :       1             Min.   : 2                Min.   : 3          Min.   : 4  

 1st Qu.:      4             1st Qu.: 5               1st Qu.: 6         1st Qu.: 7  

 Median :    7             Median : 8              Median : 9       Median :10  

 Mean   :     7             Mean   : 8               Mean   : 9        Mean   :10  

 3rd Qu.:    10            3rd Qu.:11              3rd Qu.:12       3rd Qu.:13  

 Max.   :     13            Max.   :14              Max.   :15        Max.   :16 

- It provides the summary for each of the columns present within a dataframe

 

* The list of all the summary / descriptive summary commands that work on a dataframe are listed and short

 

* One can always extract a single vector from a dataframe and perform a summary upon the data

 

* In general , it is better to use more specialised commands when dealing with the rows and columns of a dataframe

 

Row & Column Summary Commands "RowMeans()" & "ColMeans()" in R language over dataframe and Matrix objects


 Special Row and Column Summary Commands


* Two summary commands used for row data are - rowMeans() and rowSums()

 

> rowMeans(mat01)

[1]  2.5  6.5 10.5 14.5

 

> rowSums(mat01)

[1] 10 26 42 58

 

* In the given example , each row in the dataframe has a specific row name

 

* If the names of the rows along with the values for the various rows would appear as a simple vector of values

 

> rowSums(mat01)

[1] 10 26 42 58

 

* The corresponding "colSums()" and "colMeans()" commands function in the same manner .

 

* In the following example ... one can see the "mean()" and "colMeans()" command with their comparison in the following manner :

> colMeans(df)

[1]  7  8  9 10

 

> mean(mf)

[1] 8.5

 

 

* One can see that one would essentially get the same display / result using the above two commands

 

* The commands use "na.rm" instruction which is used by default and is set to FALSE

 

* If one wants to ensure that the "NA" items are removed from the dataframe then one can add "na.rm = TRUE " as an instruction in the command

"Apply()" Command for finding Summaries on Rows / Columns of a Matrix or Dataframe Object

 


"Apply()" Command for finding Summaries on Rows / Cols

=======================================================

* The "ColMeans()" and "RowSums()" command are designed as quick alternatives to a more generalised command "Apply()"

 

* The "apply()" command enables one to apply a function to rows or columns of a matrix or a dataframe

 

* The general form of the "Apply()" command is given in the following manner :

apply(X,margin,FUN,....)

 

In this command , the applicable MARGIN within the parameter is either 1 or 2 where 1 is for the rows and 2 is for the columns applicable for the dataframe

 

* One can replace the "FUN" part within the parameter of the apply() function and one can also add additional instructions which might be appropriate to the command / function that one is applying

 

* Example :

One might add the parameter "na.rm = TRUE " as an instruction to the apply function .

> mat01

     [,1] [,2] [,3] [,4]

[1,]    1    2    3    4

[2,]    5    6    7    8

[3,]    9   10   11   12

[4,]   13   14   15   16

 

> apply (mat01 , 1 , mean , na.rm = TRUE )

[1]  2.5  6.5 10.5 14.5

 

* In such a case , one can see that the row names of the original dataframe are displayed as output .

 

* If the dataframe has no set row names , then one will see the result as a vector of values .

 

> apply (fw , 1 , median , na.rm = TRUE )

2.5  6.5 10.5 14.5

 



Wednesday, March 31, 2021

Rotating Data Tables / Matrices in R

 


        Rotating Data Tables / Matrices in R

 

* One can do a rotation operation over a T table / dataframe / matrix object so that the rows become the columns and the columns become the rows .

 

* For doing the rotation operation over any data table object / data frame object or a matrix object in R , one can use the t() command .

 

* One can think of such a program as short for transpose operation

 

* The given example begins with a dataframe that contains two columns of numeric data with its rows also named .

  



* The final object is transposed ( means - the rows are changed to columns and the columns are changed to rows / reversal of attributes )

 

* Also , the new object is in fact a matrix rather than a dataframe .

  

* One can see this much more clearly if one tries the same t() command over a simple vector .




* Vectors are treated like columns , but when they are displayed they look like rows


* In any event , when you apply a t() command one would get a matrix object as a result .


* One can easily convert the objects to a dataframe using the "as.dataframe()" command .



 

Selecting and Displaying Parts of a Vector in R Language

 


   Selecting and Displaying Parts of a Vector

 

·     *   Being able to select and display the parts of a vector is one of the most important reasons of selection of a Vector .

 

·     * If one has a large sample of data , then in case if one wants to obtain a large sample of data , then one may want to see which of the items are larger than which of the values which would require the user of the data to select those data that are larger ones among the dataset

 

·    *   In an alternative scenario , one may want to extract a series of values as a subsample from an analysis .

 

·    *    Being able to select / extract required parts of a vector is one of the most important aspects of performing many more complicated operations in R tool .

 

* The various examples or processes that one may come across while doing any type of selection of a chunk of data from a vector are in form of given scenarios :

 

·        extraction of the first item / single item from within a vector ;
·        selection of the third item ( nth item) from within a vector ;
·        selection of the first to the third items from a vector ;
·        selection and extraction of all items from a vector ;
·        selection of items from the combination vector ;
·        selection of all items which are greater than the value 3 (that means selection and extraction of given items with a value for the number greater than or lesser than some particular number) ;
·        Showing items which are either greater than or lesser than some set of numbers








  The other useful commands over the objects which can be used to extract the various parts of data are : length() command which can be used to find the length of a given vector .

·        The length command can be also put to use to obtain / extract segments of data from square brackets :

 

data[ length(data) - 5 : length(data)]

 

In the above given scenario example the last five elements of the vector are found out from the above used code :

·        

·        max() command can be used to get the largest value in the vector

 

==========================================================

> data1

[1] 4 6 8 6 4 3 7 9 6 7 10

 

> max( data1 )

[1] 10

 

> which( data1 == max(data1))

[1] 11

==========================================================

 

# The upper command -- "which" is showing the index number or position of the largest data from within the data vector . The maximum value of all the data elements present within the "data1" vector is 10 . The positional index value of the data from the vector is 11 .

 

·        The first command .. max() provides the actual value which is the largest value within the vector and the second command asks which of the elements is the largest .

 

·        Another useful command is one that generates sequences from a vector which can be expressed in the form .. seq()

·        While using the "sequence" vector , one may need to pick out the beginning to ending of the interval vectors . In given words , one may select the first , third , fifth and so on vectors using the given in sequence parameters like the start , end and the interval values .

 

·        Therefore putting the full scale general form of the "sequence" command can be writen in the given form :

 

seq(start ,end ,interval)

 

 

·        The above command will work on character vectors as well as numeric vectors in the given manner :

 ==========================================================

> data5

   "Jan" "Feb" "Mar" "Apr" "May" "Jun" "Jul" "Aug" "Sep" "Oct"     "Nov" "Dec"

 

> data5[-1:-6]

   "Jul" "Aug" "Sep" "Oct" "Nov" "Dec" 

=================================================

* In the above code , the last 6 strings which are actually the three letter initials of each of the months of a calendar year are found out as result .

 

Tuesday, March 30, 2021

Working with Data Objects in R

   

       

               Working with Data Objects in R


* Data Objects are the fundamental items that one can work with in R language

* Carrying out analysis on one's given data and making sense of the results are the most important reasons of using R . In this article methods of working over a given data set would be provided and along with that understanding the results associated with the data objects of R is the central idea for working over R

* One can learn to use the different forms of data that are associated with R and how to convert the data from one form to another form

* Over R , one would also learn the techniques of sorting and rearranging the data 

* Some of the processes involved with Data Objects manipulation in R are in following manner :

 

==========================

        Manipulating Data Objects in R

==========================


- When you collect the data the very forst step is to get the data over to the R console

 - After the data is imported over to the R console the very first step to perform over the data is to do summary statistics steps for finding out the requisite results from the data

 - One may try to find more of some analytical results from the data from the given summary statistics of R as one may want to manipulate the data that is present over the R software .

 - One may want to reorder the data into newer and more informative manner from the first version of the imported data otherwise one may also try to do a more informative manner of data reordering .

 - Data Manipulation exercises of the given manner could also be performed over the data like extraction of certain parts of complex form of data etc could also be done from the data .

 - As given there are multiple ways of manipulation of the data and thus understanding how to do this is the most important aspect of learning about R because the more one knows about the working of R language and the way R handles the objects , it is better to make use of R as an analytical tool

Set-Difference Operations in RDBMS - an explanatory blog

   


            Set-Difference Operations in RDBMS

 

* The Set-Difference operation , denoted by "-" allows us to find the tuples that are in one relation but not in another .

 

* The expression , ( r - s ) produces a relation containing those tuples in r but not in s .

 

* One can find all the customers of the bank who have an account but not a loan by writing in the below manner :

 



* In the case of the Union Operation , one must ensure that the set differences are taken between compatible relations .

 

* For a set-difference operation where "r-s" to be valid , one requires that the relations r and s be of the same arity , and that the domains of the ith attribute of r and the ith attribute of s should be the same .