Hello,

 

I am trying to calculate the median of numbers across each row for the data
shown below  , with the condition that if the number is negative, that it
should be ignored and the median should be taken of only the positive
numbers.

 

For eg: data is in Column A,B,C. Column D and E demonstrates what I want to
get as answer

 

A

B

C

Median

median value

-13.6688115

-32.50914055

-50.54011892

all negative, so ignore

 NA

NA

-53.65656268

42.58599666

median C

42.58599666

33.30683089

18.93765489

-25.17024229

median A,B

26.12224289

 

The R script I have written is below( which  doesnot  do the job properly)

 

median.value<- matrix(nrow=nrow(data),ncol=1)

for(k in 1:nrow(data)){

median.value[k]<-median(data[which(data[k,]>0)])}

 

Can someone suggest me the correct R script to do what I have explained
above.

 

Thanks

Manisha

 


	[[alternative HTML version deleted]]


