AMZ DIGICOM

Digital Communication

AMZ DIGICOM

Digital Communication

R commands: overview of the main commands

PARTAGEZ

R commands are the foundation of data analysis and statistical modeling in the R environment. They provide the tools and flexibility to understand data, detect patterns, and make informed decisions.

R commands: what are they?

R commands (or R commands in English) are instructions used in R programming to execute specific tasks or initiate tasks in the R environment. These commands allow you toanalyze data, perform statistical calculations or create visualizations. R commands can be entered and processed in the R command line or in R scripts. It is important to distinguish commands from R functions.

R functions are code blocks defined and designated under R, which perform specific tasks. They can include the use of R operators and R data to accept arguments or display return values. This means that functions can save, process, and return data that is associated with different R data types.

With web hosting from IONOS, you benefit from at least 50 GB of free memory and powerful servers with high availability, which ensure that your website is always online and loads quickly. Additionally, you get a free domain and a Wildcard SSL certificate to ensure your website is secure.

R commands: list of different commands

The following list of R commands gives you an overview of the different application areas in R programming. Depending on your specific projects and requirements, you can select and combine the appropriate R commands.

Data handling and processing

  • read.csv() : reading data from a CSV file
  • data.frame() : creation of a data frame
  • subset() : filtering data based on specific conditions
  • merge() : merging data from different data frames
  • aggregate() : data aggregation based on specific criteria
  • transform() : creation of new variables in a data frame
  • sort() : sorting vectors or data frames
  • unique() : identifying unique values ​​in a vector or column

Data visualization

  • plot() : creating scatterplots and other basic types of diagrams
  • hist() : creation of histograms
  • barplot() : creating bar charts
  • boxplot() : creating boxplots
  • ggplot2::ggplot() : for more demanding and customizable visualizations with the ggplot2 package

Statistical analyzes

  • summary() : preparation of a collection of data, including key statistical figures
  • lm() : running linear regressions
  • t.test() : running T tests to test hypotheses
  • cor() : calculation of correlation coefficients between variables
  • anova() : performing analyzes of variance (ANOVA)
  • chi-sq.test() : for chi-square tests

Data processing

  • ifelse() : for condition evaluations and conditional expressions
  • apply() : application of a function to matrices or data frames
  • dplyr::filter() : filtering data in a data frame with the dplyr package
  • dplyr::mutate() : creation of new variables in data frames with the dplyr package
  • lapply(), sapply(), mapply() : for applying functions to lists or vectors

Importing and exporting data

  • readRDS(), saveRDS() : reading and saving R data objects
  • write.csv(), read.table() : export and import of data in different formats

Statistical charts and graphs

  • qqnorm(), qqline() : for creating quantile-quantile diagrams
  • plot(), acf() : representation of autocorrelation diagrams
  • density() : representation of density functions and histograms
  • heatmap() : creation of density maps

R commands: usage examples

The following code examples demonstrate the use of major R commands in various application domains. According to your data and analytics requirementsyou can adapt and expand these commands.

Reading data from a CSV file

data <- read.csv("donnees.csv")

R

Read.csv() is a command allowing you to read the data present in a CSV file, in R. In our example, the data read is saved in the variable data. This command is useful for importing external data into R and for making analyzes available.

Creating a Scatter Plot

plot(data$X, data$Y, main="DiagrammeDispersion")

R

Plot() is an R command for creating charts and graphs in R. In our example, a scatter plot is created to represent the relationship between variables X And Y of the data frame data. The argument main sets the title of the diagram.

Running a Linear Regression

regression_model <- lm(Y ~ X, data=data)

R

In this example, we run a linear regression in order to model the relationship between variables X And Y in the data frame data. The command lm() is used to calculate a linear regression in R. The result of the regression is saved in the variable regression_model and can be used for other analyses.

Filtering data with the dplyr package

filtered_data <- dplyr::filter(data, column > 10)

R

The command dplyr::filter() comes from dplyr package and will be used for data manipulation. The dplyr package provides powerful functions for data filtering. We obtain the variable filtered_data by selecting the lines of the data frame data for which the value of the column column is greater than 10.

Creating quantile-quantile plots

qqnorm(data$Variable)
qqline(data$Variable)

R

You can use qqnorm() to represent a quantile-quantile diagram in R. In this example, a quantile-quantile diagram is represented for the variable Variable of data. qqline() adds a reference line to compare the distribution with a normal distribution.

We recommend that all beginners check out the R programming overview tutorial. There you will find plenty of tips and the basic knowledge needed to progress with the R programming language. More tips and basics are available in our article “Learn programming: basic principles” from the Digital Guide.

Télécharger notre livre blanc

Comment construire une stratégie de marketing digital ?

Le guide indispensable pour promouvoir votre marque en ligne

En savoir plus

Souhaitez vous Booster votre Business?

écrivez-nous et restez en contact