
Hi all,

 

I'm trying to write a script that changes all negative values in a data frame column to a small positive value, based on the the minimum value of the column.

However, I get the following error:

 

Error in if (x[i] < 0) { : argument is of length zero

 

 

As well, I would "minimum" to be the smallest of the non-negative values...

 

 

Aa_non_neg=(fieldTrial0809$Aa) # Copy column from data frame to manipulate

 

nonNegative = function(x)
{
   minimum=min(x) # Should only use positive minimum!
   for (i in x)
   {

      if(x[i]<0) # Found a negative value
      {
         x[i]=minimum/10 # Change to a new non-negative value
      }
   }
}

 

nonNegative(Aa_non_neg) # Apply function on column
 		 	   		  
_________________________________________________________________
Lagra alla dina foton på Skydrive. Det är enkelt och säkert!
http://www.skydrive.live.com
	[[alternative HTML version deleted]]


