Search icon CANCEL
Subscription
0
Cart icon
Your Cart (0 item)
Close icon
You have no products in your basket yet
Arrow left icon
Explore Products
Best Sellers
New Releases
Books
Videos
Audiobooks
Learning Hub
Free Learning
Arrow right icon
Modern R Programming Cookbook
Modern R Programming Cookbook

Modern R Programming Cookbook: Recipes to simplify your statistical applications

Arrow left icon
Profile Icon Jaynal Abedin
Arrow right icon
Free Trial
Paperback Oct 2017 236 pages 1st Edition
eBook
zł59.99 zł158.99
Paperback
zł197.99
Subscription
Free Trial
Arrow left icon
Profile Icon Jaynal Abedin
Arrow right icon
Free Trial
Paperback Oct 2017 236 pages 1st Edition
eBook
zł59.99 zł158.99
Paperback
zł197.99
Subscription
Free Trial
eBook
zł59.99 zł158.99
Paperback
zł197.99
Subscription
Free Trial

What do you get with a Packt Subscription?

Free for first 7 days. $19.99 p/m after that. Cancel any time!
Product feature icon Unlimited ad-free access to the largest independent learning library in tech. Access this title and thousands more!
Product feature icon 50+ new titles added per month, including many first-to-market concepts and exclusive early access to books as they are being written.
Product feature icon Innovative learning tools, including AI book assistants, code context explainers, and text-to-speech.
Product feature icon Thousands of reference materials covering every tech concept you need to stay up to date.
Subscribe now
View plans & pricing
Table of content icon View table of contents Preview book icon Preview Book

Modern R Programming Cookbook

Data Structures in R

In this chapter, you will learn about the data structures of R and how to create and access its properties, and various operations related to a specific data structure. The following recipes will be covered in this chapter:

  • Creating a vector and accessing its properties
  • Creating a matrix and accessing its properties
  • Creating a data frame and accessing its properties
  • Creating an array and accessing its properties
  • Creating a list from a combination of vector, matrix, and data frames
  • Converting a matrix to a data frame and a data frame to a matrix

Introduction

To use R most efficiently and effectively, you must understand the data types and data structures of R, because the Machine Learning algorithms such as Support Vector Machine (SVM), decision tree, and even linear regression and logistic regression have optimization components. The use of the correct data types is the key part of the performance of optimization. Also, to perform matrix operations, the user must use matrix data types. Moreover, the user needs to know the use of correct variables into the statistical model, and understanding R data types is the important aspect in this area. Here are the data types that will help you store and manage your data correctly and efficiently:

  • Character
  • Numeric
  • Logical
  • Integer
  • Complex

The data structure of R is the way to organize the dataset for data storage and analytics purposes. Each of the different data structures can...

Creating a vector and accessing its properties

In this recipe, you will learn what a vector is in R, and how to create it, access its properties, and perform certain operations.

Getting ready

To follow this recipe, you need the R software installed on your computer. Before going to the next step, you have to understand the definition of a vector in R. In R, a vector is simply a collection of values with the same type; it could be all character, numeric, or logical. For example, it could contain names of places/countries, it could contain the number of hours a person spends on the internet over the last seven days, or it could also contain whether a group of people has a certain disease or not (true/false).

...

Creating a matrix and accessing its properties

A matrix is a two-dimensional arrangement of vectors of the same type. Like vectors in R, the matrix is restricted to one data type. In this recipe, you will learn how to create a matrix, how to access its elements, and understand a few notes on matrix operations.

Getting ready

To get started with this recipe, you must have R installed on your computer. You also need to understand the structure of a matrix and various operations. There is no library required for this recipe, but if you are interested in advanced matrix algebra, then you might consider the See also section of this recipe. A matrix is considered as a two-dimensional grid where each cell is represented by a row and...

Creating a data frame and accessing its properties

A data frame in R is also a two-dimensional arrangement like a matrix, but it can contain a combination of data types in different columns. One column could be numeric, another column could be character. A data frame can be considered as a natural generalization of a matrix in R. In this recipe, you will learn how to create a data frame and how to access various columns and/or elements of it.

Getting ready

Since you have already learned to create a matrix, it will be relatively simple to understand the data frame. It is good to have an understanding of variables and datasets. Though the structure of a data frame is similar to a matrix, it has more information within it.

...

Creating an array and accessing its properties

An array is a way to organize data of the same type in more than two dimensions. An array could be of any dimension, and the data type must be the same in each of the array elements. A matrix is a special case of an array with only two dimensions. In this recipe, you will learn how to create an array and how to access its elements.

Getting ready

Suppose you are in a situation where you must store a series of matrices into a single R object and then perform analysis based on that; however, in this case, this is the perfect and efficient way to create an array. For example, you are in a situation to store four matrices of 2 x 2 order.

...

Creating a list from a combination of vector, matrix, and data frame

A list is the natural generalization of a data frame in R. A data frame is a rectangular arrangement of rows and columns where each of the columns must be of the same length. A list can contain a variety of heterogeneous objects with various lengths and data types. An array contains only one data type, whereas a list could contain heterogeneous data types of various lengths. In that sense, a list is also a natural generalization of an array. A list is a versatile R object, and it is important to know how it stores elements and how you can access it. In this recipe, you will learn how to create a list and access its elements.

Getting ready

Recall that you...

Converting a matrix to a data frame and a data frame to a matrix

A matrix is a two-dimensional arrangement of data with rows and columns where each row/column is of the same data type, either all numeric, all character, or all logical. Moreover, the number of elements in each column should be the same, and the number of elements in each row should also be the same.

A data frame is also a two-dimensional arrangement of data with rows and columns, but each column could be of very different types; for example, a data frame may contain both character and numeric columns. However, the number of elements in each column should be the same. Since both data structures share some common properties, they could be converted from one structure to another. In this recipe, you will learn to convert a matrix to a data frame and a data frame to a matrix.

...
Left arrow icon Right arrow icon
Download code icon Download Code

Key benefits

  • Develop strategies to speed up your R code
  • Tackle programming problems and explore both functional and object-oriented programming techniques
  • Learn how to address the core problems of programming in R with the most popular R packages for common tasks

Description

R is a powerful tool for statistics, graphics, and statistical programming. It is used by tens of thousands of people daily to perform serious statistical analyses. It is a free, open source system whose implementation is the collective accomplishment of many intelligent, hard-working people. There are more than 2,000 available add-ons, and R is a serious rival to all commercial statistical packages. The objective of this book is to show how to work with different programming aspects of R. The emerging R developers and data science could have very good programming knowledge but might have limited understanding about R syntax and semantics. Our book will be a platform develop practical solution out of real world problem in scalable fashion and with very good understanding. You will work with various versions of R libraries that are essential for scalable data science solutions. You will learn to work with Input / Output issues when working with relatively larger dataset. At the end of this book readers will also learn how to work with databases from within R and also what and how meta programming helps in developing applications.

Who is this book for?

This book is for developers who would like to enhance the R programming skills. Basic knowledge of R programming is assumed.

What you will learn

  • • Install R and its various IDE for a given platform along with installing libraries from different repositories and version control
  • • Learn about basic data structures in R and how to work with them
  • • Write customized R functions and handle recursions, exceptions in R environments
  • • Create the data processing task as a step by step computer program and execute using dplyr
  • • Extract and process unstructured text data
  • • Interact with database management system to develop statistical applications
  • • Formulate and implement parallel processing in R

Product Details

Country selected
Publication date, Length, Edition, Language, ISBN-13
Publication date : Oct 10, 2017
Length: 236 pages
Edition : 1st
Language : English
ISBN-13 : 9781787129054
Category :
Languages :

What do you get with a Packt Subscription?

Free for first 7 days. $19.99 p/m after that. Cancel any time!
Product feature icon Unlimited ad-free access to the largest independent learning library in tech. Access this title and thousands more!
Product feature icon 50+ new titles added per month, including many first-to-market concepts and exclusive early access to books as they are being written.
Product feature icon Innovative learning tools, including AI book assistants, code context explainers, and text-to-speech.
Product feature icon Thousands of reference materials covering every tech concept you need to stay up to date.
Subscribe now
View plans & pricing

Product Details

Publication date : Oct 10, 2017
Length: 236 pages
Edition : 1st
Language : English
ISBN-13 : 9781787129054
Category :
Languages :

Packt Subscriptions

See our plans and pricing
Modal Close icon
$19.99 billed monthly
Feature tick icon Unlimited access to Packt's library of 7,000+ practical books and videos
Feature tick icon Constantly refreshed with 50+ new titles a month
Feature tick icon Exclusive Early access to books as they're written
Feature tick icon Solve problems while you work with advanced search and reference features
Feature tick icon Offline reading on the mobile app
Feature tick icon Simple pricing, no contract
$199.99 billed annually
Feature tick icon Unlimited access to Packt's library of 7,000+ practical books and videos
Feature tick icon Constantly refreshed with 50+ new titles a month
Feature tick icon Exclusive Early access to books as they're written
Feature tick icon Solve problems while you work with advanced search and reference features
Feature tick icon Offline reading on the mobile app
Feature tick icon Choose a DRM-free eBook or Video every month to keep
Feature tick icon PLUS own as many other DRM-free eBooks or Videos as you like for just zł20 each
Feature tick icon Exclusive print discounts
$279.99 billed in 18 months
Feature tick icon Unlimited access to Packt's library of 7,000+ practical books and videos
Feature tick icon Constantly refreshed with 50+ new titles a month
Feature tick icon Exclusive Early access to books as they're written
Feature tick icon Solve problems while you work with advanced search and reference features
Feature tick icon Offline reading on the mobile app
Feature tick icon Choose a DRM-free eBook or Video every month to keep
Feature tick icon PLUS own as many other DRM-free eBooks or Videos as you like for just zł20 each
Feature tick icon Exclusive print discounts

Frequently bought together


Stars icon
Total 641.97
R Data Analysis Projects
zł221.99
R Programming By Example
zł221.99
Modern R Programming Cookbook
zł197.99
Total 641.97 Stars icon
Banner background image

Table of Contents

9 Chapters
Installing and Configuring R and its Libraries Chevron down icon Chevron up icon
Data Structures in R Chevron down icon Chevron up icon
Writing Customized Functions Chevron down icon Chevron up icon
Conditional and Iterative Operations Chevron down icon Chevron up icon
R Objects and Classes Chevron down icon Chevron up icon
Querying, Filtering, and Summarizing Chevron down icon Chevron up icon
R for Text Processing Chevron down icon Chevron up icon
R and Databases Chevron down icon Chevron up icon
Parallel Processing in R Chevron down icon Chevron up icon
Get free access to Packt library with over 7500+ books and video courses for 7 days!
Start Free Trial

FAQs

What is included in a Packt subscription? Chevron down icon Chevron up icon

A subscription provides you with full access to view all Packt and licnesed content online, this includes exclusive access to Early Access titles. Depending on the tier chosen you can also earn credits and discounts to use for owning content

How can I cancel my subscription? Chevron down icon Chevron up icon

To cancel your subscription with us simply go to the account page - found in the top right of the page or at https://subscription.packtpub.com/my-account/subscription - From here you will see the ‘cancel subscription’ button in the grey box with your subscription information in.

What are credits? Chevron down icon Chevron up icon

Credits can be earned from reading 40 section of any title within the payment cycle - a month starting from the day of subscription payment. You also earn a Credit every month if you subscribe to our annual or 18 month plans. Credits can be used to buy books DRM free, the same way that you would pay for a book. Your credits can be found in the subscription homepage - subscription.packtpub.com - clicking on ‘the my’ library dropdown and selecting ‘credits’.

What happens if an Early Access Course is cancelled? Chevron down icon Chevron up icon

Projects are rarely cancelled, but sometimes it's unavoidable. If an Early Access course is cancelled or excessively delayed, you can exchange your purchase for another course. For further details, please contact us here.

Where can I send feedback about an Early Access title? Chevron down icon Chevron up icon

If you have any feedback about the product you're reading, or Early Access in general, then please fill out a contact form here and we'll make sure the feedback gets to the right team. 

Can I download the code files for Early Access titles? Chevron down icon Chevron up icon

We try to ensure that all books in Early Access have code available to use, download, and fork on GitHub. This helps us be more agile in the development of the book, and helps keep the often changing code base of new versions and new technologies as up to date as possible. Unfortunately, however, there will be rare cases when it is not possible for us to have downloadable code samples available until publication.

When we publish the book, the code files will also be available to download from the Packt website.

How accurate is the publication date? Chevron down icon Chevron up icon

The publication date is as accurate as we can be at any point in the project. Unfortunately, delays can happen. Often those delays are out of our control, such as changes to the technology code base or delays in the tech release. We do our best to give you an accurate estimate of the publication date at any given time, and as more chapters are delivered, the more accurate the delivery date will become.

How will I know when new chapters are ready? Chevron down icon Chevron up icon

We'll let you know every time there has been an update to a course that you've bought in Early Access. You'll get an email to let you know there has been a new chapter, or a change to a previous chapter. The new chapters are automatically added to your account, so you can also check back there any time you're ready and download or read them online.

I am a Packt subscriber, do I get Early Access? Chevron down icon Chevron up icon

Yes, all Early Access content is fully available through your subscription. You will need to have a paid for or active trial subscription in order to access all titles.

How is Early Access delivered? Chevron down icon Chevron up icon

Early Access is currently only available as a PDF or through our online reader. As we make changes or add new chapters, the files in your Packt account will be updated so you can download them again or view them online immediately.

How do I buy Early Access content? Chevron down icon Chevron up icon

Early Access is a way of us getting our content to you quicker, but the method of buying the Early Access course is still the same. Just find the course you want to buy, go through the check-out steps, and you’ll get a confirmation email from us with information and a link to the relevant Early Access courses.

What is Early Access? Chevron down icon Chevron up icon

Keeping up to date with the latest technology is difficult; new versions, new frameworks, new techniques. This feature gives you a head-start to our content, as it's being created. With Early Access you'll receive each chapter as it's written, and get regular updates throughout the product's development, as well as the final course as soon as it's ready.We created Early Access as a means of giving you the information you need, as soon as it's available. As we go through the process of developing a course, 99% of it can be ready but we can't publish until that last 1% falls in to place. Early Access helps to unlock the potential of our content early, to help you start your learning when you need it most. You not only get access to every chapter as it's delivered, edited, and updated, but you'll also get the finalized, DRM-free product to download in any format you want when it's published. As a member of Packt, you'll also be eligible for our exclusive offers, including a free course every day, and discounts on new and popular titles.