Consider the following toy data frame of my seed study:
site <- c(LETTERS[1:12])
site1 <- rep(site,each=80)
fate <- c('germinated', 'viable', 'dead')
fate1 <- rep(fate,each=320)
number <- c(41:1000)
df <- data.frame(site1,fate1,number)
> str(df)
'data.frame': 960 obs. of 3 variables:
$ site1 : Factor w/ 12 levels "A","B","C","D",..: 1 1 1 1 1 1 1 1 1 1 ...
$ fate1 : Factor w/ 3 levels "dead","germinated",..: 2 2 2 2 2 2 2 2 2 2 ...
$ number: int 41 42 43 44 45 46 47 48 49 50 ...
I want R to go through all observations which are "dead" and assign "0" to every single one of them. Similarly, I want to assign "1" to all "viable" observations and "2" to all "germinated" observations.
My final data frame would be a single column, somewhat like this:
> year16
[1] 0 1 2 0 1 2 0 1 2 0 1 2 0 1 2 0 1 2 0 1 2 0 1 2 0 1 2 0 1 2 0 1 2 0 1 2 0
[38] 1 2 0 1 2 0 1 2 0 1 2 0 1 2 0 1 2 0 1 2 0 1 2 0 1 2 0 1 2 0 1 2 0 1 2 0 1
All suggestions are highly welcome