我正在使用R搜索原始的Twitter片段,但仍然遇到有非标准字母数字字符的问题,如下所示"̆ºÌøÑ".
我想取出所有非[abcdefghijklmnopqrstuvwxyz0123456789]字符使用gsub.
您可以使用gsub指定取代这些项目不中[abcdefghijklmnopqrstuvwxyz0123456789]?
如果该数字的每个数字的立方总和等于数字本身,则数字称为阿姆斯壮数.
例:
153 = 1 + 5^3 + 3^3
......所以,153 是阿姆斯特朗号.
142 != 1 + 4^3 + 2^3
......所以,142 不是阿姆斯特朗号.
有人可以帮我编写R中所有3位数阿姆斯特朗数的代码吗?
这可能是一个普遍的问题,我会尽力明确地描述它。在 R Shiny 和ui.R文件中,我使用radioButtons两种方法之一来选择:
radioButtons("Methods", strong("Choose a Method:"),
choices = list("method_1" = "m1",
"method_2" = "m2"),
selected="method_1"),
selectInput("method_2_ID", strong("Choose an ID (method_2"),
topIDs)
mainPanel(
tabsetPanel(
tabPanel(title = "method_1_tab1",
plotOutput("plots"),
tabPanel(title = "method_2_output1",
tableOutput("m2_output1")),
tabPanel(title = "method_2_output2",
verbatimTextOutput("m2_output2")))
))
Run Code Online (Sandbox Code Playgroud)
你可以看到对于method_2,我打算使用两个不同的标签来显示不同的结果,即m2_output1和m2_output2。在我的server.R文件中,我使用:
if (input$Methods == "method_2") {
# m2_output1
updateTabsetPanel(session, "method_2_output1", selected="panel2")
# drop-down menu
SelectedID = reactive(function(){
input$method_2_ID
})
# m2_output1
output$m2_output1 = renderTable({
m2[m2$ID == input$method_2_ID, ]
})
# m2_output2
updateTabsetPanel(session, …Run Code Online (Sandbox Code Playgroud) 我将数据框中的列设置为具有4个级别的因子
False, FALSE, True, TRUE
Run Code Online (Sandbox Code Playgroud)
我需要降低到2级
FALSE, TRUE
Run Code Online (Sandbox Code Playgroud)
我做了这个(工作正常)但是有更好的方法:
df$col1 <- as.character(df$col1) # change the factor to chr
df$col1 <- toupper (df$col1) # Ensure all are uppercase
df$col1 <- as.factor(df$col1) # change back
Run Code Online (Sandbox Code Playgroud) 这是prop.test函数:
baby.prop.test = function (x, n, p, conf.level = 0.95) {
# ...
return(prop.test(x,n,p,conf.level))
#baby.prop.test$statistic
}
# test case
baby.prop = baby.prop.test(72, 100, .7, conf.level=.99)
stopifnot(isTRUE(all.equal(as.numeric(baby.prop$statistic), .43643578)))
stopifnot(isTRUE(all.equal(as.numeric(baby.prop$p.value), .66252058)))
Run Code Online (Sandbox Code Playgroud)
这是错误:
Error in match.arg(alternative) :
'arg' must be NULL or a character vector
Run Code Online (Sandbox Code Playgroud)
知道什么是错的吗?
我曾经捣乱过R,现在一切似乎都逃过了我...
我有一个有几百列和大约100k行的表.其中一列包含有时带有逗号的字符串(例如鸡,山羊,牛或鸡).我需要一个带有(我相信)for循环的脚本,它可以创建一个新列(我知道新的列代码不应该在for循环中),计算逗号的数量(或者有问题的列中的条目数)少一个)并添加一个,以便我可以找出每列中有多少条目.一个例子:
col
chicken
chicken,goat
cow,chicken,goat
cow
Run Code Online (Sandbox Code Playgroud)
我想要一个脚本在表中创建一个看起来像的附加列...
col2
1
2
3
1
Run Code Online (Sandbox Code Playgroud) 所以我知道以下命令会在列表中存储所需长度y的所有可能组合,其中y < j:
lapply(y, function(x) combn(j,x))
Run Code Online (Sandbox Code Playgroud)
但是我不希望它们全部存储在列表中,因为稍后我将只访问它们一次,因此将它们存储在内存中效率不高.有没有办法让我可以在某种循环或其他东西中生成每个组合,然后在我完成计算后,它会给我下一个组合?所以基本上我想迭代地生成组合而不是先存储它们.
所以在伪代码中,我想拥有的是:
#loop that will generate each possible combination one by one
loop{
operation that uses combination
}
Run Code Online (Sandbox Code Playgroud)