Академический Документы
Профессиональный Документы
Культура Документы
# plot categorical
plot(pelican$Type.of.Customer)
# plot numerical
plot(pelican$Net.Sales)
# plot 2 x categorical
plot(pelican$Type.of.Customer, pelican$Method.of.Payment)
# plot histogram
hist(pelican$Net.Sales)
# box plot
boxplot(pelican$Net.Sales)
rm(list = ls())
--------------------------------------------------------------------------
plot(pelican$Age, pelican$Net.Sales, xlab = "Age", ylab = "Net Sales", main = "Age
vs Sales", col = "orange")
######################################
plot(salescalls, unitsold)
lm(unitsold~salescalls)
abline(lm(unitsold ~ salescalls))
attach(mtcars)
plot(wt, mpg)
abline(lm(mpg~wt))
title("Reg")
detatch(mtcars)
----------------------------------------------------------------
A1 <- matrix(1:10, nrow = 5, byrow = TRUE)
nrow(A)
ncol(A)
dim(A)
# Check if elements are equal
A == B
A %*% t(B)
rownames(A) <- c("First", "Second", "Third", "Fourth", "Fifth")
cbind(1:3, 4:6)
# Subsetting Matrix
# subset by names
exp(10)
abs(35)
sqrt(100)
ceiling(34.59)
floor(34.59)
round(34.59, 1)
trunc(34.59)
# Paste
i <-10
paste("i = ", i)
toupper("hello")
sum1 <- function()
{
a <- 10
b <- 10
c <- a+b
print("Addition of two numbers")
print(c)
}
sum1()
------------------
x <- 0
if(x > 0)
{
print("Positive number")
}else if(x < 0)
{
print("Negative number")
}else
print("Zero")
n <- readline("Enter any number: ")
n <- as.integer(n)
# Check wether the no. is odd or even
if((n%%2) == 0)
---------------------------------------------------------------
#sum the rows
apply(theMatrix, 1, sum, na.rm=TRUE)
rowSums(theMatrix)
theList <- list(A = matrix(1:9, 3), B = 1:5, C = matrix(1:4,2), D=2)
require(ggplot2)
data(diamonds)
head(diamonds)
View(diamonds)
# Calculate the average price for each type of cut: Fair, Good, Very Good, Premium,
Ideal
# Group the data by more than one variable: cut and color
require(plyr)
aggregate(price ~ cut, diamonds, each(mean, median))
cor(diamonds$carat, diamonds$price)
round(cor(diamonds$carat, diamonds$price), 2)
cor.test(diamonds$carat, diamonds$price)
----------------------------------------------------
x <- sample(x = 1:100, size = 100, replace = TRUE)
# Weighted mean
grades <- c(90, 89, 78, 55)
weights <- c(1/2, 1/4, 1/8, 1/8)
mean(grades)
sd(y)
summary(y)