我有一个data.frame如下
df <- read.table(header = T, text = "Item.Nbr supply demand
1 82078-002 1 1
2 82078-007 2 0
3 82078-007 4 0
4 82078-007 0 0
5 82078-007 0 7")
> df
Item.Nbr supply demand
1 82078-002 1 1
2 82078-007 2 0
3 82078-007 4 0
4 82078-007 0 0
5 82078-007 0 7
Run Code Online (Sandbox Code Playgroud)
我想计算Item.Nbr发生0次供需的次数,我也想知道Item.Nbr供应和需求的次数是多少次.
Item.Nbr 0_supply 0_demand 0_both
1 82078-002 0 0 0
2 82078-007 2 3 1
Run Code Online (Sandbox Code Playgroud) 我想在excel文件中对工作表进行排序.我发现这个代码有效.但问题是我的工作表名称是1_abc,2_adf,3_dasf,11_ad等.此代码将11_ad放在2_adf和3_dasf之前.我想在我的工作表名称"_"(第一个下划线)之前根据数字对工作表进行排序.我怎么能这样做?
################################ UPDATE1我修改了如下代码.但它按降序排序:(.我想按升序排序
Option Explicit
Sub SortWorksheets()
Dim N As Integer
Dim M As Integer
Dim FirstWSToSort As Integer
Dim LastWSToSort As Integer
Dim SortDescending As Boolean
SortDescending = False
If ActiveWindow.SelectedSheets.Count = 1 Then
'Change the 1 to the worksheet you want sorted first
FirstWSToSort = 1
LastWSToSort = Worksheets.Count
Else
With ActiveWindow.SelectedSheets
For N = 2 To .Count
If .Item(N - 1).Index <> .Item(N).Index - 1 Then
MsgBox "You cannot sort non-adjacent sheets"
Exit Sub …Run Code Online (Sandbox Code Playgroud) 我有一个数据框如下.我想将最后一列拆分为2.拆分需要基于唯一的第一列完成:其余的列不重要.
在新数据框中,将有4列.第3列为(a,b,d),第4列为(1,2:3,3:4:4)
有什么建议?我的代码的第4行不起作用:(.我可以使用全新的解决方案或对第4行进行更正
employee <- c('John Doe','Peter Gynn','Jolie Hope')
salary <- c(3, 2, 1)
df <- data.frame(employee, salary, originalColumn = c("a :1", "b :2:3", "d: 3:4:4"))
as.data.frame(do.call(rbind, strsplit(df,":")))
Run Code Online (Sandbox Code Playgroud)
-------------------- UPDATE1
以下解决方案效果很好 但我需要一个修改过的解决方案,因为我刚刚意识到第3列中的某些单元格不会有":".在这种情况下,我希望该单元格中的文本在拆分该列后仅出现在第一列中
employee <- c('John Doe','Peter Gynn','Jolie Hope')
salary <- c(3, 2, 1)
df <- data.frame(employee, salary, originalColumn = c("a :1", "b", "d: 3:4:4"))
Run Code Online (Sandbox Code Playgroud) 我想安装 pptx 包,我在下面尝试过。我的主要目标是运行本页底部提供的代码。
我有最新版本的 PIP,我收到消息
Collecting pptx
Could not find a version that satisfies the requirement pptx (from versions: )
No matching distribution found for pptx
(C:\ProgramData\Anaconda3) C:\WINDOWS\system32>easy_install -U pip
Searching for pip
Reading https://pypi.python.org/simple/pip/
Best match: pip 18.0
Processing pip-18.0-py3.6.egg
pip 18.0 is already the active version in easy-install.pth
Installing pip-script.py script to C:\ProgramData\Anaconda3\Scripts
Installing pip.exe script to C:\ProgramData\Anaconda3\Scripts
Installing pip3-script.py script to C:\ProgramData\Anaconda3\Scripts
Installing pip3.exe script to C:\ProgramData\Anaconda3\Scripts
Installing pip3.6-script.py script to C:\ProgramData\Anaconda3\Scripts
Installing pip3.6.exe script …Run Code Online (Sandbox Code Playgroud) r ×2
delimiter ×1
excel ×1
excel-vba ×1
installation ×1
python ×1
python-pptx ×1
split ×1
vba ×1