[R] using mapply()
dxc13
dxc13 at health.state.ny.us
Tue Jan 8 20:51:55 CET 2008
useR's,
This is a follow up question to one I previously asked. Consider the
3-element list below
> res
[[1]]
[,1] [,2] [,3] [,4] [,5] [,6] [,7] [,8] [,9] [,10] [,11] [,12]
[,13] [,14]
[1,] NA NA NA 1.25 0.25 0.75 NA NA NA NA NA NA 1.25
0.25
[2,] 1.25 0.25 0.75 NA NA NA NA NA NA 1.25 0.25 0.75 NA
NA
[3,] NA NA NA NA NA NA 1.25 0.25 0.75 NA NA NA NA
NA
[4,] NA NA 1.25 0.25 0.75 NA NA NA NA NA NA 1.25 0.25
0.75
[5,] NA NA NA NA NA 1.25 0.25 0.75 NA NA NA NA NA
NA
[[2]]
[,1] [,2] [,3] [,4] [,5] [,6] [,7] [,8] [,9] [,10] [,11] [,12]
[,13] [,14]
[1,] NA NA NA NA NA NA NA NA NA NA NA NA NA
1.25
[2,] 1.25 NA NA NA NA NA NA NA NA NA NA NA NA
NA
[3,] 1.25 1.25 1.25 1.25 1.25 1.25 1.25 1.25 1.25 0.25 0.25 0.25 0.25
0.25
[4,] NA NA NA NA NA NA NA NA NA NA NA NA NA
NA
[5,] NA NA NA NA NA 1.25 NA NA NA NA NA NA NA
NA
[[3]]
[,1] [,2] [,3] [,4] [,5] [,6] [,7] [,8] [,9] [,10] [,11] [,12]
[,13] [,14]
[1,] NA NA NA NA NA NA NA NA NA NA NA NA NA
1.25
[2,] 0.25 NA NA NA NA NA NA NA NA NA NA NA NA
NA
[3,] 1.25 1.25 1.25 1.25 1.25 1.25 1.25 1.25 1.25 0.25 0.25 0.25 0.25
0.25
[4,] NA NA NA NA NA NA NA NA NA NA NA NA NA
NA
[5,] NA NA NA NA NA 0.25 NA NA NA NA NA NA NA
NA
What I want to do is find the values that are not NA simultaneously for each
value in each element of the list, and then average these numbers and store
them in a 14x1 vector. For example, in position (2,1) in each of the 3
elements of the res list, there is a value, 1.25 in [[1]] and [[2]], 0.25 in
[[3]]. Since there is a value in this position in all elements of the list
I want to average these numbers: (1.25+1.25+0.25)/3 and store this value in
a numeric vector. So, if there are not 3 values to average, this means
that a given position (i,j) does not have a value in each element of the
list and thus I want to store NA in the 14x1 vector. In the end, the 14x1
vector will be mixed with values and NA's or NaN's.
Does anyone know a efficient way to do this? Maybe using mapply()? I hope
it is clear. Thank you for any input.
Derek
--
View this message in context: http://www.nabble.com/using-mapply%28%29-tp14697351p14697351.html
Sent from the R help mailing list archive at Nabble.com.
More information about the R-help
mailing list