Dear all,
I would like to create a number of vectors which contain the the first n
elements of an existing vector.
For example I have the vectors vnk (200x1) and vro(200x1) and I want to
create 200 vectors that contain the 1st till the n_th element of the vectors
and thus be able to create a vector s with 200 elements which are the
product of all these vectors:
i.e s1<-vnk[1]%*%vro[1] +p^(length(vp[1]+1))
s2<-vnk[1:2]%*%vro[1:2]+p^(length(vp[1:2]+1))
s3<-vnk[1:3]%*%vro[1:3]+p^(length(vp[1:3]+1))
...............................
...............................
s200<-vnk[1:200]%*%vro[1:200]+p^(length(vp[1:200]+1))
s<-[s1 s2 ......s200]
In the code I created I can calculate only the 200th element
vnk<-t(nk^(200:0))
vro<-ro^(0:200)
s<-nz*e*(vnk%*%vp)+p^(length(vp))
if lapply wouldn't need functions but vector arguments it would do the job
perfectly but I don't know the respective command for vectors. If you know
please tell me.
Any help would be highly appreciated
Thanks a lot
Dimitris
--
View this message in context:
http://n4.nabble.com/Create-vectors-from-a-vector-tp1592334p1592334.html
Sent from the R help mailing list archive at Nabble.com.
On Mar 14, 2010, at 8:11 AM, Dimitris Kapetanakis wrote:> > Dear all, > > I would like to create a number of vectors which contain the the > first n > elements of an existing vector. > For example I have the vectors vnk (200x1) and vro(200x1) and I want > to > create 200 vectors that contain the 1st till the n_th element of the > vectors > and thus be able to create a vector s with 200 elements which are the > product of all these vectors: > > i.e s1<-vnk[1]%*%vro[1] +p^(length(vp[1]+1)) > s2<-vnk[1:2]%*%vro[1:2]+p^(length(vp[1:2]+1)) > s3<-vnk[1:3]%*%vro[1:3]+p^(length(vp[1:3]+1)) > ............................... > ............................... > s200<-vnk[1:200]%*%vro[1:200]+p^(length(vp[1:200]+1)) > > s<-[s1 s2 ......s200] > > In the code I created I can calculate only the 200th element > > vnk<-t(nk^(200:0)) > vro<-ro^(0:200) > > s<-nz*e*(vnk%*%vp)+p^(length(vp))Here is a guess, untested because you provided no sample data objects: s <- sapply(1:200, function (x) { vnk[1:x]%*%vro[1:x] + p^(length(vp[1:x]+1)) } )> > if lapply wouldn't need functions but vector arguments it would do > the job > perfectly but I don't know the respective command for vectors. If > you know > please tell me. > > Any help would be highly appreciated > > Thanks a lot > > Dimitris > >David Winsemius, MD West Hartford, CT
Thanks a lot. It is exactly what I was looking for. I found though and
another way (worse) to do it, so I just post in case someone find it useful
sk<-nz*e*(vnk[c(i:0)]%*%vro[c(0:i)])
for(i in 0:200){
sk[i]<-nz*e*(vnk[c(i:0)]%*%vro[c(0:i)])
}
--
View this message in context:
http://n4.nabble.com/Create-vectors-from-a-vector-tp1592334p1592793.html
Sent from the R help mailing list archive at Nabble.com.
Apparently Analagous Threads
- Identifying last record in individual growth data over different time intervalls
- bug: sample( x, size, replace = TRUE, prob= skewed.probs) produces uniform sample
- documentation for 'open': some clarification?
- Gluster communication via TLS client problem
- test