R ifelse() is returning TRUE/FALSE instead of value

Hi there,

for me something weird is happening in my R-Script... Im using the statement below. tmp1 and tmp2 just return TRUE/FALSE and not 0 or the result of the sequence function.
Do you have any idea?

dt_DAY[, tmp1 := ifelse(KT_fd == 1,sequence(rle(as.character(KT_fd))$lengths),0), by=id]
dt_DAY[, tmp2 := ifelse(tmp1== 0,1,0),by=id]
dt_DAY[, tmp2 := shift(tmp2, 1),by=id]
dt_DAY[, KT_fsdi0 := tmp1 * tmp2]

Hello.
Thanks for providing code , but you could take further steps to make it more convenient for other forum users to help you.

Share some representative data that will enable your code to run and show the problematic behaviour.

You might use tools such as the library datapasta, or the base function dput() to share a portion of data in code form, i.e. that can be copied from forum and pasted to R session.

1 Like

@nirgrahamuk the discovery of the datapasta() package has been life changing... I would type all my tibbles() for my reprexes.

This topic was automatically closed 21 days after the last reply. New replies are no longer allowed.

If you have a query related to it or one of the replies, start a new topic and refer back with a link.