Skip to content

Instantly share code, notes, and snippets.

View DATAUNIRIO's full-sized avatar

DATAUNIRIO DATAUNIRIO

View GitHub Profile
diamond.query('carat > 3.5 and color=="J")
@DATAUNIRIO
DATAUNIRIO / Benchmarking_contribution_of_each_DMU.R
Created November 10, 2025 20:16
Benchmarking do DEA para o Juarez
# Install the Benchmarking package if you haven't already
# install.packages("Benchmarking")
# Load the library
library(Benchmarking)
# Sample data: inputs (x) and outputs (y) for a set of DMUs
# Example from the package documentation
x <- matrix(c(100, 200, 300, 500, 100, 200, 600), ncol = 1)
y <- matrix(c(75, 100, 300, 400, 25, 50, 400), ncol = 1)
@DATAUNIRIO
DATAUNIRIO / gist:b92482520319cc014fd2b94b0f81cabd
Created October 30, 2025 14:45
Razao de chances e teste de fisher
link = 'https://github.com/DATAUNIRIO/dados_para_aula/raw/refs/heads/main/csv/Titanic.csv'
link2 ='https://github.com/DATAUNIRIO/dados_para_aula/raw/refs/heads/main/csv/students.csv'
titanic = read.delim2(link,sep = ";")
estudantes = read.csv(link2)
table(estudantes$Sex,estudantes$Major)
library(forcats)
estudantes$Novo_Major = fct_lump(estudantes$Major, n = 3)
@DATAUNIRIO
DATAUNIRIO / como corrigir erro de encoding.R
Created October 30, 2025 14:08
como corrigir erro de encoding
iconv(Titanic$Classe, "latin1", "UTF-8")
library(stringi)
# Seu texto com problema
texto <- "Tripula\xe7\xe3o"
# Converter escapes Unicode para caracteres
texto_corrigido <- stri_unescape_unicode(gsub("\\\\x", "\\\\u00", texto))
# https://rfortherestofus.com/2024/01/speedometer
library(tidyverse)
library(ggplot2)
#Metas Alcançadas
#7.84% das metas estão alcançadas
percentage_done = 0.078
percentual_feito = scales::comma(percentage_done, accuracy = 0.001, big.mark = "." , decimal.mark = ",")
@DATAUNIRIO
DATAUNIRIO / dotplot_no_python.py
Last active September 12, 2025 17:48
Dotplot no Python
# Importando as bibliotecas do python
import pandas as pd
import numpy as np
import matplotlib.pyplot as plt
familias = pd.read_excel("https://github.com/DATAUNIRIO/dados_para_aula/raw/refs/heads/main/excel/Familias.xls")
familias.head()
def dotplot(input_x, **args):
snippet meu_save_no_excel_formatado
library(openxlsx)
#options("openxlsx.borderColour" = "#003747")
#options("openxlsx.borderStyle" = "thin")
#options("openxlsx.dateFormat" = "%d %b %Y")
estilo_cabecalho <- createStyle(fgFill="#003747",fontColour="#ffffff",halign="center", border = "TopBottomLeftRight",fontSize=16,textDecoration = "Bold")
wb <- createWorkbook()
modifyBaseFont(wb, fontSize = 13, fontName = "Arial Narrow")
# https://stats.oarc.ucla.edu/other/mult-pkg/faq/general/faq-how-do-i-interpret-odds-ratios-in-logistic-regression/
dados = matrix(c(74, 17, 77, 32), ncol = 2)
dados
dimnames(dados) <- list(voto = c("Normal","Menção Honrosa"),
sexo = c("Masculino","Feminino"))
dados
mosaicplot(dados, color = c("skyblue", "pink"), xlab ="Menção Honrosa",
ylab = "Sexo")
tibble::tibble()
tribunais <- forosCNJ::da_tribunal |>
dplyr::filter(id_justica == 8) |>
dplyr::pull(sigla) |>
tolower()
endpoints <- glue::glue(
"https://api-publica.datajud.cnj.jus.br/api_publica_{tribunais}/_search"
)
library(dplyr)
percentual <- CARROS %>%
pull(TipodeMarcha) %>%
table() %>%
prop.table()*100
percentual <- round(percentual,digits = 1)
rotulo <- paste0(percentual,"%")
#GRÁFICO DE BARRA
bp<- CARROS %>%
pull(TipodeMarcha) %>%