嗨,我正在文件夹中的许多文件上运行以下 r 脚本
runForAll <- function(x) {
emboss <- read.table(x,header=T)
x <- table(emboss[,2],emboss[,3])/NROW(emboss[,3])
y <- as.vector(t(x))
nms <- expand.grid(colnames(x), rownames(x))
names(y) <- paste( nms[,2],nms[,1],sep="")
return(t(y))
}
my.files <- list.files(pattern = "emboss_\\d+\\.ss")
outputs <- lapply(my.files, FUN = runForAll)
我注意到在 x 中,一些表的行数比其他表少 1 行。
正常 x:
C E H
A 0.011152416 0.003717472 0.011152416
C 0.026022305 0.033457249 0.003717472
D 0.029739777 0.000000000 0.007434944
E 0.044609665 0.011152416 0.003717472
F 0.022304833 0.011152416 0.011152416
G 0.026022305 0.003717472 0.007434944
H 0.040892193 0.007434944 0.003717472
I 0.040892193 0.022304833 0.022304833
K 0.059479554 0.003717472 0.018587361
L 0.018587361 0.007434944 0.066914498
M 0.003717472 0.003717472 0.011152416
N 0.052044610 0.003717472 0.007434944
P 0.044609665 0.000000000 0.003717472
Q 0.018587361 0.000000000 0.014869888
R 0.026022305 0.007434944 0.011152416
S 0.022304833 0.007434944 0.011152416
T 0.029739777 0.014869888 0.014869888
V 0.000000000 0.000000000 0.014869888
W 0.011152416 0.007434944 0.007434944
Y 0.018587361 0.029739777 0.022304833
x 缺少行:
C E H
A 0.030874786 0.012006861 0.049742710
D 0.044596913 0.005145798 0.015437393
E 0.029159520 0.008576329 0.024013722
F 0.013722127 0.015437393 0.005145798
G 0.051457976 0.003430532 0.008576329
H 0.013722127 0.005145798 0.006861063
I 0.024013722 0.015437393 0.013722127
K 0.056603774 0.003430532 0.039451115
L 0.025728988 0.024013722 0.039451115
M 0.006861063 0.003430532 0.010291595
N 0.029159520 0.001715266 0.008576329
P 0.036020583 0.001715266 0.008576329
Q 0.020583190 0.005145798 0.015437393
R 0.037735849 0.008576329 0.020583190
S 0.030874786 0.005145798 0.027444254
T 0.034305317 0.006861063 0.017152659
V 0.010291595 0.012006861 0.018867925
W 0.006861063 0.000000000 0.010291595
Y 0.005145798 0.008576329 0.006861063
我该如何检查:
x 的每个实例有 20 行,如果 x 的特定实例少于 20 行,则添加一个充满零的行
即如果一个 x 只有 17 行,则添加 3 行零。
非常感谢。