Re: [R] some question about vector[-NULL]

2014-09-11 Thread Philippe GROSJEAN
Petr's suggestion to replace NULL by 0. I just wanted to indicate that it could produce unwanted results in several cases. Philippe >> >> Best, >> >> Philippe >> >> >> > Regards >> > Petr >> > >> > >> >>

Re: [R] some question about vector[-NULL]

2014-09-11 Thread Duncan Murdoch
roject.org] On Behalf Of PO SU >> Sent: Thursday, September 11, 2014 3:54 AM >> To: Duncan Murdoch >> Cc: R. Help >> Subject: Re: [R] some question about vector[-NULL] >> >> >> Tks, i think using logical index is a way, but to do that, i have to >> keep a v

Re: [R] some question about vector[-NULL]

2014-09-11 Thread Philippe GROSJEAN
org] On Behalf Of PO SU >> Sent: Thursday, September 11, 2014 3:54 AM >> To: Duncan Murdoch >> Cc: R. Help >> Subject: Re: [R] some question about vector[-NULL] >> >> >> Tks, i think using logical index is a way, but to do that, i have to >> keep a ve

Re: [R] some question about vector[-NULL]

2014-09-11 Thread Duncan Murdoch
On 11/09/2014, 6:04 AM, PO SU wrote: > > > Actually, i thought the way: > a<-1:3 > b<-NULL or 2 > a[-b] will not work if b is NULL > > A<-c(a,1) If a is a long vector, that is a very expensive operation, at least as expensive as constructing a logical vector of the same length as a. > B<-c(b

Re: [R] some question about vector[-NULL]

2014-09-11 Thread PO SU
Actually, i  thought  the way: a<-1:3 b<-NULL or 2 a[-b] will not work if b is NULL A<-c(a,1) B<-c(b,length(A)) A[-B] will get the same result as if b is NULL get a, if b is 2 get a[-2] I think it works well  in considering memory use or efficiency or code tidy. -- PO SU mail: desolato...@

Re: [R] some question about vector[-NULL]

2014-09-11 Thread PO SU
Orignally i don't want to do the if ( length) check because i know that in a 1 loops, after may be 10 or 20 or 100 loops , "i" will not be empty. so i mean , in the left loops, i would always check something not needed to check which i would not like to do.   -- PO SU mail: desolato...@1

Re: [R] some question about vector[-NULL]

2014-09-11 Thread Duncan Murdoch
On 10/09/2014, 9:53 PM, PO SU wrote: > > Tks, i think using logical index is a way, but to do that, i have to keep a > vector as long as the original vector. that's, to exclude position 1 and 3 > from > a<-1:5 > I have to let b<-c(F,T,F,T,T) and exec a[b], not a[-c(1,3)]. which c(1,3) is > muc

Re: [R] some question about vector[-NULL]

2014-09-11 Thread PIKAL Petr
behaviour would change almost any R code I am afraid that you need to reprogram it yourself. Regards Petr > -Original Message- > From: PO SU [mailto:rhelpmaill...@163.com] > Sent: Thursday, September 11, 2014 9:27 AM > To: PIKAL Petr > Cc: R. Help > Subject: Re

Re: [R] some question about vector[-NULL]

2014-09-11 Thread PO SU
t; > >> -Original Message- >> From: r-help-boun...@r-project.org [mailto:r-help-bounces@r- >> project.org] On Behalf Of PO SU >> Sent: Thursday, September 11, 2014 3:54 AM >> To: Duncan Murdoch >> Cc: R. Help >> Subject: Re: [R] some question

Re: [R] some question about vector[-NULL]

2014-09-10 Thread PIKAL Petr
roject.org] On Behalf Of PO SU > Sent: Thursday, September 11, 2014 3:54 AM > To: Duncan Murdoch > Cc: R. Help > Subject: Re: [R] some question about vector[-NULL] > > > Tks, i think using logical index is a way, but to do that, i have to > keep a vector as long as the ori

Re: [R] some question about vector[-NULL]

2014-09-10 Thread PO SU
Tks, i think using logical index is a way, but to do that, i have to keep a vector as long as the original vector. that's, to exclude position 1 and 3 from a<-1:5 I have to let b<-c(F,T,F,T,T) and exec a[b], not a[-c(1,3)]. which c(1,3) is much shorter than b if a is a long vector. that's, b wo

Re: [R] some question about vector[-NULL]

2014-09-10 Thread Duncan Murdoch
On 10/09/2014 12:20 PM, William Dunlap wrote: Can you make your example a bit more concrete? E.g., is your 'index vector' A an integer vector? If so, integer(0), an integer vector with no elements, would be a more reasonable return value than NULL, an object of class NULL with length 0, for the

Re: [R] some question about vector[-NULL]

2014-09-10 Thread William Dunlap
Can you make your example a bit more concrete? E.g., is your 'index vector' A an integer vector? If so, integer(0), an integer vector with no elements, would be a more reasonable return value than NULL, an object of class NULL with length 0, for the 'not found' case and you could check for that c

Re: [R] some question about vector[-NULL]

2014-09-10 Thread PO SU
May be i could add a extra elment to B,that's: F<-function( C ) { C<-C[-A] some processing... res<-NULL or some new index not included in A return(res) } so in a loop, C<-c(B,1) tmpindex<-length(C) A<-tmpindex for( i in 1:10) { D<-F(C) A<-c(A,D) } -- PO SU mail: desolato...@163.com M

Re: [R] some question about vector[-NULL]

2014-09-10 Thread PO SU
Tks for your  a <- list(ress = 1, res = NULL) And in my second question, let me explain it : Actually i have two vectors in global enviroment, called A and B .A is initialized to NULL which used to record some index in B. Then i would run a function F, and each time, i would get a index value o

Re: [R] some question about vector[-NULL]

2014-09-10 Thread Duncan Murdoch
On 10/09/2014, 3:21 AM, PO SU wrote: > > Dear expeRts, > I have some programming questions about NULL in R.There are listed as > follows: > 1. I find i can't let a list have a element NULL: > a<-list() > a$ress<-1 > a$res<-NULL > a > str(a) You can do it using a <- list(ress = 1, res = NU

Re: [R] some question about vector[-NULL]

2014-09-10 Thread PIKAL Petr
[unlist(lapply(a, function(x) !is.null(x)))] Regards Petr > -Original Message- > From: r-help-boun...@r-project.org [mailto:r-help-bounces@r- > project.org] On Behalf Of PO SU > Sent: Wednesday, September 10, 2014 9:21 AM > To: R. Help > Subject: [R] some question about

[R] some question about vector[-NULL]

2014-09-10 Thread PO SU
Dear expeRts,   I have some programming questions about NULL in R.There are listed as follows: 1. I find i can't let a list have a element NULL: a<-list() a$ress<-1 a$res<-NULL a str(a) How can i know i have a named element but it is NULL, not just get a$,a$,a$ there all get NUL