I have data that looks like this :
X snp_id is_severe encoding_1 encoding_2 encoding_0
1 0 GL000191.1-37698 0 0 1 7
3 2 GL000191.1-37922 1 1 0 12
what I wish to do is to add a new row after every row that will contain the previous snp_id value and the is_sever value will be 1 if the previous is 0 and 0 if the previous is 1 (the goal is that every value of snp_id will have zero and one in is_severe column and not only zero or one ( and every snp_id will appear twice once with is_sever =zero and once with is_sever=1 all values of snp_id in the data are unique ) . Also, the encoding_1 & ancoding_2 will have the value 0 and the encoding_0 column will follow the equation: if in the new row the is_severe value is 0 the encoding_0 will be =8 and if in the new row the is_severe value is 1 the encoding_0 will be =13
Examples of desired output:
X snp_id is_severe encoding_1 encoding_2 encoding_0
1 0 GL000191.1-37698 0 0 1 7
2 1 GL000191.1-37698 1 0 0 13 <- new row
3 2 GL000191.1-37922 1 1 0 12
4 3 GL000191.1-37922 0 0 0 8 <- new row
i saw a similar QA here:How can I add rows to an R data frame every other row? but i need to do more data manipulation and unfortunately this solution doesn't solve my problem . thank you:)