Skip to content

Instantly share code, notes, and snippets.

@victorkurauchi
Last active October 25, 2017 00:50
Show Gist options
  • Save victorkurauchi/bc72bc8b73bf82755d224fa9c27ae801 to your computer and use it in GitHub Desktop.
Save victorkurauchi/bc72bc8b73bf82755d224fa9c27ae801 to your computer and use it in GitHub Desktop.
Working with R and dataframes
nomes <- c('victor', 'moriyuki', 'kurauchi')
salarios <- c(100, 200, 300)
idades <- c(18, 19, 20)
cadastro <- data.frame(nomes, salarios, idades)
cadastro
filhos <- c(0, 2, 4)
cadastro$filhos <-c(filhos)
cadastro
cadastro$aumento_salarial <- c((salarios * 0.1)+salarios)
cadastro
names(cadastro)
levels(cadastro$nomes)
write.csv(cadastro, file='C:/Users/logonrm/Desktop/teste.csv')
# working with excel files
attach(Apend_BB)
Apend_BB [order(Apend_BB$id), ]
unique(Apend_BB)
library(dplyr)
grupo <- group_by(Salario, id)
grupo
agregar <- summarise(
grupo,
salario_m = mean(salario_m),
data_pagamento_min = min(data_pagamento),
data_pagamento_max = max(data_pagamento)
)
agregar
# we can use ungroup() to return to original values
# ungroup()
# getting profile by age of each customer to see how risk they are
data_atual <- as.Date(Sys.Date())
data_atual
attach(Banco)
Banco$data_atual <- c(data_atual)
Banco
idade <- difftime(data_atual, datanasc) / 365.25
idade <- round(idade, digits = 0)
Banco$idade <- idade
View(Banco)
idade <- as.numeric(idade)
is.numeric(idade)
faixa_etaria <- cut(idade, breaks= c(46, 55, 61, 70, 89), right = T)
faixa_etaria
Banco$faixa_etaria <- faixa_etaria
attach(Banco_1)
mean(Banco_1$filhos, na.rm = TRUE)
round(mean(Banco_1$filhos, na.rm = TRUE))
by(Banco_1$idade, Banco_1$filhos, mean)
table(Banco_1$sexo)
library(gmodels)
CrossTable(
Banco_1$sexo,
Banco_1$Situacao,
digits=3,
expected = FALSE,
prop.r = TRUE,
prop.c = TRUE,
prop.t = TRUE,
asresid = FALSE
)
barplot(prop.table(table(Banco_1$sexo)) * 100, col=c('pink', 'blue'))
library(ggplot2)
attach(Bank)
dispersao <- ggplot(Bank, aes(x=age, y=salbeg, color=sex))
dispersao + geom_point()
dispersao <- ggplot(Bank, aes(x=age, y=salbeg))
dispersao + geom_point() + facet_wrap(~sex)
boxplot(
Banco_1$idade ~Banco_1$sexo,
main='boxplot por idade e sexo',
xlab = 'sexo', ylab='idade',
col=c('blue', 'red')
)
# lista 2
#1
barplot(prop.table(table(Bank$sex)) * 100, col=c('pink', 'blue'))
barplot(prop.table(table(Bank$jobcat)) * 100)
barplot(prop.table(table(Bank$sexrace)) * 100, col=c('pink', 'blue', 'green', 'yellow'))
table(Bank$sex)
table(Bank$jobcat)
table(Bank$sexrace)
#2
boxplot(
Bank$salnow ~Bank$sex,
main='boxplot por sex e salnow',
xlab = 'sex', ylab='salnow',
col=c('blue', 'red')
)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment