Assignment 1 - IN PDF FORMAT Using R and Rstudio
Pick a database from: data()
Then preview the first 10 rows.
Print the number of rows and columns
- Print the names of the variables
If you have row names, print them - work with the values for afield in your dataset. You can do it by dataset[[xx]] operator withxx can be the index of the field or the nae of the field.
Now use dataset[xx] to get a slice of datframe instead ofvector, e.g. df = mtcars[c(‘mpg’, ‘disp’)] - With two scalararguments (rows,columns), the [] operator can select elements inthe dataframe. Try this.
- Subset your data using rules similar to the lectures. Forexample part of the data that has a characteristics AND/OR anotherone, etc.
- Write a function that does an operation, for example averaginga property, on your dataset.
- Write a function that works on rows and adds a column to thedataset with the results for each row.
- Using the iris database, explain the following line ofcode:
data(iris) aggregate(iris[\"Petal.Length\"], by = iris[\"Species\"],FUN=median)
## Species Petal.Length
## 1 setosa 1.50
## 2 versicolor 4.35
## 3 virginica 5.55