[R] Re adout row and column of a matrix value

Chris82 rubenbauar at gmx.de
Wed Sep 17 19:47:04 CEST 2008


Hello R users,

I want to readout the row and column postion from a certain matrix value
into a csv file.
I have only found this syntax 

"which(a == b, arr.ind = T)"

so I get

a = matrix

 [,1] [,2] [,3] [,4] [,5] [,6] [,7] [,8]
[1,]    1    1    2    2    2    1    1    2
[2,]    1    2    3    3    3    4    4    3
[3,]    3    3    3    5    5    6    5    4
[4,]    4    4    4    3    3    4    4    3
[5,]    3    4    5    3    3    3    2    2
[6,]    3    3    3    3    3    3    2    2
[7,]    2    2    2    2    2    4    2    1
[8,]    1    1    0    0    0    0    0    0

> print(max(a))
[1] 6
> which(a == max(a), arr.ind = T) 
     row col
[1,]   3   6

but I need row and col seperate for the csv file.

row <- c("code for row")
col <- c("code for col")
value <- c("6")

#dataframe

test <- data.frame(row, col, value)

write.csv................

Thanks.

Greets

-- 
View this message in context: http://www.nabble.com/Readout-row-and-column-of-a-matrix-value-tp19537540p19537540.html
Sent from the R help mailing list archive at Nabble.com.



More information about the R-help mailing list