**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 :**

- Loops usually slower the speed of programmes, so better is to use vectors and matrices.
- Use # symbol to write comment to understand the syntax.
- Use the variable names which are easy to understand.
- 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.

Enjoyed reading the article above, really explains everything in detail, the article is very interesting and effective. Thank you and good luck for the upcoming articles Python Programming Training

ReplyDelete