Hi,
I have a problem with my program in R.
I have "while" loop. From these loop i have vectors "a:k", where a and k are parametres / variables. I need these vectors in one matrix. However i tried, i have or one matrix from lats vector from loop or single matrixs from one vector.. I tried created matrix also in loop while also after while.
I have it :
f1=function (c)
{ l = length(c)
i=0
while (i<l)
{i=i+1}
for (e in 0:((l+1)/2))
{a=0
k=(((l-1)/2)-e)
while ((a<=(((l-1)/2)-e)) & (k<=(l-e)))
{a=a+1
k=k+1
print(c[a:k])
print("aaa")
}}
print (matrix(c[a:k]))}
I need to create few matrix"s from vectors which have these same length.
You've got an essential part right -- the vectors need to be of equal length. And, of course, a matrix can't mix characters and numeric the way a data frame can.
Loops have their place, but often a more direct approach is preferable.