mutate multiple conditions in R
0
0
Entering edit mode
2.8 years ago
logbio ▴ 30

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 • 3.1k views
ADD COMMENT
2
Entering edit mode

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.

ADD REPLY
0
Entering edit mode

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

ADD REPLY
0
Entering edit mode

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.

ADD REPLY
2
Entering edit mode

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
ADD REPLY
0
Entering edit mode

Thank you for helping

ADD REPLY
0
Entering edit mode

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

ADD REPLY
0
Entering edit mode

Actually my advisor was given as starting content for R

ADD REPLY
0
Entering edit mode

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

ADD REPLY

Login before adding your answer.

Traffic: 3119 users visited in the last hour
Help About
FAQ
Access RSS
API
Stats

Use of this site constitutes acceptance of our User Agreement and Privacy Policy.

Powered by the version 2.3.6