# MATH 223 Lecture Notes - Lecture 10: Scatter Plot, Summary Statistics, Working Directory

9 views4 pages

21 Oct 2020

School

Department

Course

Professor

Questions:

Use the dataset “Food Nutrition” and answer the following questions:

1. Set the working directory for your work

2. Import the dataset in the console in the .xls(x) format

3. View the top 10 rows of the data

4. View the last 20 rows of the data

5. Show the summary of the data

6. Create a vector “test” using the top 10 values of variable Protein_(mg)

7. Select the top 5 rows of initial 5 variables in a matrix format

8. What is the class of the Sodium_(mg) variable

9. Create a new variable “EPW” by dividing Energ_Kcal with the Water; what is the

dimension of the new dataset?

10. Create a subset of the dataset, where the Energ_Kcal is less than 500, what is the

dimension of this new dataset?

11. Plot a Scatter Plot between Enrg_Kcal and Water using the new subset created

12. Plot a histogram of Sugar_tot variable using the new subset

13. Find the top 10 products based on following

1. Higher the Energy_Kcal, higher the ranking

2. Lower the water content, higher the ranking

14. Create a subset of the data where product_desc contains “CHEESE” and list down

the summary statistics of the subset

15. Using the cut function on water variable divide the whole data into 6 bins, list down

the summary statistics of all the 6 bins

Solution:

#set directory

getwd()

setwd("F:/Nivedita/PGP-BABI/R-Prog/FoodNutritionAssign2")

#install package

install.packages("readxl")

library(readxl)

#read excel

req_data_f<-read_excel("Food Nutrition.xlsx")