From: Narcyz Ghinea <Narcyz.Ghinea_at_swsahs.nsw.gov.au>

Date: Wed 19 Oct 2005 - 14:55:18 EST

R-help@stat.math.ethz.ch mailing list

https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html Received on Wed Oct 19 15:13:25 2005

Date: Wed 19 Oct 2005 - 14:55:18 EST

Dear R Users,

Any insights into why the following occurs would be helpful....

Firstly:

#Evaluating proportions

p<-as.list(rep(0,times=length(n))) #creating object of appropriate size.
for(j in 1:length(n)){

for(k in 1:length(n[[j]])){

p[[j]][[k]]<- (s[[j]][[k]]/n[[j]][k])}} # 31 x k x num_samples(dim)
where k varies

The list object s[[j]][[k]] has 3 levels, j, k, and i. j represents the review number, k the study number in that review, and i is the number of simulations in that study. n[[j]][k] is also a list object with 2 levels that represents the number of patients in study k of review j.

When I run this the following error message occurs:

Error: more elements supplied than there are to replace.

However, if I make the simple adjustment p[[j]][[k]]<- list(s[[j]][[k]]/n[[j]][k]) it works fine! If anyone knows why please let me know. I couldn't get the answer from reading the "list" help.

Secondly:

#Evaluating weights.

w<-as.list(rep(0,times=length(n))) #creating object of appropriate size.

for(j in 1:length(n)){ for(k in 1:length(n[[j]])){ w[[j]][[k]]<- (1/(p[[j]][[k]]*n[[j]][k]*(1-p[[j]][[k]])))}} # 31 x k xnum_samples(dim) where k varies

When I run this section of the code, if gives the same error message as the previous one. When I try to solve it using the "list" function again, instead it gives a different error message:

Error in p[[j]][[k]] * n[[j]][k] : non-numeric argument to binary operator

The error message is straightforward but what I can't understand is why an error trying to calculate p[[j]][[k]]*n[[j]][k] in the second case, but no such problem evaluating s[[j]][[k]]/n[[j]][k] in the first case, even though they are objects of the same type and sizes?

How can I get rid of the second error? I have tried converting the p[[j]][[k]] vector into the numeric type but it won't allow it.

This message is intended for the addressee named and may con...{{dropped}}

R-help@stat.math.ethz.ch mailing list

https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html Received on Wed Oct 19 15:13:25 2005

*
This archive was generated by hypermail 2.1.8
: Fri 03 Mar 2006 - 03:40:46 EST
*