I agree a reprex would be helpful.
What is happening here is you are trying to pass f() a vector of length > 1. if() and else can only react to one logical element (i.e., a TRUE or a FALSE) at a time. You should either use sapply(t, f), or use ifelse(). ifelse() can respond to a logical vector with length greater than one. First, you should make sure you are intending to pass f() a vector of length > 1. If you are, then write your function using ifelse():
f <- function(t) {
ifelse(t < 0, 0, (2*t)/((1+t^2)^2)
}
This should work if you run f(t) where t is a numeric vector. The syntax is:
ifelse(condition, do_if_true, do_if_false)
See the section in a book I recently wrote using bookdown on this topic. Hope this helps!