• No products in the cart.

103.1.10 My First R Program

An Example R program.

In previous section, we studied about Most Common Errors in R, now we will be studying about My First R Program.

Here are the following operations that must be performed using R.

  • Create income data(vector) for 4 employees with the values 5500, 6700, 8970, 5634.
  • Create a new variable tax and save 0.2 in it.
  • Create a new variable year and save 2015 in it.
  • Create a new variable company and save “DataVedi” in it.
  • Derive net_income by deducting tax from the income.
  • Create Employee name(vector) for 4 employees with the values Redd, Kenn, Finn, Scott.
  • Create a data frame with Employee name and Net income.
  • Create a new list with all the above information on company, year, tax, Employee name and Salary dataset.

Operations

> income<-c(5500, 6700, 8970, 5634)
 > tax<-0.2
 > year<-2015
 > company<-"Datavedi"
 > net_income<-income-tax
 > net_income<- income*(1-tax)
 > Emp_name<-c("Redd", "Kenn", "Finn", "Scott")
 > Emp_database<-data.frame(net_income, Emp_name)
 > View(Emp_database)
 > Emp_db_list<-list(income,tax, year, company, Emp_database)

 

Solution

 > tax
 [1] 0.2
 > year
 [1] 2015
 > income
 [1] 5500 6700 8970 5634
 > company
 [1] "Datavedi"
 > net_income
 [1] 4400.0 5360.0 7176.0 4507.2
 > Emp_database
 net_income Emp_name
 1 4400.0 Redd
 2 5360.0 Kenn
 3 7176.0 Finn
 4 4507.2 Scott
 > Emp_db_list
 [[1]]
 [1] 5500 6700 8970 5634
 [[2]]
 [1] 0.2
 [[3]]
 [1] 2015
 [[4]]
 [1] "Datavedi"
 [[5]]
 net_income Emp_name
 1 4400.0 Redd
 2 5360.0 Kenn
 3 7176.0 Finn
 4 4507.2 Scott

20th June 2017

DV Analytics

DV Data & Analytics is a leading data science,  Cyber Security training and consulting firm, led by industry experts. We are aiming to train and prepare resources to acquire the most in-demand data science job opportunities in India and abroad.

Bangalore Center

DV Data & Analytics Bangalore Private Limited
#52, 2nd Floor:
Malleshpalya Maruthinagar Bengaluru.
Bangalore 560075
India
(+91) 9019 030 033 (+91) 8095 881 188
Email: info@dvanalyticsmds.com

Bhubneshwar Center

DV Data & Analytics Private Limited Bhubaneswar
Plot No A/7 :
Adjacent to Maharaja Cine Complex, Bhoinagar, Acharya Vihar
Bhubaneswar 751022
(+91) 8095 881 188 (+91) 8249 430 414
Email: info@dvanalyticsmds.com

top
© 2020. All Rights Reserved.