Create one column indexed to another in R

Question:

Good evening !

I'm new to R and I have a database where I need to include a column, however the values ​​in this column need to be linked to the values ​​in another column.

In this case, I have the ano column (2006:2016) and I need to create the PIB column (with specific values ​​for each year).

The years don't follow the sequence, some jump.

I'm using dCoopCred$ano and dCoopCred$PIB .

Example:

ano     PIB
2006    4,0
2007    6,1
2008    5,1
2009    -0,1
2010    7,5
2011    4,0
2012    1,9
2013    3,0
2014    0,5
2015    -3,8
2016    -3,6

However, there are 10,000 lines, the years do not follow a sequence.

Sorry for anything, it's my first post here.

Grateful in advance.

Answer:

I decided through a for:

dCoopCred$PIB <- c(0) for(i in row(dCoopCred)){  
if(dCoopCred$ano[i]==2006){dCoopCred$PIB[i] <- c(4)     
} else if (dCoopCred$ano[i]==2007){dCoopCred$PIB[i] <- c(6.1)   
 }else if (dCoopCred$ano[i]==2008){dCoopCred$PIB[i] <- c(5.1)   
}else if (dCoopCred$ano[i]==2009){dCoopCred$PIB[i] <- c(-0.1)   
}else if (dCoopCred$ano[i]==2010){dCoopCred$PIB[i] <- c(7.5) 
}....
}}
Scroll to Top