Saturday, 29 September 2018

Array, Strings and Functions in R Languages

Array 
  • Used to store ordered list of values of same type.
We will see how to:
  • Create Array
  • Access Array
  • Modify Array





Functions :-
  •  Function is a set of statements combined together perform a specific Task.
  • Syntax:
                 functionName <- function(Arguments_optional)
                   {
                       //Statemnts.
                      }
  • We will see how to:
                 - Create a Function
                 - Call a Function




String :-  
  •  Values written inside single or double quotes are called strings. E.g. "Hello" , 'hello'
  • Quotes can't be mixed, if a string has double quote in beginning ending quotes should be same as well.
  • Example of  Valid strings and invalid strings.
  • "Hey", 'Hey', "Teacher's", 'Name" is' are valid strings.
  • 'Hey", "Hello" there", 'hey"there', are invalid strings.
  • We will see how to:
             - Create and manipulate strings using predefined functions.

Tuesday, 25 September 2018

Importing Data Files from Other Software in R Language

Importing Data Files

Spreadsheet (Excel) file data

The xlsx package has the function read.xlsx ( ) for reading Excel files.

This will read the first sheet of an Excel spreadsheet.

To read Excel files, we first need to install the package

install.packages ("xlsx")
library (xlsx)
data  <-  read.xlsx ("datafile.xlsx", sheet Index or sheet Name)

 To load other sheets with read.xlsx( ), we specify a number for sheetIndex or a name for sheetName:

data  <- read.xlsx("datafile.xlsx", sheetIndex=2)

data  <-  read.xlsx("datafile.xlsx",sheetName="marks")

For reeading older Excel files in .xls format, use gdata package and function read.xls ( )

This will read the first sheet of an Excel spreadsheet.
To read Excel files, we first need to install the package

install.packages ("gdata")
library (gdata)
data  <- read.xls ("datafile.xls", sheet Index or sheet Name) )  

SPSS data file

For reading SPSs data files, use foreign package and function read.spss ( )

To read SPSs files, we first need to install the package

install.packages ("foreign")
library (foreign)
data  <-  read.spss ("datafile.sav") 


Other data files

The foreign package also includes functions to load other formats, including:
  • read.octave ("<Path to file>") : Octave and MATLAB
  • read.systat ("<Path to file>") : SYSTAT
  • read.xport ("<Path to file>") " SAS XPORT
  • read.data ("<Path to file>") : Stata
  
Contents of working directory

The list.files function shows the contents of your working directory:
> list.files ( )   // List of all available files in the working directory.

> setwd  ("C:/RCourse/")
> list.files ( )

 Redirecting Output to a File

Issue:
We want to redirect the output from R into a file instead of your console.

Solution:
Redirect the output of the cat function by using its file argument:

> ans  <-  6 + 8
> cat ("The answer of 6 + 8 is", ans, "\n", file="filename")

The Output will be saved in the working directory with given filename. 

Use the sink function to redirect all the output from both print and cat.

Call sink with a filename argument to begin redirecting console output to that file.

When we are done, sink with no argument to close the file and resume output to the console.

> sink ("filename")  #Beign writing output to file 
.....other session work .....
> sink

The print and cat functions normally write the output to console.

The cat function redirects the output to a file if we supply a file argument.

The print function cannot redirect its output.

The sink function can force all output to a file. 


Redirecting Output to a File: Three steps

1. 
> sink ("output.txt")  # Redirect output to file

2.
 > source ("script.R")  # Run the script, capture its output

3.
> sink ( )   # Resume writing output to console

Other options like append=TRUE/FALSE,  split=TRUE/FALSE are available. 

Example :-

 

Java Basics for Android

  • Originated in late 1995, released to public in 1996 (called Oak)
  • Nine major release since the beginning
  • Current version is SDK 8.
  • More than a programming language, it is a execution platform
            - Java Virtual Machine (JVM)

Evaluation of Java Language



Java Features

As released in the "White Paper" by the authors of Java
  1. Simple
  2. Object-Oriented
  3. Distributed
  4. Robust
  5. Secure
  6. Architecture-Neutral
  7. Portable
  8. Interpreted
  9. High-Performance
  10. Multithreaded
  11. Dynamic

JVM (Java Virtual Machine)
  • "Compile once run any where"
  • Java bytecodes
           Java Program                             Java bytecodes
                                    Java Compiler
                                                             →
         Java bytecodes                               Execution
                                      JRE
                                                           →


Execution Path
  • Windows
            - Environment variables
  • Linux
           edit ~ ./bashrc or ~./ cshrs ...
                - set path
                - export PATH
  • To test your settings
            - java - version

Java Naming Conventions

           Java is case-sensitive:
              HelloWorld             ≠           Helloworld



Java Interfaces

Set of requirements
      Describes what a class should do
             E.g. Comparable interface
                 public interface Comparable{
                        int compare To (Object other)
                 }
  • All methods are automatically public
  • All fields are public and static
  • No instance fields
  • No implementation of methods
         - Classes implement the interface
  • Can not instantiate an interface
         - Can declare interface variable
         - Instance of to check

Interfaces & Abstract Classes
  • A class can extend only a single class
  • A class can implement as many interfaces as it likes
          - Provides similar functionality as C++ multiple inheritance.

Monday, 24 September 2018

Data Reshaping in R Language

Data reshaping means changing how data is represented in rows and column.

 Most of Data Processing in R is done on Data Frames.

 R has many functions that deal with Reshaping of Data, by splitting, meaning or interchanging the Rows and columns.Some 

Data reshaping functions are:
            

             - cbind( )
             - rbind( )
             - merge( ), etc.


Another Data Frames :-



Sunday, 23 September 2018

Introduction to Android

Android

  • Android is an Operating System Mainly for smartphones.
  • But now you can find Android in your Tab, Television, TV Set top Box, Watches and even in your Car.
  • Android is a rich application Framework that allows you to develop innovative apps and Games for your Mobile devices.
  • Java is the  official development language for android, but in Google I/O 2017 Google introduce another language Kotlin as an Official language.
  • Now we have two programming languages for Android development, Java & Kotlin.
  • In this blog We are going to use Java for the App development.
  • Android is developed by Open Handset Alliance led by Google
  • Android uses Linux as its Kernel.
  • Android is open source Operating System.
  • Anyone can be an App developer and the tools needed for the App development is freely available on the web.
  • Android uses a special virtual machine for run your apps called Dalvik virtual machine.
  • You can develop Android apps and make it available for users through Google Play Store.
  • You can earn money from your apps through in App purchases and by placing Ads on your App.
  • Every year Google Release a New version of Android.
  • This Android series use a (Version 8.0, API Level 26)
Android Stack





Saturday, 22 September 2018

Introduction to Angular JS

This is developed in 2009 by Misko and Adam Abrons.
It is a Open Source and completely free.
It is a Licensed under Apache and maintained by Google.
This is very powerful JavaScript Framework.
  • A client side JS framework.
  • Developed and being maintained by Google
  • Goals
             - Separate DOM manipulation from application logic
             - Separation of concerns (using MVC like pattern)
             - Make SPA development easier
             - Provide solid foundation for robust/enterprise-scale JS client-side applications
             - Extensibility & Customization
  • Steps to make available and test Angular JS on a web page:
             - Download/refer "angular-version-x.js" on your page
             - Define an angular module using "angular.module"
             - Decorate an element using "ng-app" and attach to the module.
             - Use an angular expression to test angular js

Angular's History
  • 2010  -  Angular JS
  • 2016  - Angular Version 2
  • 2016  Dec - Angular Version 4
  • 2017 Nov  - Angular Version 5

Features of Angular JS
  • Used to create RIA
  • Helps to write application using MVC architecture
  • Application in Angular JS is cross-browser compliant.
  •  Automatically handles JavaScript code as per browser.

Monday, 17 September 2018

Data management: Sequence in R Language

Sequences

A sequence is a set of related numbers, events, movements, or items that follow each other in a particular order.

The regular sequences can be generate in R.

Syntax :-
seq ( )

seq (from = 1, to = 1, by = ( ( to from) / (length.out - 1) ), length.out = NULL, along.with = NULL, ...)

Help for seq

> help ("seq")

The default increment is +1 or -1

> seq (from = 2, to = 4)
     [1]  2  3  4

> seq (from = 4, to = 2)
    [1]  4  3  2

>seq (from = -4, to = 4)
   [1]  -4  -3  -2  -1  0  1  2  3  4

 
 Sequence with constant increment:


  Generate a sequence from 10 to 20 with an increment of 2 units

> seq (from = 10, to = 20 , by = 2)
   [1]  10  12  14  16  18  20


Generate a sequence from 20 to 10 with a decrement of 2 units

> seq (from = 20, to = 10, by = -2)
  [1]  20  18  16  14  12  10



Downstream sequence with constant increment:

Generate a sequence from 3 to -2 with a decrement of 0.5 units

> seq (from = 3, to = -2, by = -0.5)
  [1]  3.0  2.5  2.0  1.5  1.0  0.5  0.0  -0.5  -1.0  -1.5  -2



Sequence with a predefined length with default increment +1

> seq (to = 10, length = 10)
  [1]  1  2 3 4  5  6  7  8  9  10



Sequence with predefined length with constant fractional increment.

> seq (from = 10, length = 10, by = 0.1)
  [1]  10.0  10.1  10.2  10.3  10.4  10.5  10.6  10.7  10.8  10.9




Sequence with a predefined length with constant decrement

> seq (from = 10, length = 10, by = -2)
  [1]  10  8  6  4  2  0  -2  -4  -6  -8



Sequences with a predefined length with constant fractional decrement

> seq (from = 10, length = 5, by = -.2)
  [1]  10.0  9.8  9.6  9.4  9.2



Sequence with a predefined variable and constant increment

> x <-2
> seq (1, x, x/10)
  [1]  1.0  1.2  1.4  1.6  1.8  2.0

> x<-50
> seq (0, x, x/10)
  [1]  0  5  10  15  20  25  30  35  40  45  50




Saturday, 15 September 2018

Basic calculations: Truth table and conditional executions

Example of standard logical operations

Truth table


 
> x = TRUE
> y = FALSE

> x & y       # x AND y
[1]   FALSE

> x | y        # x OR y 
 [1]  TRUE

> !x          # negation of x
 [1] FALSE 


Example

> x <- 5
> Logical1  <- (x > 2)
> is.logical (Logical1)
 [1] TRUE

> Logical2 <- (x < 10)
> is.logical (Logical2)
 [1] TRUE

Example

> x <- 5
> Logical3 <-  (2*x > 11)
> is.logical (Logical3)
[1] TRUE

> Logical4  <-  (3*x <20)
> is.logical (Logical4)
 [1] TRUE


Control structures in R :

control statements,
loops,
function
Conditional execution

1. Conditional execution

Syntax

if (condition) {executes commands if condition is TRUE}
if (condition) {executes commands if condition is TRUE}

else {executes commands if condition is FALSE}

please note: 
  • The condition in this control statement may not be vector valued and if so, only the first element of the vector is used.
  • The condition may be complex expression where the logical operators "and" (&&) and "or" (| |) can be used.
Example

> x <- 5
> if ( x == 3)  { x <- x-1} else { x <- 2*x}
Interpretation:
  • If x = 3, then execute  x = x - 1.
  • If x ≠ 3, then execute x = 2*x.
In this case, x = 5 so x ≠ 3. Thus x = 2*5.

> x
 [1]  10

Now choose x = 3 and repeat this example


Friday, 14 September 2018

Basic calculations: Logical operators in R Languages

Logical Operators and Comparisons

The following table shows the operations and functions for logical comparisons (True or False).




Examples :

> x = 1 : 6       # Generates x=1,2,3,4,5,6
> (x > 2) & (x < 5)  # Checks whether the values are greater than 2 and less than 5

[1]  FALSE  FALSE  TRUE  TRUE  FALSE  FALSE

> x [(x > 2) & (x < 5)]  # Finds which values are greater than 2 and smaller than 5.
[1]   3  4



Logical Operators and Comparisons 



  • The shoter form performs element-wise comparisons in almost the same way as arithmetic operators.
  • The longer from evaluates left to right examining only the first element of each vector. Evaluation proceeds only until the result is determined.
Example of   " The longer form evaluates left to right examining only the first element of each vector"
> x = 1 : 6           # Generates x = 1,2,3,4,5,6

> (x > 2)  && (x < 5) 
 [1]  FALSE

is equivalent to:

> (x[1] > 2) & (x[1] < 5)
  [1]  FALSE


Note that x[1] is only the first element in x.

> x[ (x > 2) && (x < 5) ] 
   integer(0)                # Finds which values are greater than 2 and smaller than 5
This statement is equivalent to 

> x [ (x[1] > 2) & (x[1] < 5) ]
integer (0)


Thursday, 13 September 2018

Introduction to Python

What is Python?

Python is an interpreted High level programming Language for General purpose programming.
Python is created by Guido Van Rossem and first release in 1991.It is very dynamic and easy to use.



Scope :-
  • Application Development
  • Graphical Development
  • Game Development
  • Web Designing
  • Data Science
  • Machine Learning
  • Deep Learning 
Who Uses a Python?

YouTube :-  

The popular YouTube video sharing service is largely written in Python.


Google :-  

Google makes extensive use of Python in its web search systems.

Dropbox :-

Dropbox storage service codes both its server and desktop client software primarily in Python.

Raspberry :-

The Rasberry Pi single-board computer promotes Python as its educational language.

BitTorrent :-

BitTorrent peer-to-peer file sharing system began its life as a Python program.

NASA :-

NASA, Los Alamos, Fermilab, JPL, and other use Python for scientific programming tasks.

NSA :-

The NSA uses Python for cryptography and intelligence analysis.


NETFLIX :-

Netflix and Yelp have both documented the role of Python in their software infrastructures.


Python Features 
  •  Python is simple and easy to learn and also read and write.
  • Python is an example of a FLOSS (Free/Libre and Open Source Software)  which means one can freely distribute copies of this software, read it's source code, modify it, etc.
  • Python is a (High-level Language) one does need to bother about the low-level details like memory allocation, etc. while writing Python script
  • It is supported by many platforms like Linux, Windows, FreeBSD, Macintosh, Sloaris, OS/2, Amiga, AROS, AS/400, BeOS, OS/390, PlayStation, Windows CE, etc.
  • Python supports procedure-oriented programming as well as object-oriented programming.
  • Python code can invoke C and C++ libraries, can be called from and C++ programs, can integrate with Java and .NET components.
Top 5 Reasons to Learn Python

1. Dynamically Typed
     No type when declaring a variable
     Skip headaches of Java type casting
Java:      int x = 1;
               x = (int) x/2;              
                                         x now equals 0
                                         x can never equal 0.5
Python:     x = 1
                  x = x/2               x now equals 0.5

2. Simple Syntax 
  • Some programming languages will kill you with parentheses, brackets, braces, commas and colons.
  • With Python you spend less time debugging syntax and more time programming.
3. One-Liners 
  • Elegant 1-line solutions to what takes a whole block of code in other language.
  • One example: swap x and y
          Java:          int temp = x;
                            x = y;
                            y = temp;
          Python:     x,y = y,x         Wow! Now that's Pythonic

4. English-like Commands
            Java:       String name = "Bob";
                             System.out.println (name);
            Python:    name = "Bob"
                              print (name)

5. Intuitive Data Structures
          Lists, Tuples, Sets, Dictionaries
          Powerful, yet simple and intuitive to use
          Flexible (mixed data types)


Tuesday, 11 September 2018

Basic calculations: Missing data and logical operators in R Language

Missing data

R represents missing observations through the data value NA
We can detect missing values using is.na

> x  <-  NA             # assign NA to variable x
> is.na (x)               # is it missing ?
   [1]    TRUE

Now try a vector to know if any value is missing?

> x <-  c(11, NA, 13)
> is.na (x)
  [1] FALSE TRUE FALSE














Example : How to work with missing data

> x  <-  c(11, NA, 13)  # vector
> mean (x)     11 + NA + 13/2
  [1]   NA
> mean (x, na.rm = TRUE )  # NAs can be removed 
 [1]  12
                    11 + 13/2 = 12
The null object, called NULL, is returned by some functions and expressions.

Note that NA and NULL are not the same.

NA is a placeholder for something that exists but is missing.

NULL stands for something that never existed at all.





Logical Operators and Comparisons

The following table shows the operations and functions for logical comparisons (True or False)

TRUE and FALSE are reserved words denoting logical constants.


Logical Operators and Comparisons



  • The shorter form performs element-wise comparisons in almost the same way as arithmetic operators.
  • The longer form evaluates left to right examining only the first element of each vector. Evaluation proceeds only until the result is determined.
  • The longer form is appropriate for programming control-flow and typically preferred in if clauses (conditional).
TRUE and FALSE are reserved words denoting logical constants


Example

 > x  <- 5
Is x less than 10 or x is greater than 5 ?
 > (x < 10) | | (x > 5)   # | | means OR
 [1]  TRUE

Is x greater than 10 or x is greater than 5 ?
> (x > 10) | |  (x > 5)
[1] FALSE


Popular Posts

Categories

Android (21) AngularJS (1) Books (3) C (75) C++ (81) Data Strucures (4) Engineering (13) FPL (17) HTML&CSS (38) IS (25) Java (85) PHP (20) Python (83) R (68) Selenium Webdriver (2) Software (13) SQL (27)