[R] condition apply to elements of a data frame column

2010-05-26 Thread arnaud Gaboury
Oops, forgot to give a subject -Original Message- From: arnaud Gaboury [mailto:arnaud.gabo...@gmail.com] Sent: Wednesday, May 26, 2010 2:31 PM To: r-help@r-project.org Cc: 'arnaud Gaboury' Subject: Dear group, Here is my data frame: dput(u) structure(list(DESCRIPTION =

Re: [R] condition apply to elements of a data frame column

2010-05-26 Thread Joris Meys
Arnaud, check the vector : u$POSITION0 [1] TRUE TRUE ... what I do is putting u$POSITION==0 [1] FALSE FALSE ... when you apply the sum() function on that vector, FALSE becomes 0 and TRUE becomes 1. So this actually gives you a way of counting the amount of positions that are not zero. if you

Re: [R] condition apply to elements of a data frame column

2010-05-26 Thread arnaud Gaboury
Joris, I want to add a line in a function with a print warning if one element of the column is 0. I could use if(sum(u$POSITION)0) as a condition, but I can imagine having one element equal to -2, and another one to 2. So in this case, sum=0, but the condition is false in fact (minimum of one