Hey @Naveed,
A bit of advice for getting the best help possible. If you tried something, which did not work, it is always a good idea to post your code as well as the errors that you got. This will allow everybody to guide you in the right direction 
Did you install the dplyr and purrr` packages? If you did not, then run:
install.packages(c("dplyr", "purrr"))
Also, on top of your script, you should have:
library(dplyr)
library(purrr)
So your script you look like this:
# Load useful packages
library(dplyr)
library(purrr)
# Import the data (instead of importing the data, I generate it)
my_data <- tibble(
x1 = c(1, NA, 4, NA, 2),
x2 = c(2, NA, NA, 8, 7),
x3 = c(3, 8, NA, 3, 7)
)
# Create the x column with the stated conditions
my_data %>%
mutate(
x = pmap_dbl(list(x1, x2, x3), function(...){
row_values <- unlist(list(...))
number_of_NAs <- sum(is.na(row_values))
map_dbl(number_of_NAs, ~ case_when(
.x == 0 ~ sum(row_values),
.x == 1 ~ mean(row_values, na.rm = TRUE) * 3,
TRUE ~ NA_real_
))
}))