[R] 창우과제
height <- c(180, 165, 172, 159, 178, 170, 163, 162, 165)
Sex <- c('M', 'W', 'M', 'W', 'M', 'W', 'W', 'W','M')
height_data <- data.frame(height, Sex)
w = height_data[height_data,height_data$Sex == "W"]
w = subset(height_data , Sex == "W")
w
m = subset(height_data, Sex == "M")
plot(w$number,w$height)
plot(law,m$height)
rownames(height_data) = c(1:9)
height_data
aggregate(height_data$height, list(height_data$Sex),mean)
aggregate(height_data$height, list(height_data$Sex),var)
aggregate(height_data$height, list(height_data$Sex),sd)
w = height_data[height_data,height_data$Sex == "W"]
w = subset(height_data , Sex == "W")
w
m = subset(height_data, Sex == "M")
plot(w$number,w$height)
plot(law,m$height)
rownames(height_data) = c(1:9)
height_data
aggregate(height_data$height, list(height_data$Sex),mean)
aggregate(height_data$height, list(height_data$Sex),var)
aggregate(height_data$height, list(height_data$Sex),sd)
D1<-c(3,2,3,3,2,2,1,3,3,3,2,3,1,2,3,3,3,1,3,2)
table(D1)
D1
table_D1=table(D1)
proptable_D1=prop.table(table(D1))
cumsum_D1=cumsum(table(D1))
class(proptable_D1)
cbind(table_D1,proptable_D1,cumsum_D1)
getwd()
E2=read.csv("E2.csv",row.names = 1,header = TRUE,stringsAsFactors = F)
E2
hist(E2$Frequency,col='blue', border = 'black')
hist(E2$Relative.Frequency, col='red', border = 'black')
read.csv("E3.csv",header = TRUE,stringsAsFactors = F)
E3=read.csv("E3.csv",header = TRUE,stringsAsFactors = F)
head(E3)
C = subset(E3,癤풞rea == "Centre" )
E3C=data.frame(number2,C$癤풞rea,C$Price)
number2<-(1:6)
plot(E3C$number2,E3C$C.Price,type='p')
East = subset(E3,癤풞rea == "East")
nrow(East)
East=data.frame(number3,East$癤풞rea,East$Price)
number3<-(1:22)
East
plot(East$number3,East$East.Price)
read.csv("E4.csv",header = TRUE,stringsAsFactors = F)
plot(E4$癤풵eek == "X1",
# example 1
df = read.csv("C:/Users/82102/Documents/E1.csv")
plot.new()
x <- 1:100
y <- df$height
g <- df$sex
str(g)
plot(x, y, type = "n") # Draws no points
points(x[g == "M"], y[g == "M"], col = "blue", pch = 1)
points(x[g == "F"], y[g == "F"], col = "red", pch = 19)
legend("topleft", c("Male", "Female"), col = c("blue", "red"), pch = c(1, 19))
aggregate(df$height, list(df$sex) ,mean)
aggregate(df$height, list(df$sex) ,var)
aggregate(df$height, list(df$sex) ,sd)
# example 2
D1<-c(3,2,3,3,2,2,1,3,3,3,2,3,1,2,3,3,3,1,3,2)
table(D1)
Freq=table(D1)
Rel.Freq=prop.table(table(D1))
cum.Freq=cumsum(table(D1))
D1.2=cbind(Freq,Rel.Freq,cum.Freq)
D1.2
# Example 3
df2=read.csv("C:/Users/82102/Documents/E2.csv")
hist(df2$Frequency,col='green')
hist(df2$Relative.Frequency,col='blue')
# Example 4
df3=read.csv("C:/Users/82102/Documents/E3.csv")
colnames(df3)=c('Area','Price')
df3
Cen=subset(df3,Area=='Centre')
East=subset(df3,Area=='East')
rownames(East)=c(1:22)
North=subset(df3,Area=='North')
rownames(North)=c(1:9)
South=subset(df3,Area=='South')
West=subset(df3,Area=='West')
rownames(West)=c(1:3)
rownames(South)=c(1:10)
Cnumber=c(1:6)
Cdf=data.frame(Cnumber,Cen$Area,Cen$Price)
plot(Cdf$Cnumber,Cdf$Cen.Price,type='p',xlab='number',ylab='price',main = 'Centre')
Enumber=c(1:22)
Edf=data.frame(Enumber,East$Area,East$Price)
plot(Edf$Enumber,Edf$East.Price,type='p',xlab='number',ylab='price',main = 'East')
Nnumber=c(1:9)
Ndf=data.frame(Nnumber,North$Area,North$Price)
plot(Ndf$Nnumber,Ndf$North.Price,type='p',xlab='number',ylab='price',main='North')
Snumber=c(1:10)
Sdf=data.frame(Snumber,South$Area,South$Price)
plot(Sdf$Snumber,Sdf$South.Price,type='p',xlab='number',ylab='price', main = 'South')
Wnumber=c(1:3)
Wdf=data.frame(Wnumber,West$Area,West$Price)
plot(Wdf$Wnumber,Wdf$West.Price,type = 'p',xlab='number',ylab='price',main='West')
?plot
#Example5
df4=read.csv("C:/Users/82102/Documents/E4.csv")
colnames(df4)=c('week','one','two')
barplot(c(2,3),xlab='week',ylab='number',col = 'blue')
barplot(c(5,4),xlab='week',ylab='number')
barplot(c(7,7),xlab='week',ylab='number')
barplot(c(3,2),xlab='week',ylab='number')
barplot(c(6,1),xlab='week',ylab='number')
barplot(c(2,6),xlab='week',ylab='number')
barplot(c(4,2),xlab='week',ylab='number')
#Example6
x=c('Sun','Mon','Tue','Wed','Thu','Fri','Sat')
y=c(2,5,7,3,6,2,4)
z=c(3,4,7,2,1,6,2)
E5.1=rbind(x,y,z)
rownames(E5.1)=c('Day','Week1','Week2')
barplot(y,col = 'blue',main='week1',names=x)
barplot(z,col = 'Red', main='Week2',names=x)
?barplot
#Example 7
x
y=c(156,206,263,251,216,230,157)
E7=rbind(x,y)
rownames(E7)=c('Week','Births')
E7
barplot(y,names=x,main='Birts',col = 'Blue')