Monday, August 19, 2013

How To Create Scheduled Jobs With Crontab in Linux

Hi everyone!


In this article, I want to talk about cronjob. Some of us heard about this subject before. Cronjob scheduled task used in the sense of is very important for us. Because you can use it everytime you have to set some scripts will run next date. So, imagine that you have got a web site there are so many users on it. If you want to send e-mail to all your members at 02:00 am, here is the time you need cronjob!

Some hosting companies offer to manage cronjob service, but not all. Because of it is every hosting have not CPanel. Maybe you can use SSH or something else. Me, show you how to manage cronjob using SSH. In this regard, open your Unix Server using SSH, and;

vi /etc/crontab

* * * * * ( [minute] [hour] [day] [month] [day of the week] )
┬ ┬ ┬ ┬ ┬
│ │ │ │ │
│ │ │ │ │
│ │ │ │ └───── day of the week (0 – 7) (total 7 days)
│ │ │ └────────── month (1 – 12)
│ │ └─────────────── day (1 – 31)
│ └──────────────────── hour (0 – 23)
└───────────────────────── minute (0 – 59)

//test.php file
$db->query("INSERT INTO db_name.table_name(field_name) values('test')");
 
#cronjob file
* * * * * username php test.php

The code given above shows us the script that adds data to the database every minutes.
*/15 * * * * username php test.php

The code given above also shows us the script that adds data to the database every 15 minutes.
#02:00am at night
00 02 * * * username php test.php
 
#every 3 hours during the day
0 */3 * * * username php test.php
 
#each hour
0 * * * * username php test.php
 
#4 pm o'clock on the 15th day of each month
00 16 15 * * username php test.php
 
#weeks every night at 2 am
00 02 * * 1-5 username php test.php
 
#every hour every Sunday
0 * * * sun
 
#every 3 hours
0 2,5,8,11,14,17,20,23 * * * username php test.php

The codes given above shows us different cronjob examples. You can try and work for creative and usefull cronjob examples.
We'll see you guys next article!

Linear Regression Revisited



If she loves you more each and every day, by linear regression she hated you before you met.






- Your theory is wrong!
- Out, liar! 


Sunday, August 18, 2013

Econometrics Beat: Dave Giles' Blog: Large and Small Regression Coefficients

Econometrics Beat: Dave Giles' Blog: Large and Small Regression Coefficients: Here's a trap that newbies to regression analysis have been known to fall into. It's to do with comparing the numerical values of t...

Generating LaTeX Tables in R

Generating LATEXTables in R

jbytecode

August 18, 2013

Many R users prepare reports, documents or research papers using LATEXtype-setting system. Since typing tabular data structures in LATEXby hand consumes too much construction time, some packages were developed for automatic creation or conversion of R datasets. In this short entry, we show the usage and output of xtable function in xtable package. First install the package if it is not already installed:

> install.packages(”xtable”)

After installation, the package is loaded once in the current session:

> require(”xtable”)

Now, suppose that we have a data frame and we want to export it as a LATEXtable. Let’s create a random dataset with three variables, x,y and z.

> x<-round(runif(10,0,100)) 
> y<-round(runif(10,0,100)) 
> z<-round(runif(10,0,100)) 
> data <- as.data.frame ( cbind(x,y,z) ) 
> data 
    x   y  z 
1  26  86 44 
2  81  13 22 
3  39  27 57 
4  32  57 56 
5  50  15 31 
6  34 100 98 
7  54  46 24 
8  42  55 42 
9  62  91 77 
10  5  73 25

Calling the function xtable simply on the data that we have just created produces some output:

> xtable(data)
% latex table generated in R 2.15.3 by xtable 1.7-1 package  
% Sun Aug 18 23:40:23 2013  
\begin{table}[ht]  
\centering  
\begin{tabular}{rrrr}  
  \hline  
 & x & y & z \\  
  \hline  
1 & 26.00 & 86.00 & 44.00 \\  
  2 & 81.00 & 13.00 & 22.00 \\  
  3 & 39.00 & 27.00 & 57.00 \\  
  4 & 32.00 & 57.00 & 56.00 \\  
  5 & 50.00 & 15.00 & 31.00 \\  
  6 & 34.00 & 100.00 & 98.00 \\  
  7 & 54.00 & 46.00 & 24.00 \\  
  8 & 42.00 & 55.00 & 42.00 \\  
  9 & 62.00 & 91.00 & 77.00 \\  
  10 & 5.00 & 73.00 & 25.00 \\  
   \hline  
\end{tabular}  
\end{table}

The generated output can easly be integrated with an LATEXfile. This table is shown as






x y z




126.00 86.0044.00
281.00 13.0022.00
339.00 27.0057.00
432.00 57.0056.00
550.00 15.0031.00
634.00100.0098.00
754.00 46.0024.00
842.00 55.0042.00
962.00 91.0077.00
10 5.00 73.0025.00





This is an example of xtable function call with default parameters. In the next example, we put a caption.

> xtable(data,caption=”Our random dataset”)






x y z




126.00 86.0044.00
281.00 13.0022.00
339.00 27.0057.00
432.00 57.0056.00
550.00 15.0031.00
634.00100.0098.00
754.00 46.0024.00
842.00 55.0042.00
962.00 91.0077.00
10 5.00 73.0025.00





Table 1: Our random dataset

Let’s put a label on it:

> xtable(data,caption=”Our random dataset”, 
                          label=”This is a label”)






x y z




126.00 86.0044.00
281.00 13.0022.00
339.00 27.0057.00
432.00 57.0056.00
550.00 15.0031.00
634.00100.0098.00
754.00 46.0024.00
842.00 55.0042.00
962.00 91.0077.00
10 5.00 73.0025.00





Table 2: Our random dataset

And this function call shows the numbers with three fractional digits.

> xtable(data,caption=”Our random dataset”, 
                label=”This is a label”, 
                digits=3)






x y z




126.000 86.00044.000
281.000 13.00022.000
339.000 27.00057.000
432.000 57.00056.000
550.000 15.00031.000
634.000100.00098.000
754.000 46.00024.000
842.000 55.00042.000
962.000 91.00077.000
10 5.000 73.00025.000





Table 3: Our random dataset

Sorting Multi-Column Datasets in R

Sorting Multi-Column Datasets in R


August 18, 2013

In this entry, we present the most straightforward way to sort multi-column datasets

Suppose that we have a vector in three dimensional space. This vector can be defined as

<- c(3,1,2)

in R. The built-in function sort sorts a given vector in ascending order by default. An ordered version of vector a is calculated as shown below:

sorted_<- sort(a)

The result is

[1] 1 2 3

For reverse ordering, the value of decreasing parameter must be set to TRUE.

> sort(a,decreasing=TRUE) 
[1] 3 2 1

Another related function order returns indices of sorted elements.

> a <- c(3,1,2) 
> order (a) 
[1] 2 3 1

In the example above, it is shown that if the vector a is ordered in ascending order, second element of a will be placed at index 1. It is easy to show that, result of the function order can be used to sort data.

> a <- c(3,1,2) 
> o <- order (a) 
> a[o] 
[1] 1 2 3

Suppose that we need to sort a matrix by a desired row. The solution is easy. Get the indices of sorted desired column and use the same method as in example given above.

> x <- round(runif(5, 0, 100)) 
> y <- round(runif(5, 0, 100)) 
> z <- round(runif(5, 0, 100)) 
> data <- cbind(x,y,z) 
> data 
      x  y  z 
[1,] 48 35 75 
[2,] 40 21 43 
[3,] 58 69  1 
[4,] 49 38  2 
[5,] 43 66 46

Now, get the indices of sorted z:

> o <- order(z) 
> data[o,] 
      x  y  z 
[1,] 58 69  1 
[2,] 49 38  2 
[3,] 40 21 43 
[4,] 43 66 46 
[5,] 48 35 75

Finally, we sorted the dataset data by the column vector z.