Hello, new here.
I am trying to gather data from multiple dataframe.
My dataframe called "a3" is empty, and wants to copy every variable listed from the "a2" dataframe.
Next, I want to create a new variable called "fruits" in "a3" , which is the sum of 3 variables called apple, orange, and mango, into a variable called "fruits" based on dataframe "a".
The problem is that when I do this, it takes every variable listed in dataframe "a" and overrides the variables copied from "a2".
The only thing I wanted was dataframe from "a2" and the new variable based off of "a"
How should I approach this/what am I doing wrong? My attempt is below.
library(dplyr)
a <- data.frame(apple = sample(c(1), 50, rep=T), mango = sample(c(2), 50, rep=T), orange = sample(c(3), 50, rep=T))
a2 <- data.frame(shoes = sample(c("Male"), 50, rep=T), shirts = sample(c("Female"), 50, rep=T))
a3 <- a2
a3 <- a %>% rowwise() %>% mutate(fruits = sum(apple, orange, mango, na.rm = "TRUE"))