Advertisement
Guest User

Untitled

a guest
Jun 17th, 2019
80
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.50 KB | None | 0 0
  1. demo.df <- structure(list(node_id = 1:21, depth = c(4, 3, 2, 1, 0, 0,
  2. 1, 0, 0, 2, 1, 0, 0, 1, 0, 0, 2, 1, 0, 0, 0), x_position = c(NA, NA,
  3. NA, NA, 1, 2, NA, 3, 4, NA, NA, 5, 6, NA, 7, 8, NA, NA, 9,10, 11), X1
  4. = 1:21, X2 = c(2L, 3L, 4L, 5L, NA, NA, 8L, NA, NA, 11L, 12L, NA, NA,
  5. 15L, NA, NA, 18L, 19L, NA, NA, NA), X3 = c(17L, 10L, 7L, 6L, NA, NA,
  6. 9L, NA, NA, 14L, 13L, NA, NA, 16L, NA, NA, 21L, 20L, NA, NA, NA)),
  7. class = "data.frame", row.names = c(1L, 2L, 4L, 8L, 16L, 17L, 9L, 18L,
  8. 19L, 5L, 10L, 20L, 21L, 11L, 22L, 23L, 3L, 6L, 12L, 13L, 7L))
  9.  
  10. node_sequence <- c(4,7,11,14,18,3,10,17,2,1)
  11.  
  12. x_spot <- function (x)
  13. {mean(demo.df$x_position[which(demo.df$node_id%in%demo.df[x,c(4:6)])],
  14. na.rm = TRUE)
  15. }
  16.  
  17. demo.df$x_position[node_sequence[1]] <- x_spot(node_sequence[1])
  18. demo.df$x_position[node_sequence[2]] <- x_spot(node_sequence[2])
  19. demo.df$x_position[node_sequence[3]] <- x_spot(node_sequence[3])
  20. demo.df$x_position[node_sequence[4]] <- x_spot(node_sequence[4])
  21. demo.df$x_position[node_sequence[5]] <- x_spot(node_sequence[5])
  22. demo.df$x_position[node_sequence[6]] <- x_spot(node_sequence[6])
  23. demo.df$x_position[node_sequence[7]] <- x_spot(node_sequence[7])
  24. demo.df$x_position[node_sequence[8]] <- x_spot(node_sequence[8])
  25. demo.df$x_position[node_sequence[9]] <- x_spot(node_sequence[9])
  26. demo.df$x_position[node_sequence[10]] <- x_spot(node_sequence[10])
  27. demo.df$x_position
  28.  
  29. vapply(1:10, function(x) {demo.df$x_position[node_sequence[x]] <- x_spot(node_sequence[x])}, numeric(1))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement