Posts

Showing posts with the label Programming

How to remove NA values using R Programming

Image
Suppose that you got a csv file namely newedata.csv contains those following data.       Ozone Solar.R Wind Temp Month Day 1      41     190  7.4   67     5   1 2      36     118  8.0   72     5   2 3      12     149 12.6   74     5   3 4      18     313 11.5   62     5   4 5      NA      NA 14.3   56     5   5 6      28      NA 14.9   66     5   6 7      23     299  8.6   65     5   7 ................................................ ................................................ ................................................ 148    14      20 16.6   63     9  25 149   ...

How to Install R on Ubuntu

R is a programming language and software environment for statistical computing and graphics. The R language is widely used among statisticians and data miners for developing statistical software and data analysis.[From Wiki] There are Two way to install R on Ubuntu. Method 1: Using Terminal * Open Terminal and Type  sudo apt-get install r-base * After download to Start R  Programming  Type R on Terminal and Learn by Coding. Method 2 Installing R Studio * Go this site  and download it.

While loop VS for loop in PHP

For loop for (start value ; End value; Increment){ //do something } Example: for ($a = 10; $a "; } While loop start value while (End value){ //do something Increment } Example: $a = 10; while ($a "; $a = $a +10; }

Launching Sublime Text from command-line Windows

Lets see step by step Windows: 1. Download and Install Sublime Text and git 2.Find the directory where Sublime is installed.  If you do not change the directory during installation this should be here   C:/Program\ Files/Sublime\ Text\ 2/sublime_text.exe .  To confirm, that your directory is right, run this  ls C:/Program\ Files/Sublime\ Text\ 2  within Git Bash.  You should see  sublime_text.exe  listed.  If you get the error  No such file or directory , Sublime is installed somewhere else for you and you'll need to find it.  For example, in 64 bit PC it might be under C:/Program\ Files\ (x86) 3.Open Git Bash and run this   echo 'alias subl="C:/Program\ Files/Sublime\ Text\ 2/sublime_text.exe"' >> ~/.bashrc Finally Close and re-open Git Bash. Typing  subl  in Git Bash should now open Sublime.

How to Match with List in Python

months = ['January',           'February',           'March',           'April',           'May',           'June',           'July',           'August',           'September',           'October',           'November',           'December']           def valid_month(month):         if month in months:         return month     else:       ...

How to Find Leap Year with Python

Leap Year def how_to_find_leap_year(year): if (year%4==0 and (not year %100==0 or year%400==0)): return "Leap Year" return "Not Leap Year" print how_to_find_leap_year(1900)  Output  Not Leap Year

Find String in String with Python (sentence, word)

def find_your_word_from_sentence(sentence, word): n=0 while n check = sentence.find(word[n]) if check ==-1: return "Your Word is not found in given sentence." n=n+1 return word print find_your_word_from_sentence('This is city of technolgy, piano and violine also found here', 'techvolatile') Output: techvolatile

Find the Biggest Number Witth Python

Option 1: def biggest(a,b,c):     return max(a,b,c) print biggest (43,67,89) Option 2: def bigger (b,c):     if b>c:         return b     return c def biggest(a,b,c):         return bigger(a,bigger(b,c)) print biggest(48,60,17) Both is right

Python while loop to find Factorials of Number

def factorial (n): m=1 while n>=1: m=m*n n=n-1 return m print factorial(53) Output:4274883284060025564298013753389399649690343788366813724672000000000000

While Loop with Python

While loop is pretty awesome in Python. Lets see an example: def print_numbers(j): #define a function print_numbers i = 0 while (i!=j): i = i+1 #increment print i print_numbers(6) #call the function Output: 1 2 3 4 5 6

Convert any float number to Round number with Python

Sometimes you need to convert float number into round figure. Python has several way to do this 1. With round x = 34354.65756 round(x)  Output:34355.0 You can also define how many number after point. So look this  round(x,4) Output: 34354.6576 round(x,2) Output:34354.66 Another hard way to round float number, this code is found from Udacity. This code provide you no point after the round number. So look this code and code is very interesting x=34354.65756 num=x+0.5 s= str(num) point = s.find('.') print s[:point] Output:34355

How to find String in String using Python

example   about_me= "I am very a sgoode boy" start_link = about_me.find('sgoode') start_quote= about_me.find('s',start_link) #print start_quote end_quote=about_me.find('e',start_quote+1) #print end_quote me = about_me[start_quote+1:end_quote] print me output:good

How to remove duplicates item from a list using Python

Python is very easy but you have to think just like python   def remove_dulicates(alist): elist =[] #define an empty for new list without duplicate item for i in alist: if i not in elist: elist.append(i) return elist print remove_dulicates([2,2,2,1,3,4,5]) output:[2, 1, 3, 4, 5]

Remove vowels from a string using Python or Anti- Vowel

Removing vowels from text is very easy using python. But through internet search I found very hard way to do this. Just look the following links http://stackoverflow.com/questions/23176001/remove-vowels-from-a-string http://stackoverflow.com/questions/17299581/loop-forgets-to-remove-some-items http://pythonfiddle.com/remove-the-vowels/ But removing vowel could be done very easy and clean way, Just have a look   def anti_vowel(text): for char in text: if char in "aeiouAEIOU": text= text.replace(char, "") # Here vowel will be replaced by "" return text

How to run Python code from Sublime Text 2?

 To set up a complete Python IDE in Sublime Text 2. Go to Tools -> Build System -> (choose) Python then To Run your code:   Ctrl   +  B (For Windows) CMD + B (For OSX ) )     Enjoy Sublime Text 2         Update: You can use same rule to setup Sublime Text 3                                    

Literal notation vs Dot notation in Javascript

var myArray =[a:"book", b: "paper",c: "pen"]; myArray [a]; This is Literal Notation and gives us the value  "book". myArray.a; This is Literal Notation and gives us the value "book" Literal notation in object var student= { total: 0 }; Dot notation in object student.total = 0;

Class and Object in Javascript

Class function Cat(name, age) { this.name = name; this.age= age; } In above it is cat class Object var cat= new cat("remi", 4); In above it is cat object

How to Print Out All the property/propert value of Object in Javascript

First Define an Object with property and then use for /in loop with console to print out Example: Defining Object with property var fifa = { fullName: " International Federation of Association Football ", president: " Sepp Blatter", motto: " For the Game. For the World ", formation: " 21 May 1904 (110 years ago) " };  Now print out property  using for /in loop with console for (var property in fifa){ console.log(property); }  Now print out property value  using for /in loop with console for (var key in fifa){ console.log(fifa[key]); }

Function with Method in JavaScript

Example function Class (){ this . method = function (){ alert ( 'simple method' )}; }​​​​​​​​​ var object = new Class (); object . method ();​ Example with Method Speak and function person  function Person() { this.speak =function (){ console.log ("Hello!"); } } var user = new Person(); user.speak();   Here speak is a method of Person function

List of programming languages

Programming language is the way to instruct the machine.   There are lots of programming languages. List of all notable programming language is made different ways. In Wikipedia you will find the list as following Alphabetical Categorical Chronological Generational