1. Home
  2. /
  3. R
  4. /
  5. Random Number Generator

Random Number Generator - R Typing CST Test

Loading…

Random Number Generator — R Code

Generates random numbers between 1 and 100 and prints them.

set.seed(123)
for (i in 1:3) {
	num <- sample(1:100, 1)
	cat(paste0('Random ', i, ': ', num, '\n'))
}

R Language Guide

R is a high-level, interpreted programming language and environment specifically designed for statistical computing, data analysis, and graphical representation. It provides a rich ecosystem of packages and functions for statistical modeling, data visualization, and reproducible research.

Primary Use Cases

  • ▸Statistical modeling and hypothesis testing
  • ▸Data visualization and reporting
  • ▸Machine learning and predictive analytics
  • ▸Bioinformatics and genomic data analysis
  • ▸Financial and econometric analysis

Notable Features

  • ▸Extensive statistical functions and packages
  • ▸High-quality graphics with ggplot2 and base plotting
  • ▸Vectorized operations for efficient computation
  • ▸Data frame and tibble structures for data manipulation
  • ▸CRAN repository with thousands of contributed packages

Origin & Creator

Created by Ross Ihaka and Robert Gentleman at the University of Auckland, New Zealand, in 1993 as an open-source alternative to S and S-PLUS.

Industrial Note

R is heavily used in statistical research, data science, machine learning experiments, and academic publications where reproducible data analysis is critical.

Quick Explain

  • ▸R allows statisticians and data scientists to perform complex data analyses efficiently.
  • ▸It integrates statistical techniques, machine learning algorithms, and high-quality graphics in a single platform.
  • ▸Widely used in academia, research, and industry for data science, bioinformatics, finance, and social sciences.

Core Features

  • ▸Interpreted language with REPL interface
  • ▸Functional programming paradigm
  • ▸Rich data structures (vectors, matrices, lists, data frames)
  • ▸Advanced statistical and machine learning libraries
  • ▸Integration with C, C++, and Python for performance

Learning Path

  • ▸Learn R syntax and basic data structures
  • ▸Practice data manipulation with dplyr
  • ▸Explore visualization with ggplot2
  • ▸Study statistical modeling and machine learning
  • ▸Build reproducible reports and Shiny apps

Practical Examples

  • ▸Plotting a histogram with ggplot2
  • ▸Performing linear regression on a dataset
  • ▸Clustering with k-means
  • ▸Building a Shiny interactive dashboard
  • ▸Analyzing genomic or financial datasets

Comparisons

  • ▸Stronger in statistics than Python, though Python has broader general-purpose use
  • ▸R excels at data visualization and reporting
  • ▸CRAN offers thousands of specialized packages
  • ▸RStudio IDE provides excellent data science workflow
  • ▸Less performant for large-scale computational tasks than compiled languages

Strengths

  • ▸Excellent for statistical analysis and data visualization
  • ▸Vast ecosystem of specialized packages
  • ▸Strong community support for data science
  • ▸Open-source with extensive documentation
  • ▸Highly reproducible workflows using R Markdown

Limitations

  • ▸Slower than compiled languages for large datasets
  • ▸Memory-intensive with very large data
  • ▸Steeper learning curve for programming beginners
  • ▸Less suited for general-purpose software development
  • ▸Graphical performance can lag behind modern GUI frameworks

When NOT to Use

  • ▸High-performance computing without optimized packages
  • ▸General-purpose software development
  • ▸Mobile or embedded application development
  • ▸Projects requiring strict multithreading without external tools
  • ▸Applications outside data-centric use cases

Cheat Sheet

  • ▸x <- 10 - variable assignment
  • ▸c(1,2,3) - vector creation
  • ▸data.frame() - create data frame
  • ▸lm(y ~ x, data=df) - linear regression
  • ▸library(ggplot2) - load package

FAQ

  • ▸Is R free?
  • ▸Yes - open-source under GPL license.
  • ▸Can R run on Windows, macOS, and Linux?
  • ▸Yes, it is cross-platform.
  • ▸Is R suitable for machine learning?
  • ▸Yes, with packages like caret, mlr, and tidymodels.
  • ▸Can R integrate with Python?
  • ▸Yes, using the reticulate package.
  • ▸Is R good for big data?
  • ▸Yes, with proper packages (data.table, SparkR), but memory limitations exist.

30-Day Skill Plan

  • ▸Week 1: R basics and vectors
  • ▸Week 2: Data frames, lists, and matrices
  • ▸Week 3: Functions, control flow, and packages
  • ▸Week 4: Visualization and reporting
  • ▸Week 5: Statistical analysis and real datasets

Final Summary

  • ▸R is a specialized language for statistical computing and data analysis.
  • ▸It has strong visualization and reproducible reporting capabilities.
  • ▸CRAN and community packages make it extensible for diverse use cases.
  • ▸Ideal for researchers, statisticians, and data scientists.
  • ▸Open-source and widely supported in academia and industry.

Project Structure

  • ▸data/ - raw and processed datasets
  • ▸scripts/ - R scripts or notebooks
  • ▸plots/ - output visualizations
  • ▸docs/ - reports and R Markdown files
  • ▸libs/ - custom or third-party packages

Monetization

  • ▸Data science consulting
  • ▸Financial modeling and forecasting
  • ▸Bioinformatics pipelines
  • ▸Statistical reporting services
  • ▸R/Shiny-based analytics products

Productivity Tips

  • ▸Use RStudio keyboard shortcuts
  • ▸Leverage R Markdown for documentation
  • ▸Reuse functions and packages
  • ▸Automate repetitive analyses
  • ▸Regularly update packages and R version

Basic Concepts

  • ▸Variables and basic data types (numeric, character, logical)
  • ▸Vectors, matrices, lists, and data frames
  • ▸Functions and functional programming
  • ▸Control flow: loops, if-else, apply functions
  • ▸Statistical modeling and plotting basics

Official Docs

  • ▸R Project official website
  • ▸R manuals and reference guides
  • ▸CRAN package documentation

More R Typing Exercises

R Counter and Theme ToggleR Todo ListR Dice RollerR Countdown TimerR Prime CheckerR Temperature ConverterR Shopping CartR Name GreetingR Stopwatch

Practice Other Languages

CReactPythonC++RustTypeScriptKotlinPHPJavaC#RubyMqlCqlN1qlCypher