I have two kinds of list, for example, one is like t[[1]]= 1 6 2 7 3 8 4 9 5 10 ... t[[731]] the other is k[[1]]= 9 10 ... k[[731]] I want to have a new list,like x x[[1]]= (1-9)/9 (6-10)/10 (2-9)/9 (7-10)/10 (3-9)/9 (8-10)/10 (4-9)/9 (9-10)/10 (5-9)/9 (10-10)/10 ... x[[731]] How should I do? Thank you. -- View this message in context: http://r.789695.n4.nabble.com/list-objects-calculation-tp4602437.html Sent from the R help mailing list archive at Nabble.com.
list objects calculation
2 messages · jiangxijixzy, PIKAL Petr
Hi you maybe can use mapply If you have 2 lists xl<-list(x, x+5) xl [[1]] [1] 1 2 3 4 5 [[2]] [1] 6 7 8 9 10
yl<-list(9,10) yl
[[1]]
[1] 9
[[2]]
[1] 10
and this function
fff<- function(xl,yl) (xl-yl)/yl
mapply(fff, xl, yl)
[,1] [,2]
[1,] -0.8888889 -0.4
[2,] -0.7777778 -0.3
[3,] -0.6666667 -0.2
[4,] -0.5555556 -0.1
[5,] -0.4444444 0.0
gives you probably desired result.
Regards
Petr
I have two kinds of list, for example, one is like t[[1]]= 1 6 2 7 3 8 4 9 5 10 ... t[[731]] the other is k[[1]]= 9 10 ... k[[731]] I want to have a new list,like x x[[1]]= (1-9)/9 (6-10)/10 (2-9)/9 (7-10)/10 (3-9)/9 (8-10)/10 (4-9)/9 (9-10)/10 (5-9)/9 (10-10)/10 ... x[[731]] How should I do? Thank you. -- View this message in context:
http://r.789695.n4.nabble.com/list-objects-
calculation-tp4602437.html Sent from the R help mailing list archive at Nabble.com.
______________________________________________ R-help at r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide
http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.