Our first step is to turn the negative values from her data into zeros. The negative values are there because she has subtracted backgrounds.
As ever, StackOverflow is our friend. I found this link:
http://stackoverflow.com/questions/11275187/r-replacing-negative-values-by-zero
Steps we followed:
- Convert the column of our data frame into a vector
- Go through the vector, find the values less than zero and make them zero
- Convert our vector back to a data frame.
- Bind our data frames together.
Here is the code:
> mUr.zero <- (dataframe$col) #makes the vector
> mUr.zero[mUr.zero <0] <- 0 # loops through the vector, finds values less than zero and replaces them with zero.
> mUr.zero <- as.data.frame(mUr.zero) # converts into a data frame
> newdataframe <- cbind(dataframe, mUr.zero) # binds this into the data frame
Happy days - this seems to work :-)
No comments:
Post a Comment