> I need to write a R function to compute density function...1/2 - (1-|
> x |) for | x | <= 1 ...and then plot it.
The way that I read that expression it wouldn't be a density function.
At x == 0 it would have the value -1/2, wouldn't it?
As for creating a plot you could use the curve() function
curve(0.5 - (1-abs(x)), from = -1, to = 1)