0

I made a function systemFail(x), where x is one of the columns in my data frame (df$location).

Now I want to create a new column in my data frame (df$outcome) with the result of this function (Pass/Fail result). I used the line of code below which made the extra column as I wanted. However, annoyingly the result (a long column of Passes and Fails) also shows up in my R Markdown document.

How can I get the extra column in my data frame without getting the result also in my R Markdown document?

df$outcome <- sapply(df$location, systemFail)
Roz
  • 195
  • 2
  • 10

1 Answers1

1

It is difficult to answer without knowing details of systemFail function. However, from your previous question it seems you are printing the values in the function. Instead of printing use return to return the result.

Look at this simple example -

systemFail <- function(x) {
  print(x)
}
res <- systemFail('out')
#[1] "out"

and when we use return nothing is printed and the result is available in res.

systemFail <- function(x) {
  return(x)
}
res <- systemFail('out')
Ronak Shah
  • 377,200
  • 20
  • 156
  • 213