Are you new to programming? In this situations, the if - else if - else is almost always the most obvious solution. Add the first case under if, and in case there are more, add those conditions one by one under else if. If all the cases are collectively exhaustive, you can use else in the final one, as there's only one possibility left.
See below:
f <- function(x)
{
if ((-1 < x) & (x <= 0))
{
return((12 / 7) * ((1 + x) ^ 2))
} else if ((0 < x) & (x < 1))
{
return((12 / 7) * ((1 + x) ^ 3))
} else
{
return(0)
}
}
x_vals <- seq(from = -2,
to = 2,
by = 0.01)
y_vals <- sapply(X = x_vals,
FUN = f)
plot(x = x_vals,
y = y_vals)

Created on 2019-04-01 by the reprex package (v0.2.1)
I didn't join the points, you can do that by specifying type="l". Hope this helps.
PS I'm changing the category of your post, as it doesn't relate to either R Markdown or latex. Hope you don't mind.
PPS You can write LaTeX equations within a pair of $$ in R markdown. Check my edit in the question.