This is a test version of Biostars. For the public version, visit https://www.biostars.org.
Finding Maximum Row Element Across 3 Columns

I'm sorry to have to ask for help to solve this very basic R problem.

I have a table from which I want to find the maximum values across the first 3 columns:

 Col1    Col2    Col3    Col4
   2    4    5    3
  17    2    30    21
   5    4    2    7
   8    19    1    0

The max values are outputted in Col1 and bound to Col4 values in a new table thus:

Col1    Col4
 5    3
30    21
 5    7
19    0

I have tried:

Col1 <- apply(Table1, 1, 'max')

Which did not work exactly as required. Help will be appreciated.

r bioconductor

This is a basic R programming question. Please explain its relevance to a bioinformatics research problem.

1 answer

Create two separate data frames first,with columns 1:3 and 4:ncol(Table1).

You can use apply on the first 3 columns and then add the result to the second data frame (either by creating a new data frame or using cbind)

Thank you cwardens45! That solved the problem.

Log in to answer this question.