[R] problems understanding sapply
John Sorkin
jsorkin at grecc.umaryland.edu
Wed Apr 11 03:19:57 CEST 2007
R 2.4.1
windows XP
I am trying to fill in a matrix with binomial probabilities without using a for loop. I am trying to obtain a value for pbinom using the value stored in column one of the matrix delete. Clearly I am doing something wrong. Please help me understand my error.
> delete<-matrix(nrow=31,ncol=2)
> delete[1:31,1]<-1:31
> delete[,2]<-sapply(delete[,2], pbinom,delete[,1],30,0)
Error in delete[, 2] <- sapply(delete[, 2], pbinom, delete[, 1], 30, 0) :
number of items to replace is not a multiple of replacement length
Thanks,
John
John Sorkin M.D., Ph.D.
Chief, Biostatistics and Informatics
Baltimore VA Medical Center GRECC,
University of Maryland School of Medicine Claude D. Pepper OAIC,
University of Maryland Clinical Nutrition Research Unit, and
Baltimore VA Center Stroke of Excellence
University of Maryland School of Medicine
Division of Gerontology
Baltimore VA Medical Center
10 North Greene Street
GRECC (BT/18/GR)
Baltimore, MD 21201-1524
(Phone) 410-605-7119
(Fax) 410-605-7913 (Please call phone number above prior to faxing)
jsorkin at grecc.umaryland.edu
Confidentiality Statement:
This email message, including any attachments, is for the so...{{dropped}}
More information about the R-help
mailing list