Skip to content
Prev 66190 / 398502 Next

simple problem, but not for me

alexbri at netcabo.pt wrote:

            
Well, if you've deadened your brain by using Excel,
	no wonder.
Oh, for Pete's sake!  This makes ``data'' (NOT a good name
	for an object!) into a data frame with a single column named
	``A''.  That column will be a factor with 5 entries (an 5
	levels) with these levels being (the character strings)
	"a1","a2","a3","a4", and "a5".
	
	Nothing to do with what you actually want.
This would make B a ***vector*** equal to the concatenation
	of b1, ..., b5.

	Perhaps you mean:

		B <- cbind(b1,b2,b3,b4,b5)
You are very confused.  Your notation and your use of
	the function c() are all wrong.

	If you are going to use R, get the basic syntax straight.

	You probably should be using matrices rather than data frames
	given that the entries are all numeric.

	Be that as it may, if A is a (numeric) matrix then

		B <- A/t(apply(A,1,function(x){rev(cumsum(x))}))

	will give what you appear to want.

				cheers,

					Rolf Turner
					rolf at math.unb.ca