标签: mode

将类别和模式从字符更改为数字

下面是一个示例数据集和几行困扰我的代码。我不知道如何将这些派生变量(年份和会话)转换为数字,以便我可以获得正确的摘要并使用“子集”函数。

##Generate sample dataset
df=data.frame(StudyAreaVisitNote=c("2006 Session 1","2006 Session 2", "2008 Session 4", "2012 Session 3"))

##Create new column denoting year and session on their own
as.factor(df$StudyAreaVisitNote)
df$Year <- substr(x = df$StudyAreaVisitNote, start = 1, stop = 4)
df$Session <- substr(x = df$StudyAreaVisitNote, start = 13, stop = 14)

##Summary of Data
summary(df)  ## Year and Session are Class and Mode "Character", summary provides little info

##Turn Year and Session into Numeric
as.numeric(df$Year)
as.numeric(df$Session)


##Try Summary of Data Again
summary(df)  ## …
Run Code Online (Sandbox Code Playgroud)

r class mode character

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

计算统计模式

我目前正在尝试验证是否存在长度为N且整数为k的未排序数组A,是否存在一些发生n/k次或更多次的元素.

我对这个问题的想法是计算模式,然后将其与n/k进行比较.但是,我不知道如何快速计算这种模式.我的最终结果需要是n log(k),但我真的不知道如何做到这一点.我能找到的最快的是 ......

algorithm statistics mode selection

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

使用C++和stat获取所有者的访问权限

如何使用Kubuntu Linux中的C++使用sys/stat.h中的stat获取文件所有者的访问权限?

目前,我得到这样的文件类型:

  struct stat results;  

  stat(filename, &results);

  cout << "File type: ";
  if (S_ISDIR(results.st_mode))
    cout << "Directory";
  else if (S_ISREG(results.st_mode))
    cout << "File";
  else if (S_ISLNK(results.st_mode))
    cout << "Symbolic link";
  else cout << "File type not recognised";
  cout << endl;
Run Code Online (Sandbox Code Playgroud)

我知道我应该使用t_mode的文件模式位,但我不知道如何.请参见sys/stat.h

c++ linux file mode stat

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

内核模式计时器

如何在内核模式下使用计时器,以便在Windows XP及更高版本中大约每秒调用驱动程序中的指定函数?我应该能够在函数中使用所有函数(特别是ZwQuerySystemInformation).我不需要高分辨率计时器或毫秒精度或类似的东西,我只需要一种方法来安排一个函数在内核模式下每秒运行一次,它必须在所有32位系统windows xp和更高版本上运行.

windows kernel driver timer mode

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

Vim:不同模式下的行号颜色不同

我刚刚开始使用Vim,我发现自己对目前处于哪种模式感到困惑.我想知道是否可以在不同模式下更改行号颜色(我默认显示)(命令,视觉,并插入)以便我可以轻松识别它.

vim mode highlighting

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

如何在生产模式下使用rails 3.1建立一个完整的"hello world"站点?

我正在努力在生产模式下设置基于rails的网站.中间目标是建立一个非常简单的网站.我使用的是Rails 3.1.0,rake 0.9.2.2和Ruby 1.9.2.

这是我尝试过的,到目前为止结果不成功:

最初,确保未设置RAILS_ENV

rails new test_project

cd test_project

rails generate scaffold User name:string email:string

rake db:migrate

rails s
Run Code Online (Sandbox Code Playgroud)

浏览到localhost:3000或localhost:3000/users

事情看起来不错.

现在,尝试将其设置为生产:

export RAILS_ENV=production

rake db:migrate

rake assets:precompile

rails s
Run Code Online (Sandbox Code Playgroud)

浏览到localhost:3000

问题: Routing Error; No route matches [GET] "/"

杀死铁轨

在config/routes中,添加 root :to => 'users#index'

rails s
Run Code Online (Sandbox Code Playgroud)

现在可以浏览到localhost:3000和localhost:3000/users

但是,rails会产生以下错误:

Started GET "/assets/application-00960e5186894b532975562d59176a6a.css" for 127.0.0.1 at 2011-11-26 23:09:44 -0800

  ActionController::RoutingError (No route matches [GET] "/assets/application-00960e5186894b532975562d59176a6a.css"):

  Started GET "/assets/application-ae30e133eabbb10d9464189d3fb71e25.js" for 127.0.0.1 at 2011-11-26 23:09:44 -0800

  ActionController::RoutingError (No route matches [GET] …
Run Code Online (Sandbox Code Playgroud)

production ruby-on-rails mode

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

检查模式是否在emacs上

如何检查当前缓冲区中是否有模式?

我为LaTeX尝试了这个,我想让对齐函数对齐&,但是只有我在LaTeX缓冲区中,而不是在ESS模式缓冲区中.

怎么检查这个?我试过了:

(if (equal reftex-mode t) (message "TRUE"))

(if (equal LaTeX-mode t) (message "TRUE"))

但reftex是全局设置的,而LaTeX的东西根本不起作用.想法?

另外,如果不启动这些变量,如何防止错误"void variable"?

emacs mode

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

Sonata Admin Bundle - configureFormFields中的不同字段选项

是否有可能在Sonata Admin Bundle Form中添加不同的字段,具体取决于您是在创建新实体还是在configureFormFields中编辑现有实体?

php forms mode symfony symfony-sonata

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

程序保持返回无,即使我没有定义

我正在研究http://learnpythonthehardway.com的额外问题.编写打开并读取文件的程序后,我尝试更改它以向open命令添加模式.但每当我这样做时,它返回None以及文件内容.

这是代码:

from sys import argv

script, filename = argv

txt = open(filename, "r")

print "Here's your file %r:" % filename
print txt.read()
print txt.close()

print "Type the filename again:"
file_again = raw_input("> ")

txt_again = open(file_again, "r")

print txt_again.read() 
print txt_again.close()
Run Code Online (Sandbox Code Playgroud)

这是打印出来的:

$ python ex15.py filey.txt
Here's your file 'filey.txt':
whatever
None
Type the filename again:
> filey.txt
whatever
None
Run Code Online (Sandbox Code Playgroud)

线条之间有斜线.

我发现了一个问题,解释说当你没有指定时,python会None自动返回.但是,当我尝试使用return命令时,或者除了print之外,它还需要一个定义.当我添加一个定义时,我无法使其余的代码工作.我怎么能摆脱这个None

我也很感激,如果有人能解释为什么它出现在"r"模式,但不是没有它.

python attributes mode

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

如何在PySpark中获取数据帧的最常见值

我熟悉Pandas数据框,我使用函数"mode"和"groupby"来获取最常见的值,如下所示

df3=df5.groupby(['band']).apply(lambda x: x.mode())
Run Code Online (Sandbox Code Playgroud)

但是我在PySpark中遇到了一些困难.

我有一个火花数据框如下:

band      A3    A5  status
4G_band1800 12  18  TRUE
4G_band1800 12  18  FALSE
4G_band1800 10  18  TRUE
4G_band1800 12  12  TRUE
4g_band2300 6   24  FALSE
4g_band2300 6   22  FALSE
4g_band2300 6   24  FALSE
4g_band2300 3   24  TRUE
Run Code Online (Sandbox Code Playgroud)

上面的截图

我想要的是如下:

band      A3    A5  status
4G_band1800 12  18  TRUE
4g_band2300 6   24  FALSE
Run Code Online (Sandbox Code Playgroud)

上面的截图

我尝试了所有可能的组合,但没有任何合理的输出.请建议一个方法.

python mode apache-spark pyspark

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