通过数据框中两个字符类型行的组合来创建新行

时间:2019-07-02 21:33:03

标签: r dataframe dplyr

我具有以下数据集的大版本。

[12:32:24]: All required keys, certificates and provisioning profiles are installed ?
[⠋] ? [⠙] ? [⠹] ? [⠸] ? [⠼] ? [⠴] ? [⠦] ? [✔] ?
[12:32:27]: Could not find fastlane in current directory. Make sure to have your fastlane configuration files inside a folder called "fastlane". Would you like to set fastlane up?

Looking for related GitHub issues on fastlane/fastlane...

➡️ Fastlain Android screengrab. Could not retrieve response as fastlane runs in non-interactive mode
#14869 [open] 4 ?
2 weeks ago

➡️ FastLane 2.124 FastlaneCore::Interface::FastlaneCrash: [!] Could not retrieve response as fastlane runs in non-interactive mode
#14835 [open] 4 ?
2 weeks ago

➡️ Supply isn't working on CI with Google auth .p12 files
#14128 [closed] 2 ?
20 Apr 2019

and 36 more at: https://github.com/fastlane/fastlane/search?q=Could%20not%20retrieve%20response%20as%20fastlane%20runs%20in%20non-interactive%20mode&type=Issues&utf8=✓

? You can ⌘ + double-click on links to open them directly in your browser.
bundler: failed to load command: fastlane (/usr/local/bin/fastlane)
FastlaneCore::Interface::FastlaneCrash: [!] Could not retrieve response as fastlane runs in non-interactive mode
/Library/Ruby/Gems/2.3.0/gems/fastlane-2.126.0/fastlane_core/lib/fastlane_core/ui/interface.rb:129:in crash!' /Library/Ruby/Gems/2.3.0/gems/fastlane-2.126.0/fastlane_core/lib/fastlane_core/ui/implementations/shell.rb:155:in verify_interactive!'
/Library/Ruby/Gems/2.3.0/gems/fastlane-2.126.0/fastlane_core/lib/fastlane_core/ui/implementations/shell.rb:133:in confirm' /Library/Ruby/Gems/2.3.0/gems/fastlane-2.126.0/fastlane_core/lib/fastlane_core/ui/ui.rb:17:in method_missing'
/Library/Ruby/Gems/2.3.0/gems/fastlane-2.126.0/fastlane/lib/fastlane/commands_generator.rb:343:in ensure_fastfile' /Library/Ruby/Gems/2.3.0/gems/fastlane-2.126.0/fastlane/lib/fastlane/commands_generator.rb:107:in block (2 levels) in run'
/Library/Ruby/Gems/2.3.0/gems/commander-fastlane-4.4.6/lib/commander/command.rb:178:in call' /Library/Ruby/Gems/2.3.0/gems/commander-fastlane-4.4.6/lib/commander/command.rb:153:in run'
/Library/Ruby/Gems/2.3.0/gems/commander-fastlane-4.4.6/lib/commander/runner.rb:476:in run_active_command' /Library/Ruby/Gems/2.3.0/gems/fastlane-2.126.0/fastlane_core/lib/fastlane_core/ui/fastlane_runner.rb:76:in run!'
/Library/Ruby/Gems/2.3.0/gems/commander-fastlane-4.4.6/lib/commander/delegates.rb:15:in run!' /Library/Ruby/Gems/2.3.0/gems/fastlane-2.126.0/fastlane/lib/fastlane/commands_generator.rb:333:in run'
/Library/Ruby/Gems/2.3.0/gems/fastlane-2.126.0/fastlane/lib/fastlane/commands_generator.rb:41:in start' /Library/Ruby/Gems/2.3.0/gems/fastlane-2.126.0/fastlane/lib/fastlane/cli_tools_distributor.rb:119:in take_off'
/Library/Ruby/Gems/2.3.0/gems/fastlane-2.126.0/bin/fastlane:23:in <top (required)>' /usr/local/bin/fastlane:22:in load'
/usr/local/bin/fastlane:22:in `<top (required)>'
Exited with code 1

我希望将前两行组合在一起,以便得到的数据集看起来像这样

mydata <- data.frame("C1" = c("EB", "L", 1, 2, 3) ,
                            "C2" = c("WB", "T", 4, 5, 6),
                            "C3" = c("NB", "R", 7, 8, 9),
                            "C4" = c("SB", "Total", 12, 15, 18),
                            "C5" = c("", "L",1, 2, 3),
                            "C6" = c("", "TR", 4, 5, 6),
                            "C7" = c("", "Total", 5, 7, 9),
                            "C8" = c("", "L",1, 2, 3),
                            "C9" = c("", "R", 4, 5, 6),
                            "C10" = c("", "Total", 5, 7, 9),
                            "C11" = c("", "L",1, 2, 3),
                            "C12" = c("", "TR", 4, 5, 6),
                            "C13" = c("", "Total", 5, 7, 9), stringsAsFactors = FALSE)

> mydata
  C1 C2 C3    C4 C5 C6    C7 C8 C9   C10 C11 C12   C13
1 EB WB NB    SB                                      
2  L  T  R Total  L TR Total  L  R Total   L  TR Total
3  1  4  7    12  1  4     5  1  4     5   1   4     5
4  2  5  8    15  2  5     7  2  5     7   2   5     7
5  3  6  9    18  3  6     9  3  6     9   3   6     9

基本上,我想保留其余的数据框。

请注意:这种情况来自具有1000条记录和18个列的非常大的数据集。任何帮助都感激不尽。预先感谢!

更新: 我尝试过

    > myresult
   C1  C2  C3      C4  C5   C6      C7  C8  C9     C10 C11  C12     C13
1 EBL EBT EBR EBTotal WBL WBTR WBTotal NBL NBR NBTotal SBL SBTR SBTotal
2   1   4   7      12   1    4       5   1   4       5   1    4       5
3   2   5   8      15   2    5       7   2   5       7   2    5       7
4   3   6   9      18   3    6       9   3   6       9   3    6       9

但这只是从第一行重复一个值

mydata[1,]= paste0(rep(mydata[1,], each = length(mydata[2,])), mydata[2,])

2 个答案:

答案 0 :(得分:2)

查看数据,您似乎想要将第一行组合粘贴到第二行,直到值<input type="text" id="inputName" placeholder="Enter name" required oninvalid="this.setCustomValidity('Your Message')" oninput="this.setCustomValidity('') /> 进入第二行。我们可以分别提取第一行和第二行,根据"Total"的出现split对其进行粘贴,然后将其粘贴到"Total"以获得新值。

first_row

答案 1 :(得分:1)

您必须重复“ EB”四次,其他仅重复三遍。我认为现在是正确的:

colnames(mydata) <- paste0(c(rep(mydata[1,1], 4), rep(mydata[1, 2:4], each = 3)), mydata[2,])
mydata2 <- apply(mydata[-c(1:2),], 2, as.numeric)

> mydata2
     EBL EBT EBR EBTotal WBL WBTR WBTotal NBL NBR NBTotal SBL SBTR SBTotal
[1,]   1   4   7      12   1    4       5   1   4       5   1    4       5
[2,]   2   5   8      15   2    5       7   2   5       7   2    5       7
[3,]   3   6   9      18   3    6       9   3   6       9   3    6       9