Question

In: Advanced Math

Assignment 1 - IN PDF FORMAT Using R and Rstudio Pick a database from: data() Then...

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 a field in your dataset. You can do it by dataset[[xx]] operator with xx can be the index of the field or the nae of the field.

Now use dataset[xx] to get a slice of datframe instead of vector, e.g. df = mtcars[c(‘mpg’, ‘disp’)] - With two scalar arguments (rows,columns), the [] operator can select elements in the dataframe. Try this.

- Subset your data using rules similar to the lectures. For example part of the data that has a characteristics AND/OR another one, etc.

- Write a function that does an operation, for example averaging a property, on your dataset.

- Write a function that works on rows and adds a column to the dataset with the results for each row.

- Using the iris database, explain the following line of code:

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

Solutions

Expert Solution

IF YOU HAVE ANY DOUBTS COMMENT BELOW I WILL BE TTHERE TO HELP YOU..ALL THE BEST

CODE:

set.seed(1)
dataset <- data.frame(A = sample(c(NA, 1:100), 1000, rep = TRUE),
                      B = rnorm(1000))

> head(dataset)
   A           B
1 26  0.07730312
2 37 -0.29686864
3 57 -1.18324224
4 91  0.01129269
5 20  0.99160104
6 90  1.59396745
> nrow(dataset)
[1] 1000
> NROW(dataset)
[1] 1000

#1

rm(list = ls())

# 1.1 Modes and Classes
mylist <- list(a = c(1, 2, 3),
               b = c("cat", "dog", "duck"),
               d = factor("a", "b", "a"))
sapply(mylist, mode)
sapply(mylist, class)

# 1.2 Data Storage in R
x <- c(1, 2, 5, 10)
x
mode(x)
y <- c(1, 2, "cat", 3)
mode(y)
z <- c(5, TRUE, 3, 7)
mode(z)
all <- c(x, y, z)
all

x <- c(one = 1,
       two = 2,
       three = 3)
x
x <- c(1, 2, 3)
x
names(x) <- c('one', 'two', 'three')
x
str(x)
mode(x)
class(x)

nums <- 1:10
nums + 1
nums + c(1, 2)
nums + 1:2
nums + c(1, 2, 3)

rmat <- matrix(rnorm(15), 5, 3,
               dimnames = list(NULL, c('A', 'B', 'C'))
               )
rmat
rmat[, 'A']
as.matrix(rmat[, 'A'])

mylist <- list(c(1, 4, 6),
               "dog", 3, "cat", TRUE, 
               c(9, 10, 11)
               )
mylist
sapply(mylist, mode)
sapply(mylist, class)

mylist <- list(first = c(1, 3, 5),
               second = c('one', 'three', 'five'),
               third = 'end')
mylist
mylist['third']

mylist <- list(c(1, 3, 5),
               c('one', 'three', 'five'), 'end')
names(mylist) <- c('first', 'second', 'third')
mylist

# 1.3 Testing for Modes and Classes
# no code

# 1.4 Structure of R Objects

mylist <- list(a = c(1, 2, 3),
               b = c('cat', 'dog', 'duck'),
               d = factor('a', 'b', 'a')
               )

summary(mylist)
nestlist <- list(a = list(matrix(rnorm(10), 5, 2),
                          val = 3),
                 b = list(sample(letters, 10),
                          values = runif(5)),
                 c = list(list(1:10, 1:20), list(1:5, 1:10))
                 )

summary(nestlist)
str(nestlist)

list(1:4, 1:5)

# 1.5 Conversion of Lists

nums <- c(12, 10, 8, 12, 10, 12, 8, 10, 12, 8)
tt <- table(nums)
tt
names(tt)
sum(names(tt) * tt)
sum(as.numeric(names(tt)) * tt)

as.numeric("123")

x=c(1, 2, 3, 4, 5)
list(x)
as.list(x)

I HOPE YOU UNDERSTAND..

PLS RATE THUMBS UP..ITS HELPS ME ALOT..

THANK YOU...!!


Related Solutions

This question requires using Rstudio. This is following commands to install and import data into R:...
This question requires using Rstudio. This is following commands to install and import data into R: > install.packages("ISLR") > library(ISLR) > data(Wage) The required data installed and imported, now this is description of the data: This dataset contains economic and demographic data for 3000 individuals living in the mid-Atlantic region. For each of the 3000 individuals, the following 11 variables are recorded: year: Year that wage information was recorded age: Age of worker maritl: A factor with levels 1. Never...
This question requires using Rstudio. This is following commands to install and import data into R:...
This question requires using Rstudio. This is following commands to install and import data into R: > install.packages("ISLR") > library(ISLR) > data(Wage) The required data installed and imported, now this is description of the data: This dataset contains economic and demographic data for 3000 individuals living in the mid-Atlantic region. For each of the 3000 individuals, the following 11 variables are recorded: year: Year that wage information was recorded age: Age of worker maritl: A factor with levels 1. Never...
This question requires using Rstudio. This is following commands to install and import data into R:...
This question requires using Rstudio. This is following commands to install and import data into R: > install.packages("ISLR") > library(ISLR) > data(Wage) The required data installed and imported, now this is description of the data: This dataset contains economic and demographic data for 3000 individuals living in the mid-Atlantic region. For each of the 3000 individuals, the following 11 variables are recorded: year: Year that wage information was recorded age: Age of worker maritl: A factor with levels 1. Never...
I have an assignment that must be done on R/R studio R/RStudio - Chapter 4- Correlation...
I have an assignment that must be done on R/R studio R/RStudio - Chapter 4- Correlation and Regression Step 1 – Download and Install the R/RStudio software on your computer. The link and instructions to do that are on Blackboard under Course Information. Step 2 – Access the Data Sets in MyLab through StatCrunch. In chapter 4, a data set called “Used BMW prices 2017” is what we’ll use. Step 3 – When you open the data set in StatCrunch,...
Using the data from the csv file, answer the questions with rstudio # number_children - The...
Using the data from the csv file, answer the questions with rstudio # number_children - The number of children in the home # internet - Does the home have internet access? # mode - The way the household took the survey # own - Do the residents own with or without a mortgage or rent? # language - The primary language spoken in the home # decade_built - The decade the home was built 1) In how many households, wife’s...
Do the assignment in R/RStudio. Copy or compile your results into Word, write any explanations and...
Do the assignment in R/RStudio. Copy or compile your results into Word, write any explanations and turn in the hard copy. You conduct a survey of New Yorkers. The survey uses a stratified sample of 100 employed college graduates and 100 employed high school graduates. Your survey concludes that 70% of college graduates are happy with their job compared to only 60% of high school graduates. a. What is the standard error and margin of error of the estimate for...
RSQLite (using R studio) 1. Make you have imported the database tables into your database (I've...
RSQLite (using R studio) 1. Make you have imported the database tables into your database (I've copied and pasted these at the bottom). Write and submit the following RSQLite queries. 2. Retrieve the names of all employees. 3. Retrieve the names of all distinct employee names. 4. Retrieve the names of all employees whose name begins with the letter ‘B’. 5. Retrieve the names and NI numbers (NI_NO) of all employees. 6. Retrieve details of employees who are over 31...
Complete the R code using Rstudio so that it calculates and returns the estimates of β,...
Complete the R code using Rstudio so that it calculates and returns the estimates of β, the intercept and regression weight of the logistic regression of approximate GPA on Rouder-Srinivasan preference. ## Data Preference <- c( 0, 0, 0, 0, 0, 1, 1, 1, 1) # 0: Rouder; 1: Srinivasan GPA <- c(2.0, 2.5, 3.0, 3.5, 4.0, 2.5, 3.0, 3.5, 4.0) Count <- c( 4, 5, 21, 22, 8, 2, 1, 4, 7) # Define the deviance function deviance <-...
Hi, someone please do every part. I'm desperate!! :( Using RStudio, Create an R-Script: (1) You...
Hi, someone please do every part. I'm desperate!! :( Using RStudio, Create an R-Script: (1) You will generate a numeric matrix of size 21 by 21 and will name it tmp. To do so, draw 21×21 = 441 random observations from the standard normal distribution. Before doing so, set the seed for the random number generator to 37. See help for set.seed(). (2) Change the diagonal elements of tmp to 1s. (3) Calculate condition number of tmp. See help for...
Please use RStudio to answer the question and give the R command: please load data use...
Please use RStudio to answer the question and give the R command: please load data use data: library(MASS) data(cats) Use the “cats” data set to test for the variance of the body weight in male and female cats
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT