将向量合并为一个数 [英] Combine vectors into one number
本文介绍了将向量合并为一个数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
有没有办法将两个向量结合起来并引用结果?
Is there a way to join together two vectors and quote the result?
我有两个向量是根据我的代码自动产生的.
I have two vectors that are produced automatically from my code.
orderWA<-c(1,0,1)
orderWS<-c(1,0,0)
我知道我可以通过合并将它们合并起来
I know i can combine them by doing
c(orderWA,orderWS)
或
append(orderWA,orderWS)
无论如何,有没有机会让他们加入并输出:
Is there anyway to get them to join together and output this:
(1 0 1)(1 0 0)
然后有一种方法可以让我在矩阵的一个单元格中显示它,可以说(1 0 1)(1 0 0)= order
And then is there a way that I can get that to show in one cell in a matrix, lets say that (1 0 1)(1 0 0)=order
orderMAT<-matrix(c(Model,order),ncol=2)
colnames(orderMAT)<-c("Model","Order of parameters")
以便它输出类似这样的内容
so that it outputs something like this
Model Order of parameters
ARIMA (1 0 1)(1 0 0)
推荐答案
您可以通过以下方式将数字的组合表示为字符串.
You can represent the combinations of numbers as a string in the following way.
# combine numbers
order_string <- paste(paste0("(",
sapply(list(orderWA, orderWS),
paste, collapse = " "),
")"), collapse = "")
# create data frame
data.frame(Model = "ARIMA",
"Order of paramaters" = order_string,
check.names = FALSE)
# Model Order of paramaters
# 1 ARIMA (1 0 1)(1 0 0)
这篇关于将向量合并为一个数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文