- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我是使用 R 的新手,因此我的问题可能很简单,但尽管如此,我还是花了很多时间试图弄清楚我做错了什么,但无济于事。在过去的一周里,我在这个网站上发现了很多帮助,搜索其他问题/答案(谢谢!)但作为一个新人,通常很难解释其他人的代码。
我正在尝试构建一个包含多个数据文件的 3 维数组,每个文件的尺寸都相同,为 57x57。
# read in 100 files
Files = lapply(Sys.glob('File*.txt'), read.table, sep='\t', as.is=TRUE)
# convert to dataframes
Files = lapply(Files[1:100], as.data.frame)
# check dimensions of first file (it's the same for all)
dim(Files[[1]])
[1] 57 57
# build empty array
Array = array(dim=c(57,57,100))
# read in the first data frame
Array[,,1] = Files[1]
# read in the second data frame
Array[,,2] = Files[2]
Error in Array[, , 2] = Files[2] : incorrect number of subscripts
# if I check...
Array[,,1] = Files[1]
Error in Array[, , 1] : incorrect number of dimensions
# The same thing happens when I do it in a loop:
x = 0
for(i in 1:100){
Array[,,x+1] = Files[[i]]
x = x + 1
}
Error in Array[, , 1] = Files[[1]] :
incorrect number of subscripts
最佳答案
在进行分配之前,您需要将数据框转换为矩阵:
l <- list(data.frame(x=1:2, y=3:4), data.frame(x=5:6, y=7:8))
arr <- array(dim=c(2, 2, 2))
arr[,,1] <- as.matrix(l[[1]])
arr[,,2] <- as.matrix(l[[2]])
arr
# , , 1
#
# [,1] [,2]
# [1,] 1 3
# [2,] 2 4
#
# , , 2
#
# [,1] [,2]
# [1,] 5 7
# [2,] 6 8
unlist
在一行中构建数组。应用于要组合的矩阵列表的函数:
arr2 <- array(unlist(lapply(l, as.matrix)), dim=c(dim(l[[1]]), length(l)))
all.equal(arr, arr2)
# [1] TRUE
关于arrays - 数组中的维数和下标数不正确,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24111835/
是否可以创建一个可以使用显式参数标签调用的下标? struct MyType { subscript (label: Bool) -> String? { return nil
我正在尝试制作一个包含带有上标和/或下标的文本的超链接。我找到了两种方法来做到这一点,它们都很糟糕。 解决方案#1:使用 Typography.Variants .这为某些字体提供了极好的上标……。
在这里! 我想在 geom_bracket 中包含一个带下标的标签在 ggplot2 .我尝试了不同的方式,但没有人成功(评论中的尝试): library(ggplot2) ggplot(data =
我正在尝试让 graphviz 启动并工作,我迫切需要节点标签中的下标。不幸的是,通过浏览无数关于类似问题的帖子,我似乎适合所有建议的解决方案,但仍然不起作用。这是我的代码: digraph G{
抱歉格式问题,我从来没有真正在这样的论坛上发帖,所以我必须学习一下操作方法。 我的问题是:我正在编写一个模板类,我想通过多种 [] 运算符访问我的容器。我读了一些关于这个主题的内容,所以我已经能够重载
我知道我们可以像在 matplotlib 中生成单个下标 $r_i$ 会给我一个下标为“i”的r。 但我想生成一个包含 3 或 4 个字母的下标,例如 r_ijk 应该给我一个带有“ijk”作为下标的
this[5] 有什么作用?我是否调用了某种未定义的行为?关于: std::vector foo{this, this + 5u}; 这个有用吗?我想知道指针算法对 this 的影响是什么。这是一个测
我从 visual studio 得到了一些奇怪的行为,关于以下代码片段,错误列表显示了 E0349 的几个实例:没有运算符“[]”匹配这些操作数。 Intellisense 似乎暗示类型不匹配,但正
我想为我的数组类提供 PHP 样式的 push_back 功能: arrayT arr; arr[] = 10; // == std::vector::push_back() 和 arrayT::op
下标 (subscripts)可以定义在类(class)、结构体(structure)和枚举(enumeration)中,是访问集合(collection),列表(list)或序列(sequence)
我正在使用traindata训练svm。 (R中的e1071软件包)。以下是有关我的数据的信息。 > str(train) 'data.frame': 891 obs. of 10 variab
#include int main(){ int arr[7] = {0,1,2,3,4,3,2}; arr[0]++[arr]++[arr]++[arr]++[arr]++[arr]
如果我想以特定用户的身份调用主脚本文件中的另一个 shell 脚本,我该怎么做呢?子脚本似乎失去了它正在运行的用户的上下文,我还没有找到任何有用的子脚本技术。 例如:war-install.sh if
这个问题在这里已经有了答案: Why isn't there an operator[] for a std::list? (4 个答案) 关闭 5 年前。 我有这些类型定义: typedef pa
我在 NSUserdefaults 中获取字典的字符串时遇到问题,这是我的代码。我不知道似乎是什么问题: static func getItemInUserDefaultsDictionary(key
我正在尝试执行以下代码并收到错误 Could not find member 'subscript on Xcode6 var b:[[Float]] = [[1,2]] var i2 = 0 //
我尝试运行的代码: std::string genBlankName(std::vector &posts) { std::string baseName = "New Post ";
1 1 A_{3} 2 2 C_{2} 3 3 ^{5}C_{1} 我有一个这样的输入文件要绘制。第三列是该点上的标签( latex 格式)。我如何在绘图上显示这些标签,就像它们在 latex 编译后
我在这里搜索了一段时间,之前的问题/答案部分回答了我的问题。我正在学习 R,来自 Matlab。正如标题所说,我有一个关于情节注释的问题。在 Matlab 中,绘制包含各种数据格式的注释非常简单,我正
我想将一些化学数据放入表格的列中。但在现有表格中,下标显示为普通字符。其中一些显示为问号。我应该怎么做才能解决它? 当我输入这段代码时 SELECT N'H' + NCHAR(0x2082) + N
我是一名优秀的程序员,十分优秀!