Re: [R] remove rows based on row mean

2016-08-18 Thread Adrian Johnson
Wow. This is much cleaner and smarter than the for loop, cbind thanks a lot . On Thu, Aug 18, 2016 at 6:28 PM, Jim Lemon wrote: > Hi Adrian, > Try this: > > sm$rowmeans<-rowMeans(sm[,2:length(sm)]) > sm<-sm[order(sm$Gene,sm$rowmeans,decreasing=TRUE),] > sm[-which(duplicated(sm$Gene)),] > > Jim >

Re: [R] remove rows based on row mean

2016-08-18 Thread jeremiah rounds
oh I forgot I renamed sm. dt = sm library(data.table) setDT(dt) op = function(s){ mean0 = apply(s, 1, mean) ret = s[which.max(mean0)] ret$mean = mean0 ret } max_row = dt[, op(.SD), by = "Gene"] Thanks, Jeremiah On Thu, Aug 18, 2016 at 3:21 PM, jeremiah rounds wrote: > library(data.table) > se

Re: [R] remove rows based on row mean

2016-08-18 Thread Jim Lemon
Hi Adrian, Try this: sm$rowmeans<-rowMeans(sm[,2:length(sm)]) sm<-sm[order(sm$Gene,sm$rowmeans,decreasing=TRUE),] sm[-which(duplicated(sm$Gene)),] Jim On Fri, Aug 19, 2016 at 7:33 AM, Adrian Johnson wrote: > Hi Group, > I have a data matrix sm (dput code given below). > > I want to create a da

Re: [R] remove rows based on row mean

2016-08-18 Thread jeremiah rounds
library(data.table) setDT(dt) op = function(s){ mean0 = apply(s, 1, mean) ret = s[which.max(mean0)] ret$mean = mean0 ret } max_row = dt[, op(.SD), by = "Gene"] Thanks, Jeremiah On Thu, Aug 18, 2016 at 2:33 PM, Adrian Johnson wrote: > Hi Group, > I have a data matrix sm (dput code given below).

[R] remove rows based on row mean

2016-08-18 Thread Adrian Johnson
Hi Group, I have a data matrix sm (dput code given below). I want to create a data matrix with rows with same variable that have higher mean. > sm Gene GSM529305 GSM529306 GSM529307 GSM529308 1A1BG 6.57 6.72 6.83 6.69 2A1CF 2.91 2.80 3.08 3.00