Untitled

mail@pastecode.io avatar
unknown
plain_text
15 days ago
1.4 kB
6
Indexable
Never
library(dplyr)
library(sqldf)

actors_got <- read.csv("actors-got.csv")
class(actors_got)
dim(actors_got)       # Devuelve las dimensiones del dataframe (filas columnas)

actors_got
print(actors_got)     # Imprime la variable
head(actors_got, 3)   # Devuelve las primeras tres filas
tail(actors_got, 5)   # Devuelve las últimas cinco filas
names(actors_got)     # Devuelve los nombres de las columnas

actors_got[5, 4]

# COLUMNAS
# =========================
# select Devuelve un data.frame
# pull Devuelve un vector

select(actors_got, Name, Height)
select(actors_got, Height, Name)
select(actors_got, -Genre)

actors_got %>% 
  select(Name, Height)

actors_got %>% 
  select(Height, Name)

actors_got %>% 
  select(-Genre)

actors_got %>% 
  select(Weight) %>% 
  class() # siempre devuelve data.frames!

mean(select(actors_got, Weight)) # siempre devuelve data.frames!

actors_got %>% 
  pull(Weight) %>% 
  class()

actors_got %>% 
  pull(Weight) %>% 
  mean()

mean(pull(actors_got, Weight))

class(actors_got$Character)

# FILAS
# =========================
# filter

filter(actors_got, Genre == "F")
filter(actors_got, Weight > 120)

actors_got %>% 
  filter(Genre == "F")

actors_got %>% 
  filter(Genre == "M", Weight < 150)

actors_got %>% 
  filter(Height > 70) %>% 
  select(Name, Character)

select(filter(actors_got, Height > 70), Name, Character)


sqldf("SELECT Name, Character FROM actors_got WHERE Height > 70")

Leave a Comment