Create Random Vector of Increasing Integers in R

Nizamuddin Siddiqui
Updated on 11-Feb-2021 11:44:49

299 Views

To create a random vector of integers with increasing values, we can do random sampling with sample.int and for increasing values cummax function needs to be used. For example, to create a random vector of integers of size 5 up to values 5 starting from 1 can be done by using the command cummax(sample.int(5)).Example Live Demox1

Get List of Available Data Frames in R Environment

Nizamuddin Siddiqui
Updated on 11-Feb-2021 11:42:02

2K+ Views

When we perform any type of data analysis, there are many types of objects that are created in the R environment such as vector, data frame, matrix, lists, arrays, etc. If we want to get the list of available data frames in R environment then we can use the below command −names(which(unlist(eapply(.GlobalEnv,is.data.frame))))Example Live Demox1

Convert Numeric Columns to Factor Using dplyr Package in R

Nizamuddin Siddiqui
Updated on 11-Feb-2021 11:36:42

4K+ Views

If we have a numeric column in an R data frame and the unique number of values in the column is low that means the numerical column can be treated as a factor. Therefore, we can convert numeric columns to factor. To do this using dplyr package, we can use mutate_if function of dplyr package.Loading dplyr package and converting numerical columns in BOD data set (available in base R) to factor columns −Examplelibrary(dplyr) str(BOD) 'data.frame': 6 obs. of 2 variables: $ Time : num 1 2 3 4 5 7 $ demand: num 8.3 10.3 19 16 15.6 19.8 - ... Read More

Create Reverse of a Number in R

Nizamuddin Siddiqui
Updated on 11-Feb-2021 11:32:29

2K+ Views

To create reverse of a number, we can use stri_reverse function of stringi package. For example, if we have a vector called x that contain some numbers then the reverse of these numbers will be generated by using the command stri_reverse(x). But the output will be in character form, if we want to have numeric values then as.numeric function can be used.library(stringi)Example Live Demox1

What is Python's sys Module

S Vijay Balaji
Updated on 11-Feb-2021 06:49:05

8K+ Views

IntroductionThe sys module in Python provides valuable information about the Python interpreter. You can also use it to obtain details about the constants, functions and methods of the Python interpreter.Getting StartedThe sys module comes packaged with Python, which means you do not need to download and install it separately using the PIP package manager.In order to start using the sys module and its various functions, you need to import it. You can do that using the below line of code, import sysObtaining the list of argumentsIn python, we can execute the script directly from our terminal using various arguments. Sometimes ... Read More

What is Python's os Module

S Vijay Balaji
Updated on 11-Feb-2021 06:47:49

2K+ Views

IntroductionThe OS module in Python comes with various functions that enables developers to interact with the Operating system that they are currently working on. In this article we’ll be learning mainly to create and delete a directory/folder, rename a directory and even basics of file handling.Without further ado, let’s get started.Getting StartedPython’s OS module comes packaged within python when installed. This means you do not need to separately install it using PIP. In order to access its various methods/functions, you just need to import the module.import osNow that you’ve imported the module, you can start using its various functions.Getting current ... Read More

Reading and Writing Excel Files Using OpenPyXL Module in Python

S Vijay Balaji
Updated on 11-Feb-2021 06:46:38

2K+ Views

Introductionopenpyxl is a Python library to read/write Excel 2010 xlsx/xlsm/xltx/xltm files.It was born from lack of existing library to read/write natively from Python the Office Open XML format.An excel file that we use for operation is called Workbook that contains a minimum of one Sheet and a maximum of tens of sheets.One sheet consists of rows starting from 1 and columns starting from A.Using the openpxyl library, we can perform various functions including adding sheets and data, manipulate and even delete said data.Now that we know what we are dealing with, let us get started.Getting StartedThe openpyxl does not come ... Read More

Validate Data Using Cerberus in Python

S Vijay Balaji
Updated on 11-Feb-2021 06:44:52

2K+ Views

IntroductionThe Cerberus module in python provides powerful yet lightweight data validation functions. It is designed in such a way that you can extend it to various applications and custom validations.We first define a schema and then validate the data against the scheme and check if it matches the provided conditions or not. If not, accurate errors are thrown to display where it went wrong.Various conditions can be applied at once to the data field for validation.Getting startedIn order to use Cerberus, you must first install it, as it does not come packaged with Python.In order to download and install it, ... Read More

Match Patterns and Strings Using the Regex Module in Python

S Vijay Balaji
Updated on 11-Feb-2021 06:42:22

279 Views

IntroductionThe RegEx module stands for Regular expressions. If you have already worked on programming, you would have come across this term several times already. We use the Regular expressions to search and replace, it is used in various text editors, search engines, word processors, etc.In other words, it helps match a certain pattern that you are looking for.A good example for this would be how your collage website allows you to use only your university mail and none of the other extensions.Getting StartedThe regular expression module comes packaged within Python. You do not need to download and install it separately.In ... Read More

Encrypt and Decrypt Data in Python

S Vijay Balaji
Updated on 11-Feb-2021 06:39:10

18K+ Views

IntroductionWhat is cryptography? Cryptography deals with the conversion of plain text into cipher text which is called encryption of data and cipher text back to plain text which is called decryption of data.We will be using the fernet module in the cryptography package to encrypt and decrypt data using Python. While using the fernet module, a unique key is generated without which you cannot read or manipulate the encrypted data.Now that you know what we will be dealing with, let’s get started.Getting StartedThe cryptography module does not come packaged with Python, which means you will have to install it using ... Read More

Advertisements