a<-10
teste <- TRUE
if (a>0) {
  teste = ("maior que zero")
} else {
  teste = ("menor que zero")
}

teste

while(a < 20) {
  a = a + 1
  print(a)
}

ar = c(1,2,3,4,5,6)
a
for (a in ar) {
  print(ar[a])
}



library(ggplot2)
library(plyr)

carros <- rename(mpg, c("displ" = "Cilindradas",
                        "cty" = "Consumo",
                        "drv" = "Tração",
                        "class" = "Tipo"))


ggplot(carros, aes(Cilindradas, Consumo))
ggplot(carros, aes(Cilindradas, Consumo)) +
  geom_point()


#numeros de 1 a 100
nus <- 1:100
for (a in nus) {
  print(a)
}

#verificando o tamanho do vetor



nus[2] #retornando vetor pela posição
length(nus) #tamanho do vetor
mean(nus) #media
min(nus) #minimo
max(nus) #maximo
sum(nus) #soma todos os elementos


# algumas funcoes vetorizadas não permitem NA valores padrão, neste
# casos, um argumento de palavra-chave extra deve ser fornecido
# junto com o primeiro argumento da função:
v2 = c(1, 2, 3,4, 5 , NA, 7, NA, 9, NA, 11)
mean(v2)
#removendo as NA
mean(v2, na.rm=TRUE)
sum(v2, na.rm=TRUE)
#erro na
sum(v2, na.rm=FALSE)

#construindo vetores a partir de valores logicos
tf <- c(TRUE, FALSE, FALSE, TRUE)
tf

# valores lógicos podem ser forçados a se comportar como numericos
sum(tf) # obtendo contagem de "TRUEs"

tf2 <- c(TRUE, FALSE, NA, NA, FALSE, TRUE, TRUE, FALSE, NA, NA, FALSE, TRUE)
tf2
is.na(tf2) #removendo NAs
sum(is.na(tf2)) #contando NAs

# Quando você usa operadores booleanos em vetores, eles também 
# retornam vetores lógicos do mesmo comprimento que o vetor que
# está sendo operado
tf2 > 5

telefone <- c(9,8,9,5,9,2,2,3,1)
sum(telefone>5) #contando elementos do vetor telefone maiores que 5

telefone_com_nas <- c(9,8,NA,5,9,NA,2,3,1)
telefone_com_nas[!is.na(telefone_com_nas)]

#substituindo NAs por 0
telefone_com_nas[is.na(telefone_com_nas)] <- 0
telefone_com_nas

#normalmente não alteramos o vetor e sim copiamos para um novo
# diferente do exemplo anterior ele imprime os valores modificados
# 0 no lugar de Na, mas mantem o vetor original
telefone_com_nas <- c(9,8,NA,5,9,NA,2,3,1)
ifelse(is.na(telefone_com_nas), 0, telefone_com_nas)
telefone_com_nas

#é possivel reciclar os vetores
ex <- c(0,1,2,3)
ex + 2 # soma 2 a todos os elementos do vetor
ex
ex + c(2,1,0,-1)

#digitos do telefone
telefone[c(TRUE, FALSE)]
# Isso funciona porque o vetor c(TRUE, FALSE)
# é repetido até que tenha o comprimento 7


#CRIANDO FUNCOES
function.name <- function(argument1, argument2, ...){
  #instrucoes
}

is.par <- function(a.number){ 
     resto <- a.number %% 2 
     if(resto==0) 
       return(TRUE) 
     return(FALSE) 
} 

is.par(10)
is.par(5)


eh.divisivel.por <- function(large.number, smaller.number){ 
     if(large.number %% smaller.number != 0) 
         return(FALSE) 
     return(TRUE) 
} 

eh.divisivel.por(4,2)
eh.divisivel.por(5,2)


eh.mesmo <- function(num){ 
  eh.divisivel.por(num, 2) 
} 
eh.mesmo(2)

#sapply()recebe um vetor e uma função como seus argumentos
#verificando se cada numero no vetor é divisivel por 0
sapply(telefone, eh.mesmo)

# outra opcao, aplicar uma funcao sobre o vetor
# chamada de função anônima ou lambda
sapply(telefone, function(num){eh.divisivel.por(num, 3)}) 


where.even <- sapply(telefone, eh.mesmo) 
where.div.3 <- sapply(telefone, function(num){ 
   eh.divisivel.por(num, 3)}) 
# "&" is like the "&&" and operator but for vectors  
 telefone[where.even & where.div.3] 

 
 # matriz, entende-se como tabelas
 # uma coluna
 matrix1 = matrix(c(1,2,3,4,5,6))
matrix1 

#duas colunas
matrix2 <- matrix(c(1, 2, 3, 4, 5, 6), ncol=2)
matrix2

# A mesma matriz, criada ligando 2 vetores
matrix2.2 <- cbind(c(1, 2, 3), c(4, 5, 6))  
matrix2.2

#transposição da matriz
# (linha e colunas são trocados)
matrix3  <-rbind(c(1,2,3), c(4,5,6))
matrix3

# outra forma: "t", funcao de transposicao do R
t(matrix2.2)



#Algumas outras funções que operam em vetores inteiros 
#são rowSums()/ colSums()e rowMeans()/ colMeans():

matrix2.2

#soma nas colunas
colSums(matrix2.2)

#média das linhas
rowMeans(matrix2.2) 

#Se vetorestêm sapply(), então as matrizes têm apply().
#As duas funções anteriores poderiam ter sido escritas,
# de forma mais detalhada, da seguinte forma:
apply(matrix2.2, 2, sum) #soma nas colunas
apply(matrix2.2, 1, mean) #média das linhas
apply(matrix2.2, 2, mean) #média das colunas

matrix2.2
matrix3
matrix2.2 %*% matrix3
Este artigo foi útil ?
SimNão

7 Replies to “Base Analise de Dados em R”

  1. 88betag disse:

    I have to say, I really enjoy playing on 88betag. Very professional, easy to use, and the games are very fun! Check them out at: 88betag

  2. kkkjili29 disse:

    Anyone else playing on kkkjili29? Been a month and some good wins are coming through. Just putting that out there, you know. Good luck to y’all!

  3. superphlogin disse:

    That’s a fascinating point about skill progression in shooters! It reminds me of resources like 319SuperPH Login, which breaks down complex mechanics into manageable steps. Building that foundation is key to really improving, isn’t it? It’s cool to see educational approaches applied to gaming!

  4. bancaxeng disse:

    Bancaxeng, hey! I’ve checked it out, pretty solid. Gameplay is smooth, and I had some decent luck. Definitely worth a look if you’re trying your hand at something new. Check it out here: bancaxeng

  5. 5557betcasino disse:

    Checked out 5557betcasino. Decent selection of slots and table games. The payouts seem fair enough. Give it a shot if you’re into online casinos: 5557betcasino

  6. Been watching the sabong action on dagavietlivesv388.com lately! The stream quality is top-notch, and it’s really easy to place bets. If you’re into live cockfights, this is your go-to! You can watch here dagavietlivesv388

  7. fortunemouse4 disse:

    Just stumbled upon fortunemouse4 and gotta say, I’m impressed. The site is slick and easy to navigate. Looking forward to seeing what else they have to offer! Check it out fortunemouse4, you might just get lucky.

Deixe um comentário para 5557betcasino Cancelar resposta

O seu endereço de e-mail não será publicado. Campos obrigatórios são marcados com *

Close Search Window