如何将整个Excel文件读取为数组?

时间:2019-02-20 15:42:33

标签: r

我的PaddedBlockCipherParameters由10张纸组成。每张工作表代表一个城市,并具有一些具有不同维度的数据,即每张工作表的行数不同但列数相同。

我尝试过

import 'dart:typed_data';

import 'package:pointycastle/api.dart';
import 'package:pointycastle/block/aes_fast.dart';
import 'package:pointycastle/block/modes/ecb.dart';

main() {
  Uint8List key = Uint8List.fromList(
    [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15],
  );

  Uint8List plainText = Uint8List.fromList(
    [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16],
  );

  BlockCipher cipher = ECBBlockCipher(AESFastEngine());

  cipher.init(
    true,
    KeyParameter(key),
  );
  Uint8List cipherText = cipher.process(plainText);
}

但是还有其他方法可以自动将整个数据(如函数)存储在数组中吗? 请注意,我将行号设为160,因为它是所有工作表的最大观察数或行数。

1 个答案:

答案 0 :(得分:0)

您可能应该使用readxllapply将每张纸读入一个列表。这将生成一个列表,其中每个元素都是图纸之一(存储为R中的数据框对象)。试试这个:

library(readxl)

sheetVector <- c('sheet1', 'sheet2', 'sheet3')

sheetList <- lapply(
  sheetVector,
  function(sheet){
    read_xlsx(path = 'Data.xlsx', sheet = sheet)
  }
)

这将返回一个包含以sheetVector命名的三张纸的列表。如果要将图纸合并到一个数据框中:sheetDF <- rbindlist(sheetList)