- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我有这个数据:
merged_dat1
# A tibble: 4 x 35
# Groups: Product.Name [4]
Product.Name also apps battery better big camera case cheap day definitely enough even however
<chr> <int> <int> <int> <int> <int> <int> <int> <int> <int> <int> <int> <int> <int>
1 BLU Studio ~ 498 545 1552 465 306 839 406 161 413 225 156 590 178
2 iphone 4s 71 37 380 43 19 13 21 38 43 25 16 128 52
3 Motorola Mo~ 160 221 253 123 69 428 39 125 101 49 157 133 79
4 Samsung Gal~ 76 70 122 49 25 69 22 17 31 15 53 71 31
# ... with 21 more variables: issues <int>, life <int>, little <int>, long <int>, lot <int>, low <int>,
# many <int>, memory <int>, much <int>, overall <int>, phones <int>, pictures <int>, pretty <int>,
# quality <int>, right <int>, screen <int>, size <int>, still <int>, use <int>, way <int>, well <int>
15044
.第一行的每个值都应该除以这个值。这可能是重复的,但我找不到关于此的主题。如果有人有
dplyr
就好了解决方案。
structure(list(Product.Name = c("BLU Studio 5.0", "iphone 4s",
"Motorola Moto E", "Samsung Galaxy II"), also = c(498L, 71L,
160L, 76L), apps = c(545L, 37L, 221L, 70L), battery = c(1552L,
380L, 253L, 122L), better = c(465L, 43L, 123L, 49L), big = c(306L,
19L, 69L, 25L), camera = c(839L, 13L, 428L, 69L), case = c(406L,
21L, 39L, 22L), cheap = c(161L, 38L, 125L, 17L), day = c(413L,
43L, 101L, 31L), definitely = c(225L, 25L, 49L, 15L), enough = c(156L,
16L, 157L, 53L), even = c(590L, 128L, 133L, 71L), however = c(178L,
52L, 79L, 31L), issues = c(334L, 49L, 60L, 23L), life = c(649L,
60L, 136L, 25L), little = c(283L, 45L, 156L, 44L), long = c(197L,
49L, 65L, 25L), lot = c(316L, 35L, 107L, 39L), low = c(203L,
25L, 116L, 24L), many = c(207L, 32L, 77L, 51L), memory = c(200L,
10L, 148L, 48L), much = c(421L, 79L, 165L, 53L), overall = c(206L,
35L, 77L, 8L), phones = c(749L, 84L, 214L, 63L), pictures = c(263L,
12L, 94L, 32L), pretty = c(332L, 25L, 97L, 31L), quality = c(669L,
40L, 186L, 49L), right = c(189L, 49L, 45L, 33L), screen = c(1359L,
71L, 252L, 82L), size = c(244L, 7L, 93L, 55L), still = c(416L,
48L, 107L, 28L), use = c(650L, 126L, 256L, 140L), way = c(218L,
40L, 44L, 12L), well = c(605L, 103L, 205L, 114L)), class = c("grouped_df",
"tbl_df", "tbl", "data.frame"), row.names = c(NA, -4L), vars = "Product.Name", drop = TRUE, indices = list(
0L, 1L, 2L, 3L), group_sizes = c(1L, 1L, 1L, 1L), biggest_group_size = 1L, labels = structure(list(
Product.Name = c("BLU Studio 5.0", "iphone 4s", "Motorola Moto E",
"Samsung Galaxy II")), class = "data.frame", row.names = c(NA,
-4L), vars = "Product.Name", drop = TRUE))
最佳答案
我们可以先创建一个 rowSums
列,然后再做 mutate_if
library(tidyverse)
merged_dat1 %>%
as.data.frame %>%
mutate(newSum = select_if(., is.numeric) %>%
reduce(`+`)) %>%
mutate_if(is.numeric, list(~ ./newSum)) %>%
select(-newSum)
# Product.Name also apps battery better big camera case cheap
#1 BLU Studio 5.0 0.03310290 0.03622707 0.10316405 0.03090933 0.020340335 0.055769742 0.02698750 0.01070194
#2 iphone 4s 0.03717277 0.01937173 0.19895288 0.02251309 0.009947644 0.006806283 0.01099476 0.01989529
#3 Motorola Moto E 0.03450507 0.04766013 0.05456114 0.02652577 0.014880311 0.092301057 0.00841061 0.02695708
#4 Samsung Galaxy II 0.04662577 0.04294479 0.07484663 0.03006135 0.015337423 0.042331288 0.01349693 0.01042945
# day definitely enough even however issues life little long lot
#1 0.02745281 0.014956129 0.010369583 0.03921829 0.01183196 0.02220154 0.04314012 0.01881149 0.01309492 0.02100505
#2 0.02251309 0.013089005 0.008376963 0.06701571 0.02722513 0.02565445 0.03141361 0.02356021 0.02565445 0.01832461
#3 0.02178132 0.010567177 0.033858098 0.02868234 0.01703688 0.01293940 0.02932931 0.03364244 0.01401768 0.02307526
#4 0.01901840 0.009202454 0.032515337 0.04355828 0.01901840 0.01411043 0.01533742 0.02699387 0.01533742 0.02392638
# low many memory much overall phones pictures pretty quality right
#1 0.01349375 0.01375964 0.013294337 0.02798458 0.013693167 0.04978729 0.017482053 0.02206860 0.04446956 0.01256315
#2 0.01308901 0.01675393 0.005235602 0.04136126 0.018324607 0.04397906 0.006282723 0.01308901 0.02094241 0.02565445
#3 0.02501617 0.01660556 0.031917188 0.03558335 0.016605564 0.04615053 0.020271727 0.02091870 0.04011214 0.00970455
#4 0.01472393 0.03128834 0.029447853 0.03251534 0.004907975 0.03865031 0.019631902 0.01901840 0.03006135 0.02024540
# screen size still use way well
#1 0.09033502 0.016219091 0.02765222 0.04320659 0.014490827 0.04021537
#2 0.03717277 0.003664921 0.02513089 0.06596859 0.020942408 0.05392670
#3 0.05434548 0.020056071 0.02307526 0.05520811 0.009488894 0.04420962
#4 0.05030675 0.033742331 0.01717791 0.08588957 0.007361963 0.06993865
base R
,这可以紧凑地完成
merged_dat1[-1] <- merged_dat1[-1]/rowSums(merged_dat1[-1])
关于r - 将每一行除以其总和,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55816037/
我想要以下代码的 Python 单行解决方案,但是怎么做呢? total = 0 for ob in self.oblist: total += sum(v.amount for v in o
今天和大家一起学习一种可视化技术:构建树状热力图treemap。树形图易于可视化,且易于被人理解。树状图通过展示不同大小的矩形,以传达不同大小的数据量,一般认为,较大的矩形意味着占总体的一大部分,而较
就目前而言,这个问题不适合我们的问答形式。我们希望答案得到事实、引用或专业知识的支持,但这个问题可能会引起辩论、争论、投票或扩展讨论。如果您觉得这个问题可以改进并可能重新打开,visit the he
我有一个声明 $set eq "Y" ? $set = "N" : $set = "Y"; 但不管它总是设置为 "N" # Toggle setting if ($set eq "Y") { $
当我尝试在我的服务器上上传一个 php 文件时,我收到一条消息:"Parse error: ..." 我知道这是什么意思,但问题是别的。 如果我在本地服务器上编辑文件(我的计算机上安装了 XAMPP)
我是 python oneliner 循环的新手。 我希望用户将数据输入到二维列表中,同时提醒他他们将输入的数据索引。我的代码是: flag=0 x=[[int(input("enter the "+
尝试在变量之前和之后打印字符串。C 是否有能力使用一条语句来显示此输出? 这有效: float value = 5; printf("\nThe value of %f", value); print
我正在验证我创建的 MySQL 数据库的结果,为此,我需要一些屏幕截图。 例如,以下查询: select distinct run_ID from ngsRunStats_FK.failedRuns
有人可以解释一下这个 JS LINE 吗?数据是一个对象。 var list = data == null ? [] : (data.wine instanceof Array ? data.wine
如何在一行中添加三个下拉菜单。我想把我的日、月和年放在一行中,但不能这样做。任何帮助将不胜感激。我附上我的 jsfiddle . .... 最佳
我正在尝试使用 html 将 iframe 的高度设置为 100%(我已成功完成),但我还在顶部添加了一行额外的文本,所以它太高了 ~16px(这需要一个滚动条)。有没有办法更改 iframe 以显示
这是一个示例,我从文件中读取行作为字符串,以使整个文件作为字符串数组: String[] ArrayOfStrings = (new Scanner( new File("log.txt") ).us
我有一个包含大量定义的配置文件,用于在编译期间包含模块。此外,这意味着我必须经常检查代码内部的定义。每张支票需要 3 行,是否可以在一行中执行此操作。 #if FUNC_ENABLED functio
我正在尝试制作一个水平列表,其中每个 列表中的 s 的高度为 385px,宽度为 400px。 我尝试使用 inline-block 使列表水平排列,但这似乎不起作用。也就是说,我的意思是列表仍然是垂
这很烦人,我有一个带有 css 文件的 wordpress 主题,所有内容都在一长行中。我想知道为什么有人会那样做。现在我已经升级了,我需要将旧文件与新文件进行比较,以便我可以接受更改。 Meld、d
我有一个对象数组,其中每个对象都有一个 search_order 属性。我要检查数组并将所有对象的属性增加 1这是简单的方法: res = [] for r in array: r.searc
我在某些服务器上遇到许多具有相同内容和相同名称的文件。我需要隔离这些文件进行分析,所以我不能只删除重复项。操作系统为Linux(centos和ubuntu)。 我枚举文件名和位置并将它们放入文本文件中
你能在不抛出错误的情况下解决这个问题吗?答案是单线。这是来自一个死的职位发布,在回复中要求回答。我认为这是剔除受访者的聪明方法,但我似乎无法在不出错的情况下回答它。 显而易见的解决方案: f.moo(
这个问题在这里已经有了答案: Is it ok if I omit curly braces in Java? [closed] (16 个答案) 关闭 9 年前。 我在 java 中使用没有大括号
我在这里试图用 python 制作一个简单的计算器,我想知道是否可以在命令运行时将前 3 行合并为一行。我的意思是;我不必按 Enter 键来键入下一个数字/运算符,而是按空格键(在输入部分)。 wh
我是一名优秀的程序员,十分优秀!