A simple introduction to R and R studio
Dr. Fadhah ( ?.??? ??????) Alanazi
Assistant Professor @ Prince Sultan University | Statistical Modeling and Operational Research
R is a powerful programming language and software environment commonly used for statistical computing and graphics. It provides a wide variety of statistical and graphical techniques, making it a preferred choice for data analysis, visualization, and machine learning tasks.
RStudio is an integrated development environment (IDE) for R that provides a user-friendly interface for writing, running, and debugging R code. It offers features like syntax highlighting, code completion, built-in tools for plotting, debugging, and package management, making it easier for users to work with R.
Key features and advantages of R and RStudio include:
Coding with Rstudio
Coding with RStudio is straightforward due to the simplicity of the R language compared to others. For instance, you can easily generate a numeric vector, perform various mathematical computations, or even define your own functions.
领英推荐
# Create a vector of numbers from 1 to 100
x <- 1:100
# you can call it by tabing x
x
# you can get the first values using head() function
head(x)
# also you can get the last values using tail() function
tail(x)
# you can generate another vector and called it y
y <- sqrt(x)
# plot
plot(x,y)
# You can simply add a title or adjust the x-axis and y-axis.
plot(x,y, main="Simple plot", xlab="X", ylab="Square root of X")
To write your own function in R, you can begin by using function(). This function can accept as many arguments as necessary. Inside the curly braces, you define your mathematical function. Finally, you use return() to provide the desired result.
MyFirstFunction <- function(x,y){
result <- (2*x) + y
return(result)
}
try <- MyFirstFunction(x,y)
> head(try)
[1] 3.000000 5.414214 7.732051 10.000000 12.236068 14.449490
Consistent practice in R is essential, gradually increasing the complexity of your code each time to progress as an R programmer.
I trust this brief and straightforward introduction to R has been beneficial.
President of DISTED College | Professor of Sustainable Tourism | Experienced Consultant | Passionate about Rural Tourism ???
1 个月Looking for lecturers that can teach R programming in Penang, Malaysia. Please contact [email protected]