s-news
[Top] [All Lists]

query on column vector manipulation

To: "splus" <s-news@lists.biostat.wustl.edu>
Subject: query on column vector manipulation
From: "motohasegawa" <2116242101@jcom.home.ne.jp>
Date: Thu, 22 Aug 2002 07:04:05 +0900
Dear S-PLUS users:
 
I want to make a script that calculates returns among variables in a column vector. Specifically, I need a script that calculates, ln(x[,i+1]/x[,i]) for all elements in a column vector x. Here, i denotes ith row. For this purpose, I wrote the following "script" but it does not work. It will be of great help if you could give me some advice, suggestion, correction.

calcLN <- function(x) {
 
 x1<-c(matrix(unlist(x),nrow=nrow(x)))
 x1<-log(numeric(x1))
 for(i in 1:nrow(x1)-1) {
  x1rtn[i]<-x1[i+1]-x1[i]
  i<-i+1
 }
 x1rtn
 
}
 
Regards,
 
Moto
<Prev in Thread] Current Thread [Next in Thread>