I try to understand how to use commands of excellent plyer packages on a vector (in my case, strings) I am here. I think I want to use aaply, but it fails, asking for margin but there are no columns or rows in my vector!
To make it a little more solid, the following command works, but returns results in an odd list. States.df is a data frame, and the area is the name of the state (returned by using map_data ("state" of Hadley). Thus, the states.df $ area is a vector of string (in particular, state name). Opinion is a vector of new numbers, which is designated using state names.
states.df & lt; - map_data ("state") ch = sapply (states.df $ area, function (x) {opinion.new [names (opinion.new) == x]}) me What to do:
ch = aaply (states.df $ area, function (x) {opinion.new [name (opinion.new) == x]}) where f is the numbers Vector looked up or pulled from Opinion.new Thanks!
If you want to use a plywood on a vector, you have to use L * ply, As follows:
v <-> 1:10 sapply (v, function (x) x ^ 2) [1] 1 4 9 16 25 36 49 64 81 100 lapili ( V, function (x) x ^ 2) [1] 1 4 9 16 25 36 49 64 81 100 In other words, sapply and laply are equivalent
Comments
Post a Comment