#joins in R
data(mtcars)
mtcars$Model=rownames(mtcars)
mtcars$Brand = sapply(strsplit(mtcars$Model," "),FUN='[',n=1)
mtcars$Model = NULL
hp_mean = aggregate(
mtcars$hp,
by=list(mtcars$Brand),
FUN=mean
)
car_brand = data.frame(
Brand =c('Mazda','Toyota','Fiat','Volvo','Tata'),
country=c('Japan','Japan','Itely','Sweden','India')
)
# to join or merge we use merge() function
merge(x=mtcars,y=car_brand,by="Brand",all.x = FALSE, all.y = TRUE)
#for inner join
#allx = FALSE, all.y = FALSE
#for left join
#allx = TRUE, all.y = FALSE
#for right join
#allx = FALSE, all.y = TRUE
#for outer join
#allx = TRUE, all.y = TRUE
To embed this project on your website, copy the following code and paste it into your website's HTML: