#installation of respective packages
library(randomNames)
## Warning: package 'randomNames' was built under R version 4.1.2
library(tidyverse)
## -- Attaching packages --------------------------------------- tidyverse 1.3.1 --
## v ggplot2 3.3.5 v purrr 0.3.4
## v tibble 3.1.4 v dplyr 1.0.7
## v tidyr 1.1.3 v stringr 1.4.0
## v readr 2.0.1 v forcats 0.5.1
## -- Conflicts ------------------------------------------ tidyverse_conflicts() --
## x dplyr::filter() masks stats::filter()
## x dplyr::lag() masks stats::lag()
`
#Generate 100 student names (first and last names) using random names package.
student_names <- randomNames(100)
# displaying first 10 student names
student_names[1:10]
## [1] "el-Kaiser, Najaat" "Sayavong, Murphy" "el-Morad, Taqi"
## [4] "Aebischer, Brandon" "Odom, Ashanti" "Bowen, David"
## [7] "Pham, Casey" "el-Ayoob, Mumtaaza" "Zamora, Julia"
## [10] "Jones, Brandon"
#Generate 100 grades for above students. Random number should have a mean of 70 with standard distribution of 15. Below functions, rnorm and floor would be useful.
student_grades <- rnorm(100, mean = 70, sd = 15) %>%
floor()
# displaying first 10 student names
student_grades[1:10]
## [1] 31 75 66 72 67 77 78 61 68 75
#Put student names and grades to one tibble (data frame) You can use as_tibble function for this purpose. Your tibble should have at least 2 columns (names, grades).
df <- tibble(student_names,student_grades )
# displaying top 10 names with grades
head(df,10)
## # A tibble: 10 x 2
## student_names student_grades
## <chr> <dbl>
## 1 el-Kaiser, Najaat 31
## 2 Sayavong, Murphy 75
## 3 el-Morad, Taqi 66
## 4 Aebischer, Brandon 72
## 5 Odom, Ashanti 67
## 6 Bowen, David 77
## 7 Pham, Casey 78
## 8 el-Ayoob, Mumtaaza 61
## 9 Zamora, Julia 68
## 10 Jones, Brandon 75
#export this data frame as csv file, student_grades.csv.
write_csv(df, "student_grades.csv")
#Differences
#write.csv() is twice as fast as compared to write_csv