一般相关问题
有人可以指出我要获取R中多维列表或数据结构的维大小的函数/方法吗?
Could someone please point me to functions / methods to get the dimension sizes of a multidimension list or datastructure in R?
了解在更大的数据结构中访问各个元素的方法也将很有用?
It would also be useful to know ways to access individual elements within this bigger datastructure?
下面有关示例输入和输出数据的问题
使用以下命令将输入数据转换为输出数据:(以下相关问题):
The Input data is converted to output data using this command:(related question below):
lst <- lapply(split(df2[-1], df2$Column_Zero), function(x) acast(x, Column_Two~Column_One,value.var="Column_Three"))
输入数据:
Column_Zero, Column_One, Column_Two, Column_Three XX,A, 1, 4 XX,A, 2, 3 XX,A, 3, 77 XX,B, 1, 44 XX,B, 2, 32 XX,B, 3, 770 XX,C, 1, 43 XX,C, 2, 310 XX,C, 3, 68 YY,A1, 1, 4 YY,A1, 2, 3 YY,A1, 3, 77 YY,B1, 1, 44 YY,B1, 2, 32 YY,B1, 3, 770 YY,C1, 1, 43 YY,C1, 2, 310 YY,C1, 3, 68 YY,D2, 1, 4 YY,D2, 2, 5 YY,D2, 3, 6---------等等-----
--------- And so on -----
输出数据:
------数据表一------
------ Data Table one ------
A, B, C 4, 44, 43 3, 32, 310 77, 770, 68------数据表二------
------ Data Table Two ------
A1, B1, C1, D2 4, 44, 43,4 3, 32, 310,5 77, 770, 68,6--------等等-----
------ and so on -----
相关问题: 这是在相关的问题中提出的,我们将在其中拆分数据表并对其进行重塑.因此,了解较小的数据结构/矩阵或数据表的大小变得很重要.
Related Question: This comes up in the related question, where we are splitting a data table and reshaping it. So it becomes important to know how big the smaller data structures / matrices or data tables are.
R转换数据表将不同的列值与列名和不同的列值作为另一列的值
如果有任何不清楚的地方或需要进一步的信息,请告诉我.
Please let me know if anything is not clear or if you need any further information.
推荐答案问题的答案是
由于每个list元素都是matrix,因此我们可以使用length来查找matrices
As each of the list element is a matrix, we can use length to find the number of matrices
length(lst) #[1] 2(在一般情况下)如果还有其他对象
In case if there are other objects (in a general scenario)
sum(sapply(lst, is.matrix)) #[1] 2
我们可以使用names
names(lst)
我们可以通过遍历lst
sapply(lst, ncol) # XX YY # 3 4
与上述相同,将ncol替换为nrow.我们可以同时使用dim
It is the same as above by replacing ncol with nrow. We can get both by using dim
lapply(lst, dim)
我们可以在遍历"lst"之后使用which.min或which.max查找索引.
We can use which.min or which.max to find the index after looping through the 'lst'.
lst[which.min(sapply(lst, ncol) )] lst[which.max(sapply(lst, ncol))]和nrow
更多推荐
R查找多维数组维尺寸
发布评论