我试图按因子将辅助函数应用于数据框。 我的功能有效(我知道,因为我已经使用了很多,它也适用于完整的数据框),拼写是正确的。 但是,当我想申请时,我收到一个错误:
List<Book> books = new ArrayList<Book>();
JsonFactory f = new JsonFactory();
JsonParser jp = f.createJsonParser(json);
jp.setCodec(new ObjectMapper());
JsonNode node = jp.readValueAsTree();
JsonNode books = node.findValue("Books");
Iterator<JsonNode> it = books.getElements();
while(it.hasNext()){
JsonNode temp = it.next();
Book book = new Book();
book.setIsbn(temp.findValue("isbn").asText());
book.setTitle(temp.findValue("title").asText());
book.setAuthor(temp.findValue("author").asText());
book.setPrice(temp.findValue("price").asDouble());
books.add(book);
}
如果我试图找到它,它就在全球环境中
pru<-by( data = cs_us[,3:length(cs_us)],
+ INDICES = cs_us$ensayo,
+ FUN =desplazar(cs_us$tiempo,cs_us[,3:length(cs_us)-1])
+ )
Error in FUN(X[[1L]], ...) : could not find function "FUN"
这是我的一个数据(只是你拥有2个因素水平的关键部分)
getAnywhere(desplazar)
A single object matching ‘desplazar’ was found
It was found in the following places
.GlobalEnv
with value
function(tiempo,dataframe){
matriz = as.matrix(dataframe)
matriz_dif = abs(diff(matriz )) # derivar
matriz_dif_inv = diffinv(matriz_dif) # integrar
return(data.frame(cbind(tiempo, matriz_dif_inv )))
}
答案 0 :(得分:0)
你可以尝试
by(cs_us[,(3:length(cs_us))-1], cs_us$ensayo,
FUN= function(x) desplazar(x$tiempo, x[,-1] ) )
或者
Map(desplazar, split(cs_us$tiempo, cs_us$ensayo),
split(cs_us[3:(ncol(cs_us)-1)], cs_us$ensayo))
您还可以修改desplazar
并删除by
desplazar1 <- function(data){
matriz <- as.matrix(data[-1])
matriz_dif <- abs(diff(matriz))
matriz_dif_inv <- diffinv(matriz_dif)
data.frame(tiempo=data['tiempo'], matriz_dif_inv)
}
by(cs_us[,(3:length(cs_us))-1], cs_us$ensayo, FUN=desplazar1)