• 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

Statinfer

Statinfer derived from Statistical inference. We provide training in various Data Analytics and Data Science courses and assist candidates in securing placements.

Contact Us

info@statinfer.com

+91- 9676098897

+91- 9494762485

 

Our Social Links

top
© 2020. All Rights Reserved.