I have to create a function that takes a numeric vector as an argument, and returns its cumulative sum as a vector of equal length.
I've been trying to figure this out for over 5 hours now, but I just can't do it for the life of me. Please note that I'm new to R. Please help me.
My attempt so far, with no success:
y <- function(x) {
for (i in x) {
print(sum(x[1]:x[i]):sum(x[1]:x[i]))
}
}
also tried
y <- function(x) {
for (i in x) {
print(x[1]:sum(x[1]:x[i]))
}
}