Shana Green
R Bridge
HW 2
Due 07/26/20
# loading the data set
frostedflakes<- read.csv("frostedflakes.csv")
2. Create a new data frame with a subset of the columns and rows. Make sure to rename it.
#Create a subset extracting 50 participants from a given range
sweetfrostedflakes<-subset(frostedflakes[c(1:50),c("X","Lab","IA400")])
View(sweetfrostedflakes)
3. Create new column names for the new data frame.
colnames(sweetfrostedflakes)<-c("Y","Lab2","JA400")
View(sweetfrostedflakes)
5. For at least 3 values in a column please rename so that every value in that column is renamed. For example, suppose I have 20 values of the letter “e” in one column. Rename those values so that all 20 would show as “excellent”.
sweetfrostedflakes$Lab2<-replace(sweetfrostedflakes$Lab2, sweetfrostedflakes$Lab2 > 40, "Corn Flakes")
sweetfrostedflakes
## Y Lab2 JA400
## 1 1 36.3 35.1
## 2 2 33.2 35.9
## 3 3 39 40.1
## 4 4 37.3 35.5
## 5 5 Corn Flakes 37.9
## 6 6 38.4 39.5
## 7 7 35.8 38.5
## 8 8 36 37.9
## 9 9 37.9 41.2
## 10 10 Corn Flakes 45.7
## 11 11 40 38.3
## 12 12 Corn Flakes 42.3
## 13 13 36.6 39.0
## 14 14 33.7 30.8
## 15 15 Corn Flakes 37.3
## 16 16 38.7 39.5
## 17 17 36.2 40.3
## 18 18 Corn Flakes 42.0
## 19 19 37.8 36.9
## 20 20 Corn Flakes 41.2
## 21 21 38.9 39.3
## 22 22 36 35.6
## 23 23 Corn Flakes 40.9
## 24 24 40 37.6
## 25 25 35.5 35.5
## 26 26 34.3 35.5
## 27 27 33 32.4
## 28 28 36.9 36.1
## 29 29 36.3 36.1
## 30 30 38.5 39.0
## 31 31 35.1 38.5
## 32 32 38.7 40.0
## 33 33 34 35.4
## 34 34 Corn Flakes 40.9
## 35 35 Corn Flakes 39.4
## 36 36 38.2 38.6
## 37 37 38.3 39.6
## 38 38 37.4 39.2
## 39 39 37.5 36.4
## 40 40 36.5 36.1
## 41 41 34.8 38.1
## 42 42 38.1 39.6
## 43 43 Corn Flakes 40.8
## 44 44 35.4 37.4
## 45 45 35 37.6
## 46 46 37.9 36.0
## 47 47 39.1 37.2
## 48 48 33.3 33.0
## 49 49 Corn Flakes 41.9
## 50 50 34.9 37.9
I chose values over Lab values over 40 and replaced it with string "Corn Flakes"
6. Display enough rows to see examples of all of steps 1-5 above.
head(sweetfrostedflakes,10)
## Y Lab2 JA400
## 1 1 36.3 35.1
## 2 2 33.2 35.9
## 3 3 39 40.1
## 4 4 37.3 35.5
## 5 5 Corn Flakes 37.9
## 6 6 38.4 39.5
## 7 7 35.8 38.5
## 8 8 36 37.9
## 9 9 37.9 41.2
## 10 10 Corn Flakes 45.7
7. BONUS – place the original .csv in a github file and have R read from the link. This will be a very useful skill as you progress in your data science education and career.
frostedflakes<- read.csv("https://raw.githubusercontent.com/sagreen131/R-Week-2/master/frostedflakes.csv")