Wednesday, 17 October 2018

Steps to write a programe with Examples of Programming in R Language

Steps to write a programme
  • A programme is a set of instructions or commands which are written in a sequence of operations i.e., what comes first and what comes after that.
  • The objective of a programme is to obtain a defined outcome based on input variables.
  • The computer is instructed to perform the defined task.
  • Computer is an obedient worker but it has its own language.
  • We do not understand computer's language and computer does not understand our language.
  • The software help us and work like an interpreter between us and computer.
  • We say something in software's language and software informs it to computer.
  • Computer does the task and informs back to software.
  • The software translates it to our language and informs us.
  • Programme in R is written as a function using function.
  • Write down the objective, i.e., what we want to obtain as an outcome.
  • Translate it in the language of R.
  • Identify the input and output variables.
  • Identify the nature of input and output, i.e., numeric string, factor, matrix etc.
  • Input and output variables can be single variable, vector, matrix or even a function itself.
  • The input variables are the component of function which are reported in the argument of function ( ) .
  • The output of a function can also be input to another function.
  • The output of an outcome can be formatted as per the need and requirement.   

Tips :
  1. Loops usually slower the speed of programmes, so better is to use vectors and matrices.
  2. Use # symbol to write comment to understand the syntax.
  3. Use the variable names which are easy to understand.
  4. Don't forget to initialize the variables.

Example 1

Input variables : x, y, n (if x and y have different number of observations, choose different numbers, say n1 and n2)

We need summation, so use sum function or alternatively computer it through vectors.


Post a Comment

Popular Posts


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 (85) R (69) Selenium Webdriver (2) Software (13) SQL (27)