How to get first and last rows of Data Frame in R

We can get first n rows of Data Frame using head() function and can get last n rows of Data Frame using tail() function.

Syntax of head() and tail() functions:

head(data.frame,number_of_first_rows) tail(data.frame,number_of_last_rows)

Convert List to Vector in R

A list can be converted to a Vector in R. So that the elements of the vector can be used for further manipulation. All arthimetic operations o vectors can be applied after the the list is converted to vectors. We can convert list to vector using unlist() function. It takes list as input and produces vector as output.

How to get list of User defined Variables in R

Variables are containers to for storing data in any programming language. We get the list of variables defined in R Programming Language using ls(), objects() functions. R Variables starting with dot(.) are hidden, they can be listed using ls(all:names=TRUE).

Examples:

Copy a table structure in MySQL

We can clone or copy a table structure in MySQL using LIKE or AS operators.

Using LIKE:

We can use CREATE TABLE … LIKE to create an empty table based on the definition of another table, including any column fields and indexes defined in the original table:

Syntax:

CREATE TABLE new_table LIKE original_table;

Change USER password in MySQL

We can the user password in MySQL, using UPDATE, SET, ALTER command. To change password, current login user must have granted permissions on user table of mysql database and must have UPDATE, SET and ALTER permissions on user table.

To reset password in MySQL 5.6 or older versions(This statement not works in MySQL 5.7 or later versions. Password filed is replaced with authentication_string field in MySQL 5.7 Version)

UPDATE mysql.user SET Password=PASSWORD(‘NewPassHere’) WHERE User=’admin’;

emp table script MySQL

Standard emp table script for MySQL Server

1) Create table structure
2) Insert data into emp table

Extract tar files in Linux

Many of beginners dont know how to extract tar files in Linux.

What is tar file?

TAR actually stands for tape archive. This is a standard format in Unix/Linx. TAR files are the most popular form of archive used on a Unix/Linux system. The extension is .tar.gz or .tar.bz2

Extract tar files in Linux:

Change root password in mysql 5.7

In MySQL 5.7, the password field in mysql.user table field is removed. It is replaced authentication_string.

Steps:

1. First select mysql database, which stores users information.

mysql>use mysql;

2. And then show the tables. We will find the user table.

mysql> show tables;

3. To get user table fields:

mysql> describe user;

ERROR 1054 (42S22): Unknown column ‘Password’ in ‘field list’ MySQL

mysql> UPDATE mysql.user SET Password=PASSWORD(‘test@123′) WHERE User=’root’;
ERROR 1054 (42S22): Unknown column ‘Password’ in ‘field list’

Casue:In MySQL 5.7, the password field in mysql.user table field is removed. It is replaced authentication_string.

Steps:

1. First select mysql database, which stores users information.

mysql>use mysql;

2. And then show the tables. We will find the user table.

mysql> show tables;

3. To get user table fields:

mysql> describe user;

Powered by k2schools