This is a test version of Biostars. For the public version, visit https://www.biostars.org.
mutate multiple conditions in R

I have dataframe like below

child = data.frame(girl = 1:10, kn = NA, boy = 5)

And i want to understand the following code meaning step by step for these dataframe

df3 %>%   mutate(t = ifelse(is.na(kk), select(., matches('a')) %>%pull, ll))

Thank you for helping

ifelse mutate programming r offtopic

This question makes no sense. There is no connection between that data.frame and its colnames and the tidy chunk below. What is "a"? There is no kk in child, is it kn, and what is ll? Please invest some effort and put together a proper question.

I am new to bioinformatics That's why I'm looking for help too.

There is some communication gap then - either your advisor gave you an incomplete/wrong problem or you're missing something when you share this with us.

How is this related to bioinformatics and not a simple R question?

Actually my advisor was given as starting content for R

That makes this plain old R, not really bioinformatics. Please search StackOverflow and read dplyr manual pages.

For this code to work, the df3 must have columns, kk, ll, and any column with an "a" letter in it, for example "bay".

The meaning step-by-step:

  • ifelse(is.na(kk), - check if kk is NA
  • if the value is NA, then select(., matches('a')) %>% pull take the value from column with a column name that has "a" in it.
  • , ll)) if the value is not NA, then use the values from ll column.
  • mutate(t = finally assign the value from ifelse into new column t

Thank you for helping

0 answers

No answers yet.

Log in to answer this question.