Re: [R] Basic Vector and Matrix Operations

2008-07-07 Thread jim holtman
For the first case, just extend the vector: > x<-c(3,4,5) > x [1] 3 4 5 > x[5] <- NA > x [1] 3 4 5 NA NA > the second would use 'which' On Mon, Jul 7, 2008 at 5:07 PM, Eric Turkheimer <[EMAIL PROTECTED]> wrote: > I am wondering if it is possible to perform the following two basic > functions

Re: [R] Basic Vector and Matrix Operations

2008-07-07 Thread Erik Iverson
Eric Turkheimer wrote: I am wondering if it is possible to perform the following two basic functions with primitive R functions. I know I could write functions for either, but it seems as though they are probably built-in somewhere. 1) Fill out a vector to a desired length with missing value

Re: [R] Basic Vector and Matrix Operations

2008-07-07 Thread Jorge Ivan Velez
Dear Eric, Try this: # First function f1=function(x,k) c(x,rep(NA,k-length(x))) x<-c(3,4,5) f1(x,5) # Second function f2=function(x,val){ res=which(x==val,arr.ind=T) paste(res,collapse=',',sep='') } x<-matrix(1:9,ncol=3) f2(x,2) HTH, Jorge On Mon, Jul 7, 2008 at 5:07 PM, Eric Turkheimer

Re: [R] Basic Vector and Matrix Operations

2008-07-07 Thread apjaworski
Here is a solution: 1. c(x, rep(NA, n-length(x))) 2. which(x==2, arr.ind=TRUE) Cheers Andy __ Andy Jaworski 518-1-01 Process Laboratory 3M Corporate Research Laboratory - E-mail: [EMAIL PROTECTED] Tel: (651) 733-6092 Fax: (651) 736-3122 "Eric Turkheimer"

Re: [R] Basic Vector and Matrix Operations

2008-07-07 Thread Xiaohui Chen
Eric Turkheimer 写道: I am wondering if it is possible to perform the following two basic functions with primitive R functions. I know I could write functions for either, but it seems as though they are probably built-in somewhere. 1) Fill out a vector to a desired length with missing values or