我想在df
中添加一行,并用normal
字符串填充该行。
df[nrow(df) + 1,] <- "normal"
追溯:
Error in `[<-`(`*tmp*`, nrow(df) + 1, , value = "normal") :
subscript out of bounds
数据:
> dput(df)
structure(c(0.817235177513274, 0.842271224674921, 0.787053698556768,
0.723253823258161, 0.330810989820991, 0.929282245774236, 0.385900089441395,
0.580292714010189, 0.928938997366233, 0.78643829926366, 0.739342773828268,
0.815944692823519, 0.701024754855706, 0.690557534921593, 0.292246602221495,
0.907803873079535, 0.453213181805882, 0.550745234719392, 0.913370916956376,
0.716310393262212, 0.765542822762287, 0.568705595673652, 0.6714274267581,
0.531716650540856, 0.331580044004539, 0.840889607944185, 0.494640734908958,
0.396783055306106, 0.8692727119489, 0.759022283299301, 0.787291380662438,
0.855192302325311, 0.743632726648944, 0.710242442123609, 0.351783150991687,
0.933702108520557, 0.410525438050587, 0.549479034093077, 0.920910305577791,
0.812458352284617, 0.762864102512286, 0.82250047660344, 0.681146614449272,
0.722562365641304, 0.295007368926608, 0.923671059571924, 0.379539671884597,
0.515060486276735, 0.91767133328213, 0.79917575064228, 0.743564108418945,
0.541783705139426, 0.675695188150901, 0.530335228219673, 0.311148090618456,
0.888403586041492, 0.489850949026585, 0.495137719924742, 0.928270455994818,
0.781619937522964, 0.83114689516785, 0.745890503970576, 0.819047883913701,
0.693061612485807, 0.34437655946559, 0.925122536085658, 0.438053894428271,
0.539601859327891, 0.930313177385918, 0.77987407757735, 0.797258263299495,
0.539125161286865, 0.73772463742416, 0.596959758946811, 0.340833820254246,
0.867012396000705, 0.414398893790568, 0.478458869251912, 0.9148617831338,
0.794732448316904, 0.750972160691783, 0.421962727382347, 0.630243285799926,
0.575866112480541, 0.331617484056072, 0.880175147517098, 0.398626259709664,
0.453109749361369, 0.89591402846511, 0.800528147561602, 0.797443406632106,
0.707871104991111, 0.720883316856463, 0.589889378319629, 0.349813234586068,
0.740142906790019, 0.495298129407806, 0.389674692905969, 0.869933439187107,
0.743658144096678), dim = c(10L, 10L), dimnames = list(c("ALDH8A1",
"ALDOB", "ANXA9", "AQP1", "ARL4D", "BIN2", "BRF2", "BST2", "C14orf109",
"C1QTNF3"), c("TCGA-CZ-5455-11A", "TCGA-BQ-7061-11A", "TCGA-B0-5402-11A",
"TCGA-CZ-5469-11A", "TCGA-CZ-5465-11A", "TCGA-BQ-7051-11A", "TCGA-CZ-5454-11A",
"TCGA-BQ-5875-11A", "TCGA-BQ-5891-11A", "TCGA-BQ-5890-11A")))
1条答案
按热度按时间k7fdbhmy1#
1.正如RicVallalba评论的那样,你的数据是
matrix
而不是data.frame
,这通常不是问题,我们可以用任何一种方式工作,但是如果你需要一个帧,那么就用df <- as.data.frame(df)
。1.不清楚将
"normal"
(一个 string)追加到一个填充了numeric
数据的对象中是什么意思:通过将字符串添加到任何列,通过将那些数字转换成字符串来破坏所述列,从而挫败将来可能想要对它们进行的任何数字操作。我将推断您真正的意思是添加一个名为 *
"normal"
的空值行。(This同时适用于框架和矩阵。)