R Programming Examples Last Updated : 22 Apr, 2024 Summarize Comments Improve Suggest changes Share Like Article Like Report This R Programming Examples article will cover all R programming practice Questions and learn R Language. We can improve our R programming Skills using sets of questions from basic to advanced, containing a well-explained and detailed solution to each question. In this article, we will be discussing fundamental concepts like Variables, Data Types, Strings, loops, functions, matrices, Data frames, File handling, and much more. R Programming ExamplesR Programming FundamentalsBasics - R ProgrammingR CommentsLists - R ProgrammingData Types - R ProgrammingStrings - R ProgrammingFunctions - R ProgrammingLoops - R ProgrammingIf Else - R programmingVariable - R programmingVector - R ProgrammingMatrix - R ProgrammingDataFrame - R ProgrammingFactor - R ProgrammingDate and Time - R ProgrammingCSV - R ProgrammingExcel - R ProgrammingR Basic ExamplesWrite an R Program for "Hello Geeks".Write an R Program to Add Two VectorsFind the Sum, Mean, and Product of the Vector in R ProgrammingCreate an R Program to Take Input From the UserHow to Generate Random Numbers from Standard Distributions in RR Program to Sample from a PopulationCreate an R Program to Find the Minimum and MaximumR Program to Sort a VectorHow to Find the Factorial of a NumberHow to create R Multiplication TableWrite an R Program to Check Prime NumberR Program to check Armstrong NumberR Program to Print the Fibonacci SequenceR Program to Check for Leap YearCheck if a Number is Odd or Even in R ProgrammingR Program to Calculate Simple InterestR Program to Convert Celsius to Kelvin and FahrenheitR Program to Calculate the Area of a TriangleR Program to Check if a String is a PalindromeR Program to Find the Length of a StringR Program to Count the Number of Vowels in a StringR Program to Generate a Random PasswordR Program to Convert Decimal to Binary, Octal, and HexadecimalR CommentsIntroduction to R CommentsSingle-line CommentsMulti-line CommentsComments for Code DocumentationComments in R MarkdownList ExamplesCount the Number of List Elements in RHow to filter elements from a list based on certain conditionsCreate a list with random values in RHow to add Key Value Pair to List in R?Access Index Names of List Using apply Function in RConvert matrix to list in RConvert list to array in RData Types ExamplesR Data TypesData Type Conversion in RGetting different data types in R Programming – a type of the() Function.String ExamplesConvert Character String to Variable Name in RCount the Number of Characters in the String in RCount Number of Occurrences of Certain Character in String in RExtract Numbers from the Character String Vector in RCount the Number of Words in a String using RHow to calculate the number of occurrences of a character in each row of the R data frame?Write a Program to Concatenate Two Strings in R.R Program to Find the Length of a StringHow to Check if Characters are Present in a String in R.R Program to Extract First or Last n Characters from String in RHow to Replace Characters in a String in RCreate a Program to Compare Two Strings in R.R Program to Convert Factors to CharactersR Program to Trim Leading and Trailing WhitespacesFunctions ExamplesTypes of Functions in R ProgrammingCreate a Function to Calculate the Factorial of a NumberCreate a Function to Calculate the Mean of a Numeric VectorFind the Maximum Element in a Numeric VectorCreate a Function to Find the Sum of Squares of a Numeric VectorCreate a R Function to Reverse a Character StringCreate a R Function to Check if a String is a PalindromeCreate a Function to Calculate the Fibonacci SequenceCreate a Function to Find the Common Elements in Two VectorsFunction Arguments in R ProgrammingLooping ExamplesFor loop in Rfor loop to print the elements of a vector?Finding the maximum value in a vector using a for loop?Reversing a vector using a for loop?Counting the number of even and odd elements in a vector using a for loop?R – while loopwhile loop to print the elements of a vector?while loop to find the first occurrence of a specific element in a vector?while loop to calculate the factorial of a number?while loop to calculate the square of numbers?while loop to reverse a string?Looping over Objects in R Programmingrepeat loop to print the elements of a vector.Generating Random Numbers Until Some Condition Is Met in R?repeat loop to generate a sequence of numbers?How to Create a Nested For Loop in R?Nested for loop to print multiplication tables up to a certain number.Nested for loop to create a 2D matrix.Nested for loop to print a pattern.Nested for loop to calculate the transpose of a matrix.If … Else ExamplesR If Else ConditionsCheck if a number is positive or negative using if-else a statement.if-else to find the maximum of two numbers.Create a program to assign grades based on a student's score using if-else .Create a program to categorize numbers into odd or even.if-else to check if a number is divisible by another number.if-else to categorize ages into different groups.if-else to check if a character string contains a specific substring.Nested if-else statement in RGrade Classification Based on Multiple Conditions.Nested if-else for Temperature Classification.Quadrant Classification for Coordinates. Variable ExamplesR VariablesScope of The VariablesHow to Create Categorical Variables in R?Accessing variables of a data frame in R Programming – attach() and detach() functionSelect variables (columns) in R using DplyrDummy Variables in R ProgrammingVector ExamplesHow to create an empty vector in R?Create empty vector and append valuesFind the Sum, Mean, and Product of a Vector in RFind the product of vector elements in RCount the number of vector values in the range with RCount the specific value in a given vector in RAccess the last value of a given vector in RFind the elements of a vector that are not in another vector in RFind the Nth highest value of a vector in RHow to find Nth smallest value in vector in R?Extract every Nth element of a vector in RR Program to Concatenate a Vector of StringsHow to Check if a Vector Contains the Given ElementWrite an R Program to Count the Number of Elements in a VectorR Program to Find Index of an Element in a VectorWrite an R Program to Access Values in a VectorR Program to Add Leading Zeros to VectorMatrix ExamplesHow to create an empty matrix in R?Fill an empty matrix in RElementwise Matrix Multiplication in RMultiply Matrix by Vector in RFind the power of a matrix in RRaise a matrix to a fractional power in RGet the element at the specific position from the matrix in RFind the row and column index of maximum and minimum value in a matrix in RSelect rows of a matrix in R that meet a conditionMultiply a matrix by its transpose while ignoring missing values in RDataFrame ExamplesHow to Convert a List to a DataframeR Program to Create an Empty DataframeHow to Combine Two Dataframe into OneCreate an R Program to Change the Column Name of a DataframeHow to Extract Columns From a DataframeR Program to Drop Columns in a DataframeR Program to Reorder Columns in a DataframeHow to Split DataframeR Program to Merge Multiple DataframesR Program to Delete Rows From DataframeR Program to Make a List of DataframesHow to create a data frame from given vectors in R?Create an empty DataFrame with only column names in RInsert multiple rows in R DataFrameHow to add a column to the data frame in R?Extract the first N rows from the data frame in RHow to select the row with the maximum value in each group in R Language?Remove rows with NA in one column of the R DataFrameHow to remove empty rows from the R data frame?Find columns and rows with NA in R DataFrameSort DataFrame by column name in RHow To Merge Two DataFrames in R?Append one data frame to the end of another data frame in RHow to find common rows and columns between two data frames in R?Factor ExamplesHow to count values per level in a factor in RFind the levels of a factor of a given vector in RHow to change the order of levels of a factor in R?How to convert factor levels to list in R?Concatenate two given factors in a single factor in RGet All Factor Levels of the DataFrame Column in RDate and Time ExamplesHow to Add and Subtract Days to and from Date in R?How to subtract time in R?How to Extract time from the timestamp in R?How to calculate the number of days between two dates in R?How to calculate Years between Dates in R?How to convert a factor into a date format?File Handling ExamplesHow to check if a file already exists in R?R – Check if a Directory Exists and Create if It does notAdd New Line to Text File in RHow To Import Data from a File in R ProgrammingHow to export dataframe to RDATA file in R ?CSV ExamplesReading the CSV file into Dataframes in RExport CSV File without Row Names in RHow to write to CSV in R without an index?Append row to CSV using RHow to calculate the mean of a CSV file in R?Excel ExercisesHow to import an Excel File into R?How to export a DataFrame to Excel File in R?Convert an Excel column into a list of vectors in RHow to convert an Excel column to a vector in R?How to convert Excel content into DataFrame in R?Delete rows with empty cells from Excel using RData Visualization ExamplesAdding Colors to Charts in R ProgrammingHow to show legend in heatmap in R?Display All X-Axis Labels of Barplot in RHow to Create a Stacked Dot Plot in R?Change Spacing of Axis Tick Marks in Base R PlotAdd legends without borders and with white backgrounds in RPlot Shaded Area between vertical lines in RHow to add the Mean and Median to Histogram in R?Create a Scatter plot from CSV in RCustomizing Colors in Plots.Adding Legends to PlotsCreating Interactive Plots using ShinyAnnotating Text and Labels in PlotsFormatting Axis Labels and Ticks in PlotsWorking with Multiple Plots (Faceting)Plotting Time Series Data in RVisualizing Geographic Data with MapsCreating Animated Plots in RCreating 3D Plots in RWorking with Plotly for Interactive VisualizationsCreating Trellis (Lattice) Plots in RPlotting Large Datasets with ggplot2's geom_point() and geom_bin2d()Visualizing Hierarchical Data with DendrogramsCreating Sunburst Charts for Hierarchical DataWorking with Word Clouds in RNetwork Visualization in R using igraphCreating Heatmaps with Hierarchical ClusteringPlotting Multiple Data Series in a Single PlotInteractive Data Visualization with Plotly ExpressR StatisticsStatistics IntroductionMeasures of Central Tendency (Mean, Median, Mode)Measures of Dispersion (Variance, Standard Deviation, Range)Skewness and KurtosisProbability Distributions (Normal, Binomial, etc.)Hypothesis TestingConfidence Intervalsp-values and Significance LevelsCorrelation and Regression AnalysisSimple Linear Regression Multiple Linear RegressionAnalysis of Variance (ANOVA) Wilcoxon Rank-Sum Test Kruskal-Wallis TestConclusion In conclusion, R programming examples tutorial is covering basics like variable and data types of challenges that involves data manipulation, statistical analyses, and visualization. By understanding examples, you will be able to solve your R programming skills and also developed a problem - solving mindset crucial for real-world applications. Comment More infoAdvertise with us Next Article R Programming Examples V vipulsinghjhala Follow Improve Article Tags : R Language R Programs AI-ML-DS With R Similar Reads Purrr Package in R Programming Purrr package in R Programming , provides a set of functions that are designed to work with functional programming concepts, such as mapping, filtering and reducing. These functions are designed to work with lists, data frames and other objects, making it easier to work with complex data structures. 6 min read Magrittr Package in R Programming If you have been using R programming for a while, you may have come across the magrittr package. This package is designed to make the process of writing R code more efficient and readable. In this article, we will discuss what the Magrittr package is, why it is useful, and how to use it in your R co 6 min read Stringr Package in R Programming Character data plays a vital role in data analysis and manipulation using R programming. To facilitate these tasks, the Stringr package was developed by Hadley Wickham. This package offers a range of functions that help in working with character strings in R. The Stringr package simplifies the strin 10 min read Sample from a Population Using R Sampling from a population is a critical technique in statistics and data analysis. It allows you to draw conclusions about a large group (the population) by examining a smaller, representative subset (the sample). In R, you can easily perform random sampling to obtain a sample from a population, wh 9 min read Compare two character vectors in R In this article, we will discuss how to compare two character vectors in R Programming Language. Method 1: Using %in% This operator is used to find the elements present in one vector with respect to the second vector Syntax: vector1 %in% vector2 Return type: It returns boolean values corresponding t 2 min read Like