Welcome to the Simplilearn Community

Want to join the rest of our members? Sign up right away!

Sign Up

Data Science Certification Training - R Programming | JAN 11 - FEB 09 | Samridhi

while using barplot in code in the lab , it's showing an error

Error in plot.new() : figure margins too large

Will anyone please help me, how to resolve. While I am trying with any plots it is showing the same error.
 
Hi Samridhi,
I have two samples - one represents the cost of apple in NY and other represents the cost of apple in LA. Since the sample size is small and population variation is unknown, I want to run a t test with assumed equal variance, to see is the average price of apple in NY is at least 20% higher than average price of apple in LA.

I have defined the hypothesis as below -
Ho : mu(NY) > mu(LA) + 20%mu(LA) or, Ho: mu(NY) - mu(LA) > 20%mu(LA) or, Ho: mu(Hyp) > 0.649
Ha: mu(Hyp) < = 0.649

So, I performed one sided test here. Here is my code below. can you please check if this is what i intended for ?

NY_apple_data<- c(3.80, 3.76, 3.87, 3.99, 4.02, 4.25, 4.13, 3.98, 3.99, 3.62)
LA_apple_data<-c(3.02, 3.22,3.24, 3.02, 3.06, 3.15, 3.81, 3.44)

hyp_mu<- mean(LA_apple_data)/5 # Value of Hypothesised mean for T test

t.test(NY_apple_data, y = LA_apple_data, alternative = "less", mu = hyp_mu, var.equal = T)-> t_test
t_test
if(t_test$p.value > 0.05){
print("Average price of Apple in NY is atleast 20% higher than the price of LA")
}else {print("Average price of Apple in NY is less than or equal to 20% higher price than the price of LA")}

Now, my result shows that the price of apple in NY is alteast 20% higher than the price of apples in LA.
 

Samridhi Dutta

Well-Known Member
Alumni
Trainer
Hi Samridhi, Not sure if you get to see my message. I am waiting for the response. Am I supposed to follow any different link for responses or something? I could not practice any of the assignments.
Hi,

Here is the drive link in which datasets and assignments are uploaded.

Regards,
Samridhi
 

Samridhi Dutta

Well-Known Member
Alumni
Trainer
Error in Titanic$survived : $ operator is invalid for atomic vectors this is get when i try to access any columns of the database.
Hi Gautam,

Please read the titanic_train file as shared in Datasets folder on google drive. You can read that using read.csv in a dataframe. The features in a dataframe can be accessed using $ symbol.

Regards,
Samridhi
 

Samridhi Dutta

Well-Known Member
Alumni
Trainer
Hii i have tried to solve assignment 3 please help me last part where we require to find how many plane flew to destination once

#Questions for apply and dplyr family
head(iris)
?iris
str(iris)
#Find the sum of each column and confirm if the sum is greater than 800 or not
which(apply(iris[,1:4],MARGIN = 2,sum) > 800)
#Hint: create a custom function to find the sum and compare it with 800,
#and apply the function on each numerical column
fn = function(data)
{
sum(data)>800

}
apply(iris[,1:4],MARGIN = 2,fn)
#Find the sum / mean / median of Sepal Length species-wise
for (value in levels(iris$Species))
{
print(sum(iris$Sepal.Length[which(iris$Species==value)]))
print(mean(iris$Sepal.Length[which(iris$Species==value)]))
print(median(iris$Sepal.Length[which(iris$Species==value)]))
}
#For all the flowers having sepal width > 3.0, find the number of flowers in each species
table(iris$Species[which(iris$Sepal.Width>3.0)])
#Count how many different petal widths are there in each species.
for (value in levels(iris$Species))
{
print(length(table(iris$Petal.Width[which(iris$Species==value)])))
}
#Soln
?dplyr
library(dplyr)
iris%>%group_by(Species)%>%summarise(n_distinct(Petal.Width))
#Titanic Data set-------------------------------------------------------------
setwd("C:/Users/Alaska/Desktop/Simplilearn/Datascience with R/Live class/practicse")
train = read.csv("titanic_train.csv",na=c("","?","T"))
#Q. Find the proportion survived of males and females survived
aggregate(Survived ~ Sex, data=train, FUN=function(x) {round(sum(x)/length(x),digits=2)})
#Q. Find the proportion survived of males and females
aggregate(Survived ~ Pclass, data=train, FUN=function(x) {round(sum(x)/length(x),digits=2)})
#Q. Find the proportion of people survived passenger class wise and sex wise
aggregate(Survived ~ Pclass + Sex, data=train, FUN=function(x) {round(sum(x)/length(x),digits=2)})
#Q. Strip off the title from the names of the passengers, and create a sep col named title.
#Q. Ultimately we want only 4 levels in this col: Miss Mr. Mrs and Master
train$Title[train$Title %in% c('Lady', 'the Countess', 'Mlle')] <- 'Miss'
#if train$title is one among c('Lady', 'the Countess', 'Mlle') then give true / false
train$Title[train$Title %in% c('Capt', 'Don', 'Major', 'Sir', 'Col', 'Jonkheer', 'Rev', 'Dr') & train$Sex == "male" ] <- 'Mr'
train$Title[train$Title %in% c('Dona','Lady',"Dr","Mme", 'Ms') & train$Sex == "female"] <- 'Mrs'
?table
#hflights------------------------------------------------------------------------------------------
library(hflights)
install.packages("hflights")
#How many flights are not cancelled? Hint: use var cancellation code
table(hflights$CancellationCode)['C']
str(hflights)
hflights$CancellationCode
#Combine year month and day variables to create a date column
hflights$Date<- paste(hflights$DayofMonth,"/",hflights$DayofMonth,"/",
hflights$Year, sep = "")
hflights$Date
#Find the maximum AirTime for all flights whose Departure delay is not NA
max(hflights$AirTime[which(!is.na(hflights$DepDelay))], na.rm = T )
#Find per-carrier mean of arrival delays and arrange them in increasing / decreasing order
hflights%>%group_by(hflights$UniqueCarrier)%>%summarise(n_distinct(hflights$ArrDelay ))
table(hflights$UniqueCarrier, useNA="ifany")
hflights%>%group_by(UniqueCarrier)%>%mean(ArrTime , na.rm = T )
#How many airplanes only flew to one destination from Houston?
hflights[which(hflights$Origin == "HOU"),]->sam
which(table(sam$TailNum)==1)
# Hint: each tail number represents 1 airplane.
summarise_at(group_by(hflights,UniqueCarrier),vars(ArrTime),funs(mean(.,na.rm=TRUE)))
aggregate(hflights$ArrTime, by=list(hflights$UniqueCarrier), FUN=mean)

Hi,

Here is the answer to the last part:
hflights%>%filter(Origin=="HOU")%>%group_by(TailNum)%>%
summarise(n=n_distinct(Dest))%>%filter(n==1)%>%summarise(n())

Regards,
Samridhi
 

Samridhi Dutta

Well-Known Member
Alumni
Trainer
Dear Samridhi, can you please check below two questions?
class(cat(1,2,3)) #why NULL?
class(paste(1,2,3)) #why character?

Hi Nanar,

- cat will only paste and print the value. No value is being returned. Since the returned value is null, so the class of the returned value is NULL.
- paste will return a character value.

Regards,
Samridhi
 

Samridhi Dutta

Well-Known Member
Alumni
Trainer
Hi Samridhi,

In Class 3 you asked to find the Age of "Moran, Mr. James" from the titanic dataset.

I am unable to get the solution for the same by using grep function....please help.

Solution: grep(pattern = "Moran, Mr. James",x=tit$Age,fixed = T,value = T)

output: character(0)

please help

Hi Nikhil,

You should be looking for the pattern in the Passenger Names vector and not in Age vector.

Regards,
Samridhi
 
Hi Samriddhi,

I have to go on an unplanned travel out of town. I won't be able to attend the last 2 sessions, and my project is also still work-in-progress. What are my options?
One option I can think of is I will watch the recordings of the last 2 classes when I return on monday. Also submit my project sometime next week.

Please let me know your thoughts.

Thanks,
Makarand
 
Hi Samriddhi,

I have to go on an unplanned travel out of town. I won't be able to attend the last 2 sessions, and my project is also still work-in-progress. What are my options?
One option I can think of is I will watch the recordings of the last 2 classes when I return on monday. Also submit my project sometime next week.

Please let me know your thoughts.

Thanks,
Makarand
Please contact support asap
 

Lindys Stein

New Member
I would love to know how to deal with the errors I get while trying to add a PDF converter function on my site. It's quite frustrating having to run constantly on such error messages. It should be much easier to add some simple integrations to my site. I have found only one new coding language working extremely well with this kind of command. If you click here you will be able to find how I have managed to add AI functions and database automation to my site. Really cool stuff! The best part is the amazing and futuristic look my site has gained.
 
Last edited:
Top