小编rav*_*avi的帖子

如何将 table() 转换为 r 中的矩阵

我有一个 6x6 矩阵,如下所示:

M = matrix(0,nrow = 6, ncol = 6);
for(i in 1:6)
  for(j in 1:6)
    M[i,j]<- i+j
Run Code Online (Sandbox Code Playgroud)

M 是具有元素的 6x6 矩阵:

     [,1] [,2] [,3] [,4] [,5] [,6]
[1,]    2    3    4    5    6    7
[2,]    3    4    5    6    7    8
[3,]    4    5    6    7    8    9
[4,]    5    6    7    8    9   10
[5,]    6    7    8    9   10   11
[6,]    7    8    9   10   11   12
Run Code Online (Sandbox Code Playgroud)

我想使用 r 函数 table() 从上面的矩阵 M 中导出具有频率的元素矩阵。

table(M) 的输出是: …

r matrix

7
推荐指数
2
解决办法
1万
查看次数

熊猫数据框中的唯一字符串

我有以下示例 DataFramed由两列“col1”和“col2”组成。我想找到整个 DataFrame d 的唯一名称列表。

    d = {'col1':['Pat, Joseph', 
                 'Tony, Hoffman', 
                 'Miriam, Goodwin', 
                 'Roxanne, Padilla',
                 'Julie, Davis', 
                 'Muriel, Howell', 
                 'Salvador, Reese', 
                 'Kristopher, Mckenzie',
                 'Lucille, Thornton', 
                 'Brenda, Wilkerson'],

     'col2':['Kristopher, Mckenzie', 
             'Lucille, Thornton',
             'Pete, Fitzgerald; Cecelia, Bass; Julie, Davis', 
             'Muriel, Howell', 'Harriet, Phillips',
             'Belinda, Drake;David, Ford', 'Jared, Cummings;Joanna, Burns;Bob, Cunningham',
             'Keith, Hernandez;Pat, Joseph', 'Kristopher, Mckenzie', 'Lucille, Thornton']}

    df = pd.DataFrame(data=d)
Run Code Online (Sandbox Code Playgroud)

对于列 col1,我可以使用函数 unique() 来完成它。

df.col1.unique()
array(['Pat, Joseph', 'Tony, Hoffman', 'Miriam, Goodwin',
       'Roxanne, Padilla', 'Julie, Davis', 'Muriel, Howell',
       'Salvador, Reese', 'Kristopher, …
Run Code Online (Sandbox Code Playgroud)

python pandas

4
推荐指数
1
解决办法
7372
查看次数

在r中优化嵌套for循环

我有以下r代码.它嵌套了for循环.如果i + 3行值为零,我想用NA替换数字.它适用于小型数据集,但是,对于大型数据集,它会挂起.我假设嵌套for循环不是实现它的有效方法.有人可以帮助建议增强代码,最好是tidyverse库吗?

x <- data.frame(c1=c(1,2,3,2,1,3),
                c2=c(4,5,6,2,3,4),
                c3=c(7,8,9,7,1,6),
                c4=c(4,0,9,1,5,0),
                c5=c(3,8,0,7,3,6),
                c6=c(2,8,5,0,5,7),
                row.names = c("r1","r2","r3","r4","r5","r6"))

for( i in 1:nrow(x)){
  for(j in 1:3){
    if (x[i, j+3] == 0){
      x[i, j] <- NA
    }
  }
}
Run Code Online (Sandbox Code Playgroud)

输出:x

   c1 c2 c3 c4 c5 c6
r1  1  4  7  4  3  2
r2 NA  5  8  0  8  8
r3  3 NA  9  9  0  5
r4  2  2 NA  1  7  0
r5  1  3  1  5  3  5
r6 NA  4  6  0 …
Run Code Online (Sandbox Code Playgroud)

r tidyverse

3
推荐指数
1
解决办法
309
查看次数

如何获取Firebase服务器时间戳?

我想使用Firebase模块"Firebase.ServerValue.TIMESTAMP"将日期保存到firebase服务器,并使用服务器生成的时间戳.

如何配置将firebase导入为angular2项目中的模块.

我正在使用Angular2,angular-cli,angularFire2等.以下是配置设置.

System-config.ts
/** Map relative paths to URLs. */
const map: any = {
    firebase: 'vendor/firebase/lib/firebase-web.js',
    angularfire2: ' vendor/angularfire2'
};
/** User packages configuration.*/
const packages: any = {
      angularfire2: {
        defaultExtension: 'js',
        main: 'angularfire2.js'
      }
};
Run Code Online (Sandbox Code Playgroud)

角-CLI-build.js

/* global require, module */
var Angular2App = require('angular-cli/lib/broccoli/angular2-app');
module.exports = function(defaults) {
  return new Angular2App(defaults, {
    vendorNpmFiles: [
      'systemjs/dist/system-polyfills.js',
      'systemjs/dist/system.src.js',
      'zone.js/dist/**/*.+(js|js.map)',
      'es6-shim/es6-shim.js',
      'reflect-metadata/**/*.+(js|js.map)',
      'rxjs/**/*.+(js|js.map)',
      '@angular/**/*.+(js|js.map)',

      // below are the AngularFire entries
      'angularfire2/**/*.js',
      'firebase/lib/*.js'      
    ]
  });
};
Run Code Online (Sandbox Code Playgroud)

firebase angular-cli angular

1
推荐指数
1
解决办法
3674
查看次数

如何使用 Excel VBA 获取 Windows 应用程序进程 mainwindowtitle 和窗口状态属性?

需要帮助使用Excel VBA 脚本获取 mainwindowtitle 或窗口状态属性?

在我的 Windows 机器上,我有两个进程以相同的名称运行,例如 xyz.exe。

其中一个有 Windows 应用程序,另一个是帮助程序或后台进程。我想使用 mainwindowtitle 或窗口状态属性找出哪个是 windows 应用程序进程。

之所以选择这些属性,是因为后台进程没有主窗口标题,窗口状态为空。下面是显示两个进程的进程浏览器屏幕截图。

在此处输入图片说明

对脚本和应用程序使用 WMI 任务我可以轻松找到进程 ID,但我无法弄清楚如何获取 mainwindowtitle 或窗口状态属性。

Private Sub getP()       
    strComputer = "."
    sExeName = "XYZ.exe"

    Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\CIMV2")
    Set colItems = objWMIService.ExecQuery("SELECT * FROM Win32_Process 
    WHERE Name = '" & sExeName & "'", , 48)

    For Each objItem In colItems
      Debug.Print "ProcessId: " & objItem.ProcessId
    Next
End Sub
Run Code Online (Sandbox Code Playgroud)

excel vba win32-process

1
推荐指数
1
解决办法
6093
查看次数

标签 统计

r ×2

angular ×1

angular-cli ×1

excel ×1

firebase ×1

matrix ×1

pandas ×1

python ×1

tidyverse ×1

vba ×1

win32-process ×1