# Tag Info

## Hot answers tagged r

1

This should do the trick. You set up your vector of possible fruits to select from, and then everywhere there is an NA in df$fruit, pick a random element from the possible fruit vector to overwrite it with: randomFruits = c("apple", "banana", "peach", "pear", "strawberry") df$fruit[is.na(df\$fruit)] = ...

1

The default quantiles with quantile are 0%, 25%, 50%, 75%, 100%. This means that the quartiles Q1 and Q3 are the second and fourth value in the two vector you obtain. Since indexes start at 1 it means that you can obtain Q1 with ar_quantiles[2] and Q3 with ar_quantiles[4]. Currently you're using indexes 1 and 2 and that's certainly what causes the problem. [...

1

You can use case_when() and list the conditions in the order of your rank. Since your dummy variables are already os type logical, the following should work: df %>% mutate( WhatINeed_2 = case_when( Medical ~ "Medical", NoID ~ "NoID", Refuse ~ "Refuse", TRUE ~ NA_character_ ) ) VisitID ...

Only top voted, non community-wiki answers of a minimum length are eligible