0
私はこのコードをif..elsif..elseステートメントの中に別のテーブルをkableで印刷するようにしました。私のデータフレームを使用してKableはif..elsif ... elseステートメント内にテーブルを表示しません
```{r}
if (sum(df_final2$change)!=0 && nrow(df_final[is.na(df_final$PEH.1),])!=0) {
cat("The new peptides are:\n")
kable(df_peptides_spectra2)
cat("Decreased or increased:\n")
kable(df_final3)
} else if (sum(df_final2$change)==0 && nrow(df_final[is.na(df_final$PEH.1),])!=0) {
cat("The new peptides are:")
kable(df_peptides_spectra2)
cat("The rest peptides are the same.")
} else if (sum(df_final2$change)!=0 && nrow(df_final[is.na(df_final$PEH.1),])==0) {
cat("The are not new peptides:\n")
cat("Decreased or increased:\n")
kable(df_final3)
} else
cat("The number of peptides are the same\n")
```
、条件を満たした状態でオプション2であるので、私はこれを持っていると予想:ものの
cat("The new peptides are:")
kable(df_peptides_spectra2)
cat("The rest peptides are the same.")
、私の出力は、任意のテーブルずに、これです。 :
The new peptides are:
The rest of peptides are the same.
これを修正する方法はありますか?私は各印刷呼び出しの後に改行を追加しようとしましたが(R: why kable doesn't print inside a for loop?)、私は同じ問題を抱えています。お使いの再現性のある例では
```{r}
df <- structure(list(ID = structure(c(1L, 2L, 3L, 4L, 5L),
.Label = c("1", "2", "3", "4" ,"5")),
sequence = structure(c(1L,2L, 3L, 4L, 5L),
.Label = c(" actgat "," atagattg ", " atatagag ", " atggggg ", " atgtagtt "), class = "factor"),
peptides = structure(c(1L, 2L, 3L, 4L, 5L),
.Label = c(" 54 ", " 84 ", " 32 ", " 36 ", "12"),
class = "factor"), n_project = structure(c(1L, 1L, 1L, 1L, 1L),
.Label = " project ", class = "factor")), .Names = c("ID", "sequence", "peptides", "n_project"), class = "data.frame", row.names = c(NA, -5L))
if (0!=0 && (0)!=0) {
cat("The new peptides are:\n")
kable(df)
cat("Decreased or increased:\n")
kable(df)
} else if (10==10 && 2!=0) {
cat("The new peptides are:")
kable(df)
cat("The rest peptides are the same.")
} else if (10!=10 && 2!=0) {
cat("The are not new peptides:\n")
cat("Decreased or increased:\n")
kable(df)
} else
cat("The number of peptides are the same\n")
```
しかし、私はhtml形式でそれを持ってしたいと思います。私はそれがこれよりも見栄えが良いと思う。 – Enrique
ありがとう!それは動作します! – Enrique