顯示具有 R language 標籤的文章。 顯示所有文章
顯示具有 R language 標籤的文章。 顯示所有文章

2020/9/21

R Programming Language - Run R Script

To run R script, install RStudio.

Add a new R script file and save it as a *.R file.


The code in the new script file can be:

a = 1

b = 2

a+b

When executing the script file, move the cursor to the first line of the script.

Press the run button, one line is run and the cursor is moved to the next line.

In the above example, press the run button three time for the three lines as below:



Related Information:

Installation and basic R commands

R programming language - load and save data

2020/9/3

R programming language - load and save data

This article explains the commands to load and save R data.

Firstly, declare data x:

    x = c(1,2,3,4,5,6)

Get the local path: getwd()

    path = getwd()

Change path:

    pathnew = file.path(path,"Desktop")

Set the local path: setwd()

    setwd(pathnew)

Save

    filename = file.path(pathnew,"test.RData")

    save(x,file=filename)

Clear workplace

    rm(list=ls())

Load

    filename = file.path(getwd(),"test.RData")

    load(filename)

    > x

    [1] 1 2 3 4 5 6

Related Information:

How to save and run an R Script

Installation and basic R commands

2020/8/18

Installation and Basic R commands

The R Project for Statistical Computing software is available with multiple operating systems such as Windows, MacOS.

It may be downloaded here:

https://www.r-project.org

After installation, try declare values with '=' or '<-' and see the average result with 'mean' function.

> x<-c(1,2,3,4,5)

> mean(x)

[1] 3

> y<-c(2,3,4,5,6,7,8)

> mean(y)

[1] 5

> z=c(5,6,7)

> mean(z)

[1] 6

Result:

To remove the above warning messages, open terminal and type:

defaults write org.R-project.R force.LANG en_US.UTF-8

Reference:

[記宅] 在 Mac 上安裝 R 語言 (R Studio, R) 新手介紹

Related Information:

R programming language - load and save data

How to save and run an R Script