NickL
NickL

Reputation: 103

How can I change this function in R so that it changes the data frame in x?

The code below is my attempt at a function to change the data table in x. The data table x has columns named MutationStatus and disease. When I plug x as the data table and y as the string within the disease column manually, the function works, however plugging it as a function does not.

diseaseMutation <- function(x,y) {
  x$MutationStatus[x$disease != y] = "WT"
  x$disease[x$disease != y] = y
}

Upvotes: 1

Views: 41

Answers (1)

akrun
akrun

Reputation: 887148

We need to return the 'x'

diseaseMutation <- function(x,y) {
  x$MutationStatus[x$disease != y] = "WT"
   x$disease[x$disease != y] = y
   x
 }

Upvotes: 1

Related Questions