Coming soon - Get a detailed view of why an account is flagged as spam!
view details

This post has been de-listed

It is no longer included in search results and normal feeds (front page, hot posts, subreddit posts, etc). It remains visible only via the author's post history.

12
If-else and nested if-else on dataframes
Post Body

I would like to recreate the ifelse syntax from R in Julia and am not sure the best way to do that.

In my example I have a panel of developments and an array of developments that did receive a treatment

developments = 1:10000
years = 1:20
# panel of developments, each development observed for 20 years
data =rename!(DataFrame( (Iterators.product(developments, years)) ), [:development, :year])
# randomly assign 5000 developments to treatment
treated = sample(developments,Int(length(developments) / 2), replace = false )

# make a new column that specifies if that development ever received treatment
???

In R this would be

data$treated = ifelse(data$development %in% treated,1,0)

I can do

data[!, :treated] = [x in treated for x in data[!,:development]]

But I don't know how to neatly generalize this to handle multiple if-else statements similar to the R function case_when, or how to change the variable to be "treated" and "not treated" instead of true/false.

Thanks!

Author
Account Strength
100%
Account Age
4 years
Verified Email
Yes
Verified Flair
No
Total Karma
36,701
Link Karma
1,569
Comment Karma
34,501
Profile updated: 10 hours ago
Posts updated: 6 months ago

Subreddit

Post Details

We try to extract some basic information from the post title. This is not always successful or accurate, please use your best judgement and compare these values to the post title and body for confirmation.
Posted
2 years ago