R编程和R Studio简介

Having just graduated from college and entered the workforce, I don’t find myself always using the tools and programs I grew accustomed to over the past four years. However, there is one program I continually find myself reverting back to…R.

我刚大学毕业并加入了工作队伍,但我发现自己并不总是使用过去四年来逐渐习惯的工具和程序。 但是,有一个程序我不断发现自己回到了……R。

So what is R? R is a programming language and environment with an ever-growing bucket of tools for statistical processing and graphic creation. According to the R-project website, R includes

那么R是什么? R是一种编程语言和环境,具有用于统计处理和图形创建的越来越多的工具。 根据R-project网站 ,R包括

  • an effective data handling and storage facility,

    有效的数据处理和存储设施,
  • a suite of operators for calculations on arrays, in particular matrices,

    一组用于对数组(尤其是矩阵)进行计算的运算符,
  • a large, coherent, integrated collection of intermediate tools for data analysis,

    大量,连贯,集成的中间工具集合,用于数据分析,
  • graphical facilities for data analysis and display either on-screen or on hardcopy, and

    用于数据分析和在屏幕上或在硬拷贝上显示的图形功能,以及
  • a well-developed, simple and effective programming language which includes conditionals, loops, user-defined recursive functions and input and output facilities.

    一种发达的,简单而有效的编程语言,包括条件,循环,用户定义的递归函数以及输入和输出功能。

Sure, graduating with a minor in Statistics and my love for data manipulation may make me partially biased with using R but I feel like its uses are incredibly wide-reaching. The great thing about R is it allows the user to perform simple arithmetic calculations with matrices or dive in deeper and create complex graphs or even create dynamic reports to incorporate LaTeX.

当然,与统计专业的未成年人一起毕业,以及我对数据处理的热爱可能会使我对使用R感到有些偏颇,但是我觉得R的使用范围之广令人难以置信。 R的优点在于,它允许用户使用矩阵执行简单的算术计算,或者深入研究并创建复杂的图形,甚至创建动态报告以合并LaTeX。

Another incredible feature is you have an overwhelming amount of “packages” at your disposal to increase the functionality of your code. R Studio (a program I will explain in a few paragraphs) allows you to download and install these automatically with the options to toggle them on and off.

另一个不可思议的功能是您拥有大量的“程序包”以增加代码的功能。 R Studio(我将在几段中介绍的程序)使您可以自动下载并安装这些程序,并具有打开和关闭它们的选项。

My plan is to write a series of articles here that will cover a multitude of important functions and topics using R. I think it is an incredibly underutilized tool that can be very adaptable to a wide array of people and topic areas. The articles will start off with the basics (downloading and utilizing R), and progressively get into more advanced concepts, and eventually covering some functionality with R Sweave and LaTeX incorporation with R that I found incredibly useful in college.

我的计划是在此处写一系列文章,这些文章将涵盖使用R的许多重要功能和主题。我认为它是一种使用率极低的工具,可以非常适合于各种各样的人员和主题领域。 本文将从基础知识开始(下载和使用R),并逐步进入更高级的概念,并最终介绍R Sweave和将LaTeX与R结合使用的某些功能,这些功能我在大学中发现非常有用。


So, to start you will need to download R, which can be done
因此,要开始,您将需要下载R,可以在 here.  Do this first before proceeding. Next, you have the option of installing R Studio, a UI tool that helps make functionality with R a lot more user friendly. R Studio can be downloaded 此处完成。 在继续之前,请先执行此操作。 接下来,您可以选择安装R Studio,这是一个UI工具,可以帮助使R的功能更加用户友好。 R Studio可以在 here.  My articles will include R code but will be executed using R Studio. 这里下载。 我的文章将包含R代码,但将使用R Studio执行。

What you will see at first is an environment with three columns (see image below). The left column is your console window. This is where all of the code you want to execute should go and where the output will be displayed. The possibilities of what you will see in this window are endless so we will address more things as we move on. The right top window is the location where you will see all the variables and items stored in the workspace you will see. Below that you will notice a window with a few different tabs (Files, Plots, Packages, etc.). This is where you can see items in your working directory, view plots, download and choose packages, and quite a few more options.

首先,您将看到一个包含三列的环境(请参见下图)。 左列是您的控制台窗口。 这是您要执行的所有代码应放在的地方,并且将显示输出。 您在此窗口中看到的内容的可能性是无穷的,因此我们将继续处理更多的事情。 右上角的窗口是您将看到存储在工作空间中的所有变量和项的位置。 在其下,您会看到一个窗口,其中包含一些不同的选项卡(“文件”,“图”,“包”等)。 在这里,您可以查看工作目录中的项目,查看图,下载和选择包以及更多其他选项。

Screen-Shot-2015-07-20-at-8.16.15-AM.png

My first recommendation, along with getting familiar and checking out the functionality and preferences yourself, is to set your working directory first! Your working directory will be the location where the variables in the environment are saved. If you call any “save functions”, unless you specify another location in the variables, they will save to your working directory.  To do so, on the navigation bar at the top select Session >> Set Working Directory >> Choose Directory...

我的第一个建议是,首先熟悉您的工作目录,然后自己熟悉并检查其功能和首选项! 您的工作目录将是环境中变量的保存位置。 如果调用任何“保存函数”,除非您在变量中指定其他位置,否则它们将保存到您的工作目录中。 为此,请在顶部的导航栏上,选择“会话” >>“设置工作目录” >>“选择目录...”。

Screen-Shot-2015-07-20-at-8.56.44-AM.png

As you can see in the console window, the function setwd(" ") is run, this is another way of completing the same functionality with simple R code.  Another cool functionality is all the files in your working directory will easily be displayed and accessible via the bottom right window. The current working directory location can be viewed next to the “Console” window title on the left of the environment. I find this to be a very easy change that a lot of people overlook and can eliminate confusion later.

正如您在控制台窗口中看到的那样,运行了setwd(“”)函数,这是通过简单的R代码完成相同功能的另一种方法。 另一个很酷的功能是,您的工作目录中的所有文件都可以通过右下角的窗口轻松显示和访问。 当前工作目录位置可以在环境左侧的“控制台”窗口标题旁边查看。 我发现这是一个非常容易的更改,很多人忽略了此更改,以后可以消除混乱。

Now that you have changed your working directory and have gotten familiar with the basic layout of R Studio, it is time to write your first lines of code! My recommendation when writing code is to write it all in a script file so it can be saved or changed at a later time. To do so, click the “new” button on the top left and select “R Script” (see image below). As you can see this brings up a new window on the top left of the interface where code can be written. I recommend you play and adjust the windows on the interface to what fits your personal preference.

现在您已经更改了工作目录并熟悉了R Studio的基本布局,是时候编写第一行代码了! 在编写代码时,我的建议是将它们全部写入脚本文件中,以便以后可以保存或更改。 为此,请单击左上角的“新建”按钮,然后选择“ R脚本”(参见下图)。 如您所见,这会在界面的左上方弹出一个新窗口,您可以在其中编写代码。 我建议您根据自己的喜好播放和调整界面上的窗口。

Screen-Shot-2015-07-20-at-8.18.48-AM--3-

Try writing your first snippet of code:

尝试编写您的第一个代码段:

print("Hello World")
> print("Hello World")
[1] "Hello World"
2+2
(1/2)*(1/4)
(2*3)/4

If you want to save any script, click the save disk on the top of the top left window and save it wherever you would like! The default folder that will show up will be your current working directory!

如果要保存任何脚本,请单击左上方窗口顶部的保存磁盘,然后将其保存在任意位置! 将显示的默认文件夹将是您当前的工作目录!

That should give you a basic understanding to start discovering on your own what functionalities R is capable of. Right now it may look you that it is simply a bigger version of your desk calculator but I promise it is so much more. In future articles I will show and explain the incredible functionality of R as it applies to statistical data manipulation to get the most out of your information. If you have any questions about my article or have suggestions for future topics please leave a comment!

这应该使您有基本的了解,可以开始自己发现R的功能。 现在,您可能会发现它只是台式计算器的较大版本,但我保证它会更多。 在以后的文章中,我将展示和解释R的不可思议的功能,因为R应用于统计数据操作以充分利用您的信息。 如果您对我的文章有任何疑问或对未来主题有建议,请发表评论!

Next article in the series: https://www.experts-exchange.com/articles/19199/Mastering-R-Programming-Using-Packages-Creating-Objects-and-Basic-Matrix-Functions.html

该系列中的下一篇文章: https : //www.experts-exchange.com/articles/19199/Mastering-R-Programming-Using-Packages-Creating-Objects-and-Basic-Matrix-Functions.html

翻译自: https://www.experts-exchange.com/articles/18680/An-Introduction-to-R-Programming-and-R-Studio.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值