[R] Adding column values based on a condition

Alessandro Puglisi
Sat, 06 Jul 2019 09:55:30 -0000

Hi all!

I have a tibble regarding a series of comments on a forum; the tibble has a
certain number of variables, and in particular:

id: comment id;
author_id: author id;
parent_id: if the message is a reply, the original comment id

I want to add another column, in which I put the author id of the original
comment, when parent_id IS NOT NA.

I already tried to use mutate + ifelse but my problem is that I have to
refer to an author id in a different row than that in which I'm evaluating
the if condition...

Thanks in advance,
Alessandro