R Programming
R Programming
Debjit Konai
Department of Statistics
The University of Burdwan
Introduction To
What is 𝐑 ?
𝐑 is the statistical programming language is a free open source package based on the S
language developed by Bell Labs.
𝐑 plays a key role in a wide variety of research and data analysis projects because it
makes many modern statistical methods, both simple and advanced, readily available and
easy to use. It’s true, however, that a beginner to R is often new to programming in
general. As a beginner, you must not only learn to use R for your specific data analysis
goals but also learn to think like a programmer.
𝐑 is a language and environment for statistical computing and graphics.
𝐑 provides a wide variety of statistical (linear and nonlinear modelling, classical statistical
tests, time-series analysis, classification, clustering, ...) and graphical techniques, and is
highly extensible. The S language is often the vehicle of choice for research in statistical
methodology, and R provides an Open Source route to participation in that activity.
𝐑 can be used any one for any purpose.
𝐑 initially written by 𝐑𝐨𝐬𝐬 𝐈𝐡𝐚𝐤𝐚 and 𝐑𝐨𝐛𝐞𝐫𝐭 𝐆𝐞𝐧𝐭𝐥𝐞𝐦𝐚𝐧 at Dep. of Statistics of
University of Auckland, New Zealand during 1990s.
Contributors of R
The current R is the result of a collaborative effort with
contributions from all over the world. R was initially
written by Robert Gentleman and Ross 𝑰𝒉𝒂𝒌𝒂—also
known as "R & R" of the Statistics Department of the
University of 𝑨𝒖𝒄𝒌𝒍𝒂𝒏𝒅. 𝒓
𝑹𝒐𝒃𝒆𝒓𝒕 𝑮𝒆𝒏𝒕𝒍𝒆𝒎𝒂𝒏
The benefits of 𝑹
𝐑 is free and open source and runs on UNIX, Windows, Macintosh.
𝐑′𝐬 language has a powerful, easy to learn syntax with many built-in
statistical functions.
1. If (Condition){
Expression
}
2. If (Condition) {
Expression 1
} else {
Expression 2
}
3. If (Condition) { Repetitive execution : (use for loop, repeat loop,
while, do while loop)
Expression 1
} 𝐞𝐥𝐢𝐟 { 1. for ( 𝐢 in vector)
Expression 2 {
} 𝐞𝐥𝐢𝐟 { Expression
Expression 3 }
… 2. Repeat {
} else{ commands
Expression n if (Condition) {
} break
}
}
3. While (Condition) {
Expression
}
Some applications:
1. >a=1
> if(a==1) {print(“Hello Students”)}
[1] “Hello Students”
2. >x = -2
>if(x > 0){
print(“The given number is Non-negative ")
} else {
print(“The given number is Negative ")
}
[1] “ The given number is Negative”
3. >k = 100
> if(k>100){
print(“Greater than 100”)
} else if (k<100){
print(“Less than 100”)
} else {
print(“Equal to 100”)
}
[1] “ Equal to 100”
4. > 𝐟𝐫𝐮𝐢𝐭 = 𝐜(′𝐀𝐩𝐩𝐥𝐞′, ′𝐎𝐫𝐚𝐧𝐠𝐞′, ′𝐏𝐚𝐬𝐬𝐢𝐨𝐧 𝐟𝐫𝐮𝐢𝐭′, ′𝐁𝐚𝐧𝐚𝐧𝐚′)
> 𝐟𝐨𝐫( 𝐢 𝐢𝐧 𝐟𝐫𝐮𝐢𝐭){
𝐩𝐫𝐢𝐧𝐭(𝐢)
}
Output:
[1] Apple
[1] Orange
[1] Passion
[1] Banana
The value of typos is prefaced with a funny looking [𝟏]. This indicates that
the value is a vector. More on that later.
Entering data with c function
The most useful 𝐑 command for quickly entering in small data sets is the
𝐜 function. This function combines, or concatenates terms together. As an
example, suppose we have the following count of the number of typos per page
of these notes:
43131051
To enter this into an R session we do so with
> 𝐭𝐲𝐩𝐨𝐬 = 𝐜(𝟒, 𝟑, 𝟏, 𝟑, 𝟏, 𝟎, 𝟓, 𝟏)
> 𝐭𝐲𝐩𝐨𝐬
[𝟏] 𝟒 𝟑 𝟏 𝟑 𝟏 𝟎 𝟓 𝟏
Weight(kg) 63 81 56 91 47 57 76 62 48
Find the linear relationship between Height and Weight using R and using this relation find Height
when Weight is 102 Kg. Also find the summary of the Relationship.
Solution:
Let 𝐲 = 𝐚 + 𝐛𝐱 be the linear relationship between height and weight.
where, a and b are constants, x is explanatory(weight) and y be the response(height)
variable. In this problem, a and b is to determine using R through the sample values.
R-Code:
𝐇𝐞𝐢𝐠𝐡𝐭 < −𝐜(𝟏𝟓𝟏, 𝟏𝟕𝟒, 𝟏𝟑𝟖, 𝟏𝟖𝟔, 𝟏𝟐𝟖, 𝟏𝟑𝟔, 𝟏𝟕𝟗, 𝟏𝟓𝟐, 𝟏𝟑𝟏)
𝐖𝐞𝐢𝐠𝐡𝐭 < −𝐜(𝟔𝟑, 𝟖𝟏, 𝟓𝟔, 𝟗𝟏, 𝟒𝟕, 𝟓𝟕, 𝟕𝟔, 𝟔𝟐, 𝟒𝟖)
𝐑𝐞𝐥𝐚𝐭𝐢𝐨𝐧 < −𝐥𝐦(𝐇𝐞𝐢𝐠𝐡𝐭~𝐖𝐞𝐢𝐠𝐡𝐭)
𝐩𝐫𝐢𝐧𝐭(𝐬𝐮𝐦𝐦𝐚𝐫𝐲 𝐑𝐞𝐥𝐚𝐭𝐢𝐨𝐧 )
Output(Summary of the Linear Regression Model):
Visualize this Relationship graphically:
R-Code………..
𝐇𝐞𝐢𝐠𝐡𝐭 < −𝐜(𝟏𝟓𝟏, 𝟏𝟕𝟒, 𝟏𝟑𝟖, 𝟏𝟖𝟔, 𝟏𝟐𝟖, 𝟏𝟑𝟔, 𝟏𝟕𝟗, 𝟏𝟓𝟐, 𝟏𝟑𝟏)
𝐖𝐞𝐢𝐠𝐡𝐭 < −𝐜(𝟔𝟑, 𝟖𝟏, 𝟓𝟔, 𝟗𝟏, 𝟒𝟕, 𝟓𝟕, 𝟕𝟔, 𝟔𝟐, 𝟒𝟖)
𝐑𝐞𝐥𝐚𝐭𝐢𝐨𝐧 < −𝐥𝐦(𝐇𝐞𝐢𝐠𝐡𝐭~𝐖𝐞𝐢𝐠𝐡𝐭)
𝐩𝐥𝐨𝐭(𝐇𝐞𝐢𝐠𝐡𝐭, 𝐖𝐞𝐢𝐠𝐡𝐭, 𝐜𝐨𝐥 = "𝐛𝐥𝐮𝐞", 𝐦𝐚𝐢𝐧 =
"𝐑𝐞𝐥𝐚𝐭𝐢𝐨𝐧𝐬𝐡𝐢𝐩 𝐛𝐞𝐭𝐰𝐞𝐞𝐧 𝐇𝐞𝐢𝐠𝐡𝐭 & 𝐖𝐞𝐢𝐠𝐡𝐭", 𝐚𝐛𝐥𝐢𝐧𝐞 𝐖𝐞𝐢𝐠𝐡𝐭~𝐇𝐞𝐢𝐠𝐡𝐭 , 𝐜𝐞𝐱 = 𝟏. 𝟑, 𝐩𝐜𝐡 = 𝟏𝟔, 𝐱𝐥𝐚𝐛 =
"𝐖𝐞𝐢𝐠𝐡𝐭 𝐢𝐧 𝐊𝐠", 𝐲𝐥𝐚𝐛 = "𝐇𝐞𝐢𝐠𝐡𝐭 𝐢𝐧 𝐜𝐦")
Output:
Packages in R
R packages are collections of functions and data sets developed by the community.
They increase the power of R by improving existing base R functionalities, or by
adding new ones. For example, if you are usually working with data frames,
probably you will have heard about 𝐝𝐩𝐥𝐲𝐫 or 𝐝𝐚𝐭𝐚. 𝐭𝐚𝐛𝐥𝐞 two of the most popular R
packages.
But imagine that you'd like to do some natural language processing of Korean
texts, extract weather data from the web, or even estimate actual evapotranspiration
using land surface energy balance models, R packages got you covered! Recently,
the official repository (CRAN) reached 10,000 packages published, and many more
are publicly available through the internet.
If you are starting with R, today’s post will cover the basics of R packages and how
to use them. You’ll cover the following topics, and 11 frequently asked user
questions…..
1. The basics of R packages: what are packages and why should you incorporate
their use into your R experience?
2. Where can you find packages?
3. The installation and usage: how can you install packages from CRAN, CRAN
mirrors, 𝐁𝐢𝐨𝐜𝐨𝐧𝐝𝐮𝐜𝐭𝐨𝐫 or 𝐆𝐢𝐭𝐡𝐮𝐛?
4. What are some functions that are related to 𝐢𝐧𝐬𝐭𝐚𝐥𝐥. 𝐩𝐚𝐜𝐤𝐠𝐞𝐬() and that you can
use to update, remove, … packages?
5. How can you use the user interface to install packages?
6. How do you load packages?
7. What is the difference between a package and a library in R?
8. How do I load multiple packages at the same time?
9. How do I unload an R package?
10. The documentation: what are, besides the DESCRIPTION file, other sources of
documentation and how can use them?
11. Choosing between R packages: how do you find the right package for your
analysis?
What is a Package?
Let’s start with some definitions. A package is a suitable way to organize your own
work and, if you want to, share it with others. Typically, a package will include
code (not only R code!), documentation for the package and the functions inside,
some tests to check everything works as it should, and data sets.
The basic information about a package is provided in the DESCRIPTION file,
where you can find out what the package does, who the author is, what version the
documentation belongs to, the date, the type of license its use, and the package
dependencies.
Besides finding the DESCRIPTION files such as cran.r-project.org or stat.ethz.ch,
you can also access the description file inside R with the command
𝐩𝐚𝐜𝐤𝐚𝐠𝐞𝐃𝐞𝐬𝐜𝐫𝐢𝐩𝐭𝐢𝐨𝐧("package") via the documentation of the package
𝐡𝐞𝐥𝐩(𝐩𝐚𝐜𝐤𝐚𝐠𝐞 = "𝐩𝐚𝐜𝐤𝐚𝐠𝐞") or online in the repository of the package.
For example, for the “stats” package, these ways will be:
R-Code:
packageDescription("stats")
package(package = "stats")
Output:
What are Repositories?
A repository is a place where packages are located so you can install
them from it. Although you or your organization might have a local
repository, typically they are online and accessible to everyone. Three
of the most popular repositories for R packages are:
CRAN: the official repository, it is a network of ftp and web servers
maintained by the R community around the world. The R foundation
coordinates it, and for a package to be published here, it needs to pass
several tests that ensure the package is following CRAN policies.
Bioconductor: this is a topic specific repository, intended for open
source software for bioinformatics. As CRAN, it has its
own submission and review processes, and its community is very
active having several conferences and meetings per year.
Github: although this is not R specific, Github is probably the most popular
repository for open source projects. Its popularity comes from the unlimited space
for open source, the integration with 𝐠𝐢𝐭, a version control software, and its ease to
share and collaborate with others. But be aware that there is no review process
associated with it.
How to install an R packages ?
Installing Packages From CRAN
How you can install a package will depend on where it is located. So, for publicly
available packages, this means to what repository it belongs. The most common
way is to use the CRAN repository, then you just need the name of the package and
use the command
R-code:
install.packages("package")
Example: Installing “VIF(Variance Inflation Factor)” package from CRAN.
R-Code:
install.packages("VIF")
Output:
Packages installing from CRAN Mirrors:
Remember that CRAN is a network of servers (each of them called a “mirror”), so
you can specify which one you would like to use. If you are using R through the
𝐑𝐆𝐮𝐢 interface, you can do it by selecting it from the list which appears just after
you use the install.packages() command. On 𝐑𝐒𝐭𝐮𝐝𝐢𝐨, the mirror is already
selected by default.
You can also select your mirror by using the chooseCRANmirror() , or directly
inside the install.packages() function by using the repo parameter. You can see
the list of available mirrors with getCRANmirror().
Package installing via 𝐝𝐞𝐯𝐭𝐨𝐨𝐥𝐬:
A more efficient way is probably to use the devtools package to simplify this
process, because it contains specific functions for each repository, including
CRAN.
You can install 𝐝𝐞𝐯𝐭𝐨𝐨𝐥𝐬 package (install.packages("devtools")) but you might also
need to install Rtools on Windows, 𝐗𝐜𝐨𝐝𝐞 command line tools on Mac, or 𝒓 −
𝒃𝒂𝒔𝒆 − 𝒅𝒆𝒗 and 𝐫 − 𝐝𝐞𝐯𝐞𝐥 on Linux.
After 𝐝𝐞𝐯𝐭𝐨𝐨𝐥𝐬 is installed, you will be able to use the utility functions to install
another packages. The options are:
1. install_bioc() from Bioconductor.
2. install_bi𝐭𝐛𝐮𝐜𝐤𝐞𝐭() from Bitbucket.
3. install_𝐜𝐫𝐚𝐧() from CRAN.
4. install_𝐠𝐢𝐭() from a git repository
5. install_github() from GitHub.
6. install_𝐥𝐨𝐜𝐚𝐥() from a local file.
7. install_𝐬𝐯𝐧() from a SVN repository.
8. install_𝐮𝐫𝐥() from a URL.
9. install_𝐯𝐞𝐫𝐬𝐢𝐨𝐧() from a specific version of a CRAN package.
How to update, remove, and check installed packages:
R-Code for checking installed packages……
installed.packages()
R-Code for uninstalled packages……
remove.packages()
Package Lists
Some important R-Packages
The list of major packages in R programming language is as follows…….
1. 𝐠𝐠𝐩𝐥𝐨𝐭𝟐:
With ggplot2, you can create graphics declaratively. ggplot2 is famous for its
elegant and quality graphs that sets it apart from other visualization packages.
The ggplot2 package, created by Hadley Wickham, offers a powerful graphics
language for creating elegant and complex plots. Originally, based on Leland
Wilkinson's The Grammar of Graphics, ggplot2 allows you to create graphs that
represent both 𝐮𝐧𝐢𝐯𝐚𝐫𝐢𝐚𝐭𝐞 and multivariate numerical and categorical data in a
straightforward manner. Grouping can be represented by color, symbol, size, and
transparency.
𝟐. 𝐠𝐠𝐫𝐚𝐩𝐡:
𝐠𝐠𝐫𝐚𝐩𝐡 is an extension of ggplot2. It takes away the limitation of ggplot2, that is,
its dependency on tabular data.
𝟑. 𝐝𝐩𝐥𝐲𝐫:
We use this library for performing data wrangling and data analysis. The 𝐝𝐩𝐥𝐲𝐫
library facilitates several functions for the data frames in R.
4. 𝐠𝐠𝐦𝐚𝐩:
This is a mapping package that is used for delineating spatial visualizations. It also
consists of various tools for 𝒈𝒆𝒐𝒍𝒐𝒄𝒂𝒕𝒊𝒏𝒈 and routing.
5. MASS:
MASS provides a large number of statistical functions. It provides datasets that are
in conjunction with the book “Modern Applied Statistics with S”.
6. VIF:
This function is a simple port of VIF from car package. The VIF of a predictor is a
measure for how easily it is predicted from a linear regression using the other
predictors. Taking the square root of the VIF tells you how much larger the
standard error of the estimated coefficient is respect to the case when that predictor
is independent of the other predictors.
A general guideline is that a VIF larger than 5 or 10 is large, indicating that the
model has problems estimating the coefficient. However, this in general does not
degrade the quality of predictions. If the VIF is larger than 1/(1-𝑹𝟐 ), where 𝑹𝟐 is
the Multiple R-squared of the regression, then that predictor is more related to the
other predictors than it is to the response.
7. utf8:
utf8 is an R package for manipulating and printing UTF-8 text that fixes multiple
bugs in R's UTF-8 handling.
8. 𝐧𝐥𝐦𝐞(Non linear Mixed Effects):
In R, 𝐧𝐥𝐦𝐞 is a library or package containing many useful functions and datasets
Some problems discuss using R
Q1. Find the random number generation from standard normal distribution and uniform distribution.
Answer:
R-Code:
𝐧𝟏 < −𝐫𝐧𝐨𝐫𝐦(𝟏𝟐, 𝐦𝐞𝐚𝐧 = 𝟎, 𝐬𝐝 = 𝟏)
print(n1)
𝐧𝟐 < −𝐫𝐮𝐧𝐢𝐟(𝟐𝟎, −𝟏, 𝟏)
print(n2)
Output:
Q2. The given data sets are 12, 23, 21, 34, 11, 45, 32, 43, 67, 22, 55, 44, 33, 54. Find the
mean, median, minimum and maximum value of the given data sets.
Answer:
The given data sets are 12, 23, 21, 34, 11, 45, 32, 43, 67, 22, 55, 44, 33, 54.
R-Code:
𝐝𝐚𝐭𝐚 < −𝐜 𝟏𝟐, 𝟐𝟑, 𝟐𝟏, 𝟑𝟒, 𝟏𝟏, 𝟒𝟓, 𝟑𝟐, 𝟒𝟑, 𝟔𝟕, 𝟐𝟐, 𝟓𝟓, 𝟒𝟒, 𝟑𝟑, 𝟓𝟒
𝐩𝐫𝐢𝐧𝐭(𝐝𝐚𝐭𝐚)
𝐌𝐞𝐚𝐧 < −𝐦𝐞𝐚𝐧 𝐝𝐚𝐭𝐚 Output:
𝐩𝐫𝐢𝐧𝐭(𝐌𝐞𝐚𝐧)
𝐌𝐞𝐝𝐢𝐚𝐧 < −𝐦𝐞𝐝𝐢𝐚𝐧 𝐝𝐚𝐭𝐚
𝐩𝐫𝐢𝐧𝐭(𝐌𝐞𝐝𝐢𝐚𝐧)
𝐌𝐢𝐧𝐢𝐦𝐮𝐦 < −𝐦𝐢𝐧 𝐝𝐚𝐭𝐚
𝐩𝐫𝐢𝐧𝐭(𝐌𝐢𝐧𝐢𝐦𝐮𝐦)
𝐌𝐚𝐱𝐢𝐦𝐮𝐦 < −𝐦𝐚𝐱 𝐝𝐚𝐭𝐚
𝐩𝐫𝐢𝐧𝐭(𝐌𝐚𝐱𝐢𝐦𝐮𝐦)
𝟐 𝟒 𝟏 −𝟐 𝟓 𝟎
Q3. If A = 𝟑 𝟓 𝟕 and B= 𝟑 𝟔 𝟑 , then A+B, A-B and AB using R.
𝟒 𝟎 𝟑 −𝟒 𝟑 −𝟒
Answer:
𝟐 𝟒 𝟏 −𝟐 𝟓 𝟎
The given two matrices are A = 𝟑 𝟓 𝟕 and B= 𝟑 𝟔 𝟑
𝟒 𝟎 𝟑 −𝟒 𝟑 −𝟒
R-Code:
𝐝𝐚𝐭𝐚𝟏 < −𝐜(𝟐, 𝟒, 𝟏, 𝟑, 𝟓, 𝟕, 𝟒, 𝟎, 𝟑)
𝐀 < −𝐦𝐚𝐭𝐫𝐢𝐱 𝐝𝐚𝐭𝐚, 𝐧𝐫𝐨𝐰 = 𝟑, 𝐧𝐜𝐨𝐥 = 𝟑, 𝐛𝐲𝐫𝐨𝐰 = 𝐓𝐑𝐔𝐄
print(A)
𝐝𝐚𝐭𝐚𝟐 < −𝐜(−𝟐, 𝟓, 𝟎, 𝟑, 𝟔, 𝟑, −𝟒, 𝟑, −𝟒)
𝐁 < −𝐦𝐚𝐭𝐫𝐢𝐱 𝐝𝐚𝐭𝐚, 𝐧𝐫𝐨𝐰 = 𝟑, 𝐧𝐜𝐨𝐥 = 𝟑, 𝐛𝐲𝐫𝐨𝐰 = 𝐓𝐑𝐔𝐄
print(B)
𝐀𝐝𝐝 < − 𝐀 + 𝐁
print(Add)
𝐒𝐮𝐛𝐬 < − 𝐀 − 𝐁
print(Subs)
𝐌𝐮𝐥𝐭𝐢𝐩 < − 𝐀 ∗ 𝐁
Print(𝐌𝐮𝐥𝐭𝐢𝐩)
Output:
Q4. Suppose we have the following data set 88, 95, 92, 97, 96, 97, 94, 86, 91, 95, 97, 88,
85, 76, 68. Draw the histogram and also find 𝐬𝐤𝐞𝐰𝐧𝐞𝐬𝐬 and kurtosis using R.
Answer:
The given data sets are 88, 95, 92, 97, 96, 97, 94, 86, 91, 95, 97, 88, 85, 76, 68.
R-Code:
𝐝𝐚𝐭𝐚 < −𝐜(𝟖𝟖, 𝟗𝟓, 𝟗𝟐, 𝟗𝟕, 𝟗𝟔, 𝟗𝟕, 𝟗𝟒, 𝟖𝟔, 𝟗𝟏, 𝟗𝟓, 𝟗𝟕, 𝟖𝟖, 𝟖𝟓, 𝟕𝟔, 𝟔𝟖)
print(data)
𝐡𝐢𝐬𝐭(𝐝𝐚𝐭𝐚)
𝐥𝐢𝐛𝐫𝐚𝐫𝐲 𝐦𝐨𝐦𝐞𝐧𝐭𝐬
𝐤𝐮𝐫𝐭𝐨𝐬𝐢𝐬 𝐝𝐚𝐭𝐚
𝐬𝐤𝐞𝐰𝐧𝐞𝐬𝐬(𝐝𝐚𝐭𝐚)
Output:
Q5.Find the quartiles, interquartile of the given data sets 120, 123, 56, 67, 100, 111,
120, 89, 90, 99, 130, 110. (Using R)
Answer: The given data sets are 120, 123, 56, 67, 100, 111, 120, 89, 90, 99, 130, 110.
R-code:
𝐝𝐚𝐭𝐚 < −𝐜(120, 123, 56, 67, 100, 111, 120, 89, 90, 99, 130, 110)
print(data)
summary(data)
IQR(data)
Output:
Q6. Every month one measure the amount of weight one's dog has picked up and
get these outcomes:
0.5 0.5 0.3 -0.2 1.6 0 0.1 0.6 0.4
There are no values from 1 to just below 1.5, but we still show the space.
R-Quiz
Q7. Which of the following is a base package for R language?
a. 𝐮𝐭𝐢𝐥 b. 𝐥𝐚𝐧𝐠 c. tools d. All of the above
Q8. R comes with a ________ to help you optimize your code and improve its
performance.
a. Debugger b. Monitor c. Profiler d. None of the above.
Q10. ______ suspends the execution of a function wherever it is called and puts the
function in debug mode.
a. recover() b. browser() c. Both of the above.
Q21. R objects can have attributes, which are like ________ for the object.
a. metadata b. features c. expressions
Q22. Attributes of an object (if any) can be accessed using the ______ function.
a. objects() b. 𝐚𝐭𝐭𝐫𝐢𝐛() c. attributes()
Q23. _________ involves predicting a response with meaningful magnitude, such as
quantity sold, stock price, or return on investment.
a. Regression b. Clustering c. Summarization
Q25. ______ splits a data frame and results in an array (hence the da). Hopefully,
you’re getting the idea here.
a. apply b. 𝐝𝐚𝐩𝐥𝐲 c. stats
Q26. 𝐒𝐲𝐬𝐭𝐞𝐦. 𝐭𝐢𝐦𝐞 function returns an object of class _______ which contains two
useful bits of information.
a. 𝐝𝐞𝐛𝐮𝐠_𝐭𝐢𝐦𝐞 b. 𝐩𝐫𝐨𝐜𝐞𝐝𝐮𝐫𝐞_𝐭𝐢𝐦𝐞 c. 𝐩𝐫𝐨𝐜_𝐭𝐢𝐦𝐞
Q62. In 1991, R was created by Ross 𝐈𝐡𝐚𝐤𝐚 and Robert Gentleman in the Department
of Statistics at the University of _________.
a. Auckland b. Harvard c. California d. John Hopkins
Q73. Explain how you can create a table in R without external file?
𝐀𝐧𝐬: Use the code
𝐦𝐲𝐓𝐚𝐛𝐥𝐞 = 𝐝𝐚𝐭𝐚. 𝐟𝐫𝐚𝐦𝐞()
edit(𝐦𝐲𝐓𝐚𝐛𝐥𝐞)
This code will open an excel like spreadsheet where you can easily enter your data.