-
-
Save qodatecnologia/b4e61d489e348d86d68093f4f0961cd0 to your computer and use it in GitHub Desktop.
R em 1 hora
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# arquivos .csv | |
dados = read.csv(file.choose(), sep=";") | |
# arquivos .xlsx | |
install.packages("xlsx") | |
library(xlsx) | |
planilha = read.xlsx(file.choose()) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#if/else | |
a = 1 | |
b = 2 | |
if (a>0) | |
{ | |
print("A maior que 0") | |
} | |
else | |
{ | |
print("A menor que 0") | |
} | |
#ifelse | |
ifelse(a>0,"A maior que 0","A menor que 0") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
n = 50 | |
x = 1:n | |
y = 2 * x | |
plot(x, y) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#VETOR (todos elementos serão do mesmo tipo) | |
vec = 3 | |
is.vector(vec) #Retorna TRUE | |
#Para adicionar diversos elementos em 1 vetor, use c() | |
vec = c(1,2,3,"texto") | |
class(vec) #retorna character pois todos elementos serão do mesmo tipo | |
#LISTA (elementos de tipos diferentes) | |
x = c("texto1","texto2") | |
y = c(1,2,3) | |
z = c(T,F,T) | |
lista = c(x,y,z) | |
#MATRIZ (todos elementos serão do mesmo tipo) | |
mat = matrix(c(1,2),nrow=1,ncol=2,byrow = TRUE) | |
#nrow se refere ao número de colunas e ncol se refere ao número de linhas | |
#byrow insere os elementos dentro de linhas quando TRUE ou em colunas, quando FALSE | |
#DataFrame (estrutura para armazenar em forma de tabela) | |
x = data.frame(c("altura","largura","comprimento"),c("1.8","80","35")) | |
nrow(x) #retorna número de linhas do dataframe | |
ncol(x) #retorna número de colunas do dataframe | |
dim(x) #retorna número de linhas e colunas |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# FUNÇÕES R BASE | |
x = c(1,2,3,4,5,6,7,8,9,10) | |
sd(x) #desvio padrão | |
mean(x) #média | |
head(iris) #primeiras linhas dataframe | |
tail(iris) #ultimas linhas dataframe | |
file.choose() #abre pasta para caminho de arquivos | |
# CRIAÇÃO DE FUNÇÕES | |
raizquadrada = function(x) { | |
return(x*x) | |
} | |
raizquadrada(4) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Você pode declarar variáveis utilizando "=" ou "<-" | |
x = "Hello Qoda!" | |
y <- "Hello Qoda!" | |
# Print na tela seu primeiro programa em R! | |
print(x) | |
print(y) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
hist(rnorm(100)) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#FOR | |
for (i in -10:0) { | |
print(i) | |
} | |
#WHILE | |
x = 10 | |
while(x<10){ | |
print(x) | |
x = x+1 | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
a = 10L | |
b = 30.5 | |
(a+b)*2 | |
a == b | |
a > b | |
a != b | |
# Funções matemáticas R base | |
sqrt(9) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# CRAN | |
install.packages("ggplot2") #instala pacote | |
library("ggplot2") #carrega pacote para seu código | |
# GITHUB | |
devtools::install_github("nome-do-repo/nome-do-pacote") | |
# .ZIP, .TAR.GZ | |
install.packages(file.choose()) #abre pasta para escolha do arquivo a ser instalado |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
inteiro = 15L | |
class(inteiro) | |
num = 15 | |
class(num) | |
caract = "Texto" | |
class(caract) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment