apply - subset using R language -
i have 2 tables
in first table, have 2 columns. in first colum , values run 1 2 1000000 (call them x). in sec column, have random numbers (call them y) .
in sec table , have 2 columns. in first colum , have same x values, not run 1 2 1000000 instead in random increasing order 222 , 249 , 562 .. , on. in sec column, have random numbers (call them z) .
now, trying add together 3rd column sec table y values first table.i decided utilize apply . but, can utilize bring together or merge -- whichever more efficient. here x value connects y , z.
to start minimal data, can utilize code:
t1 <- cbind(1:20, sample(100:999, 20, true)) t2 <- rbind(c(2, 4), c(6, 12), c(17, 18)) apply(t2, 1, function(...) )
could help me fill ... blanks.
the output should of form:
2 4 -- 6 12 -- 17 18 --
does meet requirements?
require(plyr) t1 <- as.data.frame(cbind(1:20, sample(100:999, 20, true))) t2 <- as.data.frame(rbind(c(2, 4), c(6, 12), c(17, 18))) t3 <- join(t2, t1, type = "left", = "v1") t3 > t3 v1 v2 v2 1 2 4 779 2 6 12 898 3 17 18 903
r apply
No comments:
Post a Comment