我有一个数据框,如下所示(数据列在问题末尾):
可以看出,我想突出显示最终R-Markdown报告中的几个单元格以供演示。我当前的代码只能显示表格:
cluster_summary%>% kbl(caption = '<b>Clustering results</b>') %>%
kable_classic(full_width = F, html_font = "Cambria")
Run Code Online (Sandbox Code Playgroud)
我怎样才能突出显示这些单元格?
数据
structure(list(cluster = structure(1:7, .Label = c("1", "2",
"3", "4", "5", "6", "7"), class = "factor"), n = c(512L, 1048L,
662L, 1968L, 576L, 1738L, 1188L), ave_price_per_sqft_adjusted = c(5.16299733157459,
3.32371811588978, 3.96858531607868, 3.32922072520205, 3.42896017156734,
4.16418851265888, 4.08627345683475), ave_age = c(12.0393129995492,
12.6062546474121, 9.32033699503113, 25.5092197801581, 19.1151284494788,
12.2180810585854, 12.0248580167839), ave_DOM = c(47.706537201211,
42.0442099665614, 49.9960193152193, 34.2190863941281, 44.5416652882415,
37.1891219996921, 33.3872422432855), ave_activity_rate = c(1.20118970114087,
1.14598100690658, 1.47458159497434, 1.58286371628597, 1.31320615630511,
1.32586511589676, 2.90376115653893), topic_1 = …Run Code Online (Sandbox Code Playgroud) 我有一个数据框,我想清理包含字符形式的价格的列。我想删除 $ 符号和,分隔符并将这些列作为数字。
structure(list(Sold.Price = c("", "$177,500", "$180,000", "$180,000",
"$189,000"), Title.to.Land = c("Freehold Strata", "Freehold Strata",
"Freehold Strata", "Freehold Strata", "Freehold Strata"), Price = c("$174,900",
"$177,500", "$180,000", "$180,000", "$189,000"), DOM = c(93L,
34L, 39L, 56L, 2L), List.Date = c("10/4/2019", "12/12/2019",
"12/9/2019", "11/12/2019", "1/9/2020"), MaintFee = c("$2,916.00",
"$373.80", "$331.57", "$320.42", "$1,055.67")), row.names = c(NA,
5L), class = "data.frame")
Sold.Price Title.to.Land Price DOM List.Date MaintFee
1 Freehold Strata $174,900 93 10/4/2019 $2,916.00
2 $177,500 Freehold Strata $177,500 34 12/12/2019 $373.80 …Run Code Online (Sandbox Code Playgroud) 我有一个有 9 列和 20 行的数据框。如下图所示的数据框图片:(
数据在本题末尾使用dput函数提供)
从第一个单词 (fireplace_balconi) 可以看出,8 个数字显示在第一列到第八列中。我想要做的是在每列中找到前 5 个数字,并在单独的数据框中从单词列中显示它们对应的单词。
例如,在第 1 列中,最上面的数字是 6.61 e-4,这个数字对应的词是 pool_exercis。
我可以通过以下代码为每一列分别执行此操作:
data2 <- data[,c(1,9)]
data3 <- arrange(data2, desc(t_1))
Run Code Online (Sandbox Code Playgroud)
然后选择前 5 个单词,但我想在一个步骤中对所有列执行此操作,并将输出作为数据帧。我怎样才能做到这一点?
数据:
structure(list(t_1 = c(0.000130787327029859, 2.04812368950562e-06,
0.000279032470270266, 9.75296995002676e-08, 8.78742592497411e-05,
9.75296995002676e-08, 0.000661348892311314, 8.59236652597357e-05,
0.000189305146730019, 9.75296995002676e-08, 6.44671313696769e-05,
9.75296995002676e-08, 9.75296995002676e-08, 4.3010597479618e-05,
7.81212892997143e-05, 0.000353155041890469, 4.69117854596287e-05,
9.75296995002676e-08, 9.75296995002676e-08, 9.75296995002676e-08
), t_2 = c(0.000237523589560676, 7.19550407636099e-08, 7.19550407636099e-08,
7.19550407636099e-08, 0.000120956423523628, 0.000382872771903168,
7.19550407636099e-08, 0.000413093889023885, 9.36135080334565e-05,
7.19550407636099e-08, 1.15847615629412e-05, 4.18058786836574e-05,
7.05878949891013e-05, 3.02930721614798e-05, 2.95015667130801e-06,
7.19550407636099e-08, 0.000182837758580333, 2.88539713462076e-05,
0.000502318139570761, 0.000428923997991879), t_3 …Run Code Online (Sandbox Code Playgroud)