Finding Maximum Row Element Across 3 Columns
1
0
Entering edit mode
10.9 years ago
robjohn7000 ▴ 110

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

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

ADD REPLY
2
Entering edit mode
10.9 years ago

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)

ADD COMMENT
0
Entering edit mode

Thank you cwardens45! That solved the problem.

ADD REPLY

Login before adding your answer.

Traffic: 878 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