I am trying to write a function in R that takes two arguments, x and n, and returns h(x, n); x=1
Does anyone know how to do this using a for loop?
The function I am working with is:
x^0 + x^1 + x^2…x^n
I have been working for a while on this and am not sure if I am doing this correctly.
Can anyone give me some guidance on how to do this problem.
Here is what I have..
n = seq(1,6, by = 1)
x = 1
h = function (x,n){
for (i in 0:n){
for( i in 1:n){
sum = sum +x^i
{
}}
applyand friends (sapply,lapplyetc.).<-instead of=in assignments. It pays off in the long run.seq()where a simplek:nwill do.