Search icon CANCEL
Subscription
0
Cart icon
Your Cart (0 item)
Close icon
You have no products in your basket yet
Save more on your purchases! discount-offer-chevron-icon
Savings automatically calculated. No voucher code required.
Arrow left icon
All Products
Best Sellers
New Releases
Books
Videos
Audiobooks
Learning Hub
Newsletter Hub
Free Learning
Arrow right icon
timer SALE ENDS IN
0 Days
:
00 Hours
:
00 Minutes
:
00 Seconds
Arrow up icon
GO TO TOP
RStudio for R Statistical Computing Cookbook

You're reading from   RStudio for R Statistical Computing Cookbook Over 50 practical and useful recipes to help you perform data analysis with R by unleashing every native RStudio feature

Arrow left icon
Product type Paperback
Published in Apr 2016
Publisher
ISBN-13 9781784391034
Length 246 pages
Edition 1st Edition
Languages
Tools
Arrow right icon
Author (1):
Arrow left icon
Andrea Cirillo Andrea Cirillo
Author Profile Icon Andrea Cirillo
Andrea Cirillo
Arrow right icon
View More author details
Toc

Table of Contents (15) Chapters Close

RStudio for R Statistical Computing Cookbook
Credits
About the Author
About the Reviewer
www.PacktPub.com
Preface
1. Acquiring Data for Your Project FREE CHAPTER 2. Preparing for Analysis – Data Cleansing and Manipulation 3. Basic Visualization Techniques 4. Advanced and Interactive Visualization 5. Power Programming with R 6. Domain-specific Applications 7. Developing Static Reports 8. Dynamic Reporting and Web Application Development Index

Comparing an alternative function's performance using the microbenchmarking package


When dealing with efficiency issues, a fast way to evaluate two alternative functions can be really useful.

This recipe is going to show you how to do this quickly and effectively and display the results of your comparison in a ggplot diagram that is easy to understand.

Getting ready

This recipe is going to leverage the microbenchmark package to compute the function comparison and the ggplot2 package for comparison plotting:

install.packages(c("microbenchmark","ggplot2"))
library(microbenchmark)
library(ggplot2)

The example that follows is represented by two alternative functions to determine, for a given numeric vector, which elements of the vector are even and which are odd.

Therefore, we first need to initialize the vector we are going to use, populating it with a sequence of numbers from 1 to 1000:

vector <- seq(1:1000)

How to do it...

  1. First, we need to define the functions that are to be compared. In order...

lock icon The rest of the chapter is locked
Register for a free Packt account to unlock a world of extra content!
A free Packt account unlocks extra newsletters, articles, discounted offers, and much more. Start advancing your knowledge today.
Unlock this book and the full library FREE for 7 days
Get unlimited access to 7000+ expert-authored eBooks and videos courses covering every tech area you can think of
Renews at $15.99/month. Cancel anytime
Visually different images