Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- genre_vector <- c("Comedy","Comedy","Animation","Animation","Crime")
- fgenre_vector <- factor(genre_vector)
- fgenre_vector
- summary(genre_vector)
- summary(fgenre_vector)
- movielength_vector <- c("Very short","Short","Medium","Short","Long","Very short","Very Long")
- movielength_vector
- mvlength_factor <- factor(movielength_vector,
- ordered = TRUE,
- levels =c("Very short","Short","Medium","Long","Very Long"))
- mvlength_factor
- year <- c(1985,1999,2010,2002)
- names(year) <- c("The Breakfast Club","American Beauty","Black Swan", "Chicago")
- names(year)
- year["Black Swan"]
- length(year)
- year_sorted <- sort(year)
- year_sorted
- min(year)
- max(year)
- mean(year)
- cost_2014 <- c(8.6,8.5,8.1)
- sum(cost_2014)/3
- mean(cost_2014)
- summary(cost_2014)
- cost_2014[2]
- cost_2014[c(2,3)]
- cost_2014[1:3]
- titles <- c("Black Swan","Casino","City of God","Jumanji","Toy Story")
- titles[-1]
- titles[8]
- cost_2014 > 8.3
- cost_2014[cost_2014 > 8.3]
- age_restric <- c(14,12,10,NA,18,NA)
- age_restric[is.na(age_restric)==FALSE]
- age_restric
- age_restriction <- c(14,16,12,10,18,18)
- sequences <- c(2,3,0,2,6,3)
- multiply <- age_restriction * sequences
- multiply
- cost_2014 * 10
- cost_2014
- movie_vector <- c("Akira","Toy Story","Room","The Wave","Whiplash","Star Wars","The Ring","The Artist","Jumanji")
- movie_vector
- movie_array <- array(movie_vector,dim = c(4,3))
- movie_array
- movie_array[1,2]
- movie_array[1,]
- movie_array[,2]
- movie_matrix <- matrix(movie_vector,nrow = 3,ncol = 3, byrow = TRUE)
- movie_matrix
- hola <- matrix(movie_matrix[2:3,1:2],nrow = 2,ncol = 2)
- hola
- movie <- list("Toy Story",1995,c("Animation","Adventure","Comedy"))
- movie
- movie[2]
- movie[2:3]
- movie <- list(name="Toy Story",year=1995,genre = c("Animation","Adventure","Comedy"))
- movie$name
- movie$year
- movie$genre[1]
- movie["age"] <- 5
- movie$name
- movie$year
- movie$genre
- movie$age <- 7
- movie["age"] <- NULL
- movie
- movieDF <- data.frame(name = c("Toy Story","Akira","The Breakfast Club","The Artist","Modern Times","Fight Club","City of God","The Untouchables")
- ,year = c(1995,1998,1985,2011,1936,1999,2002,1987))
- movieDF$name
- movieDF[1]
- movieDF[1,2]
- str(movieDF)
- movieDF
- head(movieDF)
- tail(movieDF)
- movieDF["length"] = c(81,125,97,100,87,139,130,119)
- movieDFx <- data.frame(name="Dr Strange",year=1964,length=94)
- movieDF <- rbind(movieDF,movieDFx)
- movieDF["length"] <- NULL
- movieDF <- movieDF[-c(9),]
- movieDF <- movieDF[-9,] #Elimina filas
- movie_year <- 2002
- if( movie_year >2000){print('Película mayor del año 2000')}
- movie_year <- 1997
- if(movie_year >2000){
- print('Película mayor del año 2000')
- }else{
- print('Película menor del año 2000')
- }
- 1995<1987
- "Toy Story"=="Toy Story"
- 2016 > 2015
- "Toy Story" != "Interstellar"
- "Toy Story"=="Toy Story" & 1995<1987
- "Toy Story"=="Toy Story" | 1995<1987
- !("Toy Story"=="Toy Story" & 1995<1987)
- for (yr in year) {print(yr)}
- for (yr in year){
- if(yr < 2000) {
- print("Es una película vieja")
- }else{
- print("No es tan vieja")
- }
- }
- count <- 1
- while(count<=5){
- print(c("Número de iteración: ",count))
- count <- count+1
- }
- ratings <- c(8.7,6.9,8.5)
- mean(ratings)
- sort(ratings)
- sort(ratings,decreasing = TRUE)
- printHelloWorld <- function(a="Hello World!") {print(a)}
- printHelloWorld("Hola Mundo")
- add <- function(x=3,y=4) {x+y}
- add(6,4)
- isGoodRating <- function(rating){
- if(rating<7){
- return("No")
- }else{
- return("Si")
- }
- }
- isGoodRating(ratings[2])
- isGoodRating <- function(rating,threshold=7){
- if(rating<threshold){
- return("No")
- }else{
- return("Si")
- }
- }
- isGoodRating(10,9)
- my_data = data.frame(name=c("Toy Story","Akira","The Breakfast Club","The Artist","Modern Times","Fight Club"),
- year=c(1995,1998,1985,2011,1936,1999),
- length_min=c(81,125,97,100,87,139),
- genre=c("Animation","Animation","Drama","Romance","Comedy","Drama"),
- average_rating = c(8.3,8.1,7.9,8,8.6,8.9),
- foreign=c(0,1,0,1,0,0),
- age_restriction=c(0,14,14,12,10,18))
- watchMovie <- function(moviename,my_threshold = 7){
- rating <- my_data[my_data$name == moviename, "average_rating"]
- isGoodRating(rating,threshold = my_threshold)
- }
- watchMovie("Akira")
- watchMovie("The Breakfast Club",8)
- myFunction <- function() {
- y <<- 3.14
- temp <- "Hello World!"
- return(temp)
- }
- myFunction()
- y
- temp
- x <- 5
- average_rating <- 8.3
- class(average_rating)
- movies <- c("Toy Story","Akira")
- class(movies)
- logical_vector <- c(TRUE,FALSE,FALSE,TRUE,TRUE)
- class(logical_vector)
- age_restriction <- c(12,10,18,18)
- class(age_restriction)
- integer_vector <- as.integer(age_restriction)
- class(integer_vector)
- yar <- as.character(1995)
- yar
- combined <- c("Toy Story",1995,"Akira",1998)
- class(combined)
- for(i in 1:3){print(i+"a")}
- tryCatch(10+10)
- tryCatch("a"+10)
- tryCatch(10+"a",error = function(e)
- print("Ups, algo va mal"))
- tryCatch(
- for (i in 1:3) {
- print(i+"a")
- },
- error=function(e) print(c("Error encontrado",e))
- )
- as.integer("A")
- tryCatch(as.integer("A"),
- warning=function(e) print(c("Aviso",e)))
- peliculas = read.csv("/home/vagrant/peliculas.csv")
- class(peliculas)
- install.packages("readxl")
- library(readxl)
- peliculas = read_excel("/home/vagrant/movies.xlsx")
- data()
- titanic = data.frame(Titanic)
- quijote <- readLines("/home/vagrant/el_quijote.txt")
- length(quijote)
- nchar(quijote)
- file.size("/home/vagrant/el_quijote.txt")
- quijote2 <- scan("/home/vagrant/el_quijote.txt", "")
- quijote2
- m <- matrix(c(1,2,3,4,5,6),nrow = 2,ncol = 3)
- write(m,file="matriz_como_texto",ncolumns = 3,sep=" ")
- install.packages("sparklyr")
- install.packages("dplyr")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement