sapply, apply function to all dataframe

The sapply function in R is used to apply a given function to each column or row of a dataframe. Here are the steps to use sapply:

  1. Define the dataframe: Ensure that you have a dataframe with the columns to which you want to apply the function.

  2. Choose the function: Select the function that you want to apply to each column or row of the dataframe.

  3. Use sapply: Use the sapply function and specify the dataframe as the first argument and the function as the second argument.

  4. Interpret the results: The sapply function will apply the chosen function to each column or row of the dataframe and return the results.

By following these steps, you can efficiently apply a function to all columns or rows of a dataframe using the sapply function in R.