通过学习R,我只是碰到下面的代码解释这里.
open.account <- function(total) {
list(
deposit = function(amount) {
if(amount <= 0)
stop("Deposits must be positive!\n")
total <<- total + amount
cat(amount, "deposited. Your balance is", total, "\n\n")
},
withdraw = function(amount) {
if(amount > total)
stop("You don't have that much money!\n")
total <<- total - amount
cat(amount, "withdrawn. Your balance is", total, "\n\n")
},
balance = function() {
cat("Your balance is", total, "\n\n")
}
)
}
ross <- open.account(100)
robert <- open.account(200)
ross$withdraw(30)
ross$balance() …Run Code Online (Sandbox Code Playgroud) 我试图找出我如何执行logical operators,当我使用索引中data.table package的R?
以下是示例.我datatable命名为dt.然后把它var2作为我的关键datatable:
> dt = data.table(var1 = rep(LETTERS[1:5],2), var2 = seq(1,20, 2), var3 = ceiling(rnorm(10, 3, 2)))
> dt
var1 var2 var3
1: A 1 5
2: B 3 3
3: C 5 0
4: D 7 6
5: E 9 3
6: A 11 4
7: B 13 2
8: C 15 1
9: D 17 3
10: E 19 7 …Run Code Online (Sandbox Code Playgroud) 我正在创建一个Shiny仪表板,其中dataframe包含开始经度/纬度和经度/纬度结束,我R使用以下方法绘制了leaflet package:
`m=leaflet()%>%
addTiles() %>%
addMarkers(lng=(data$Start_long[i:j]), lat=(data$Start_lat[i:j]),popup="Start") %>%
addCircleMarkers(lng=(data$End_long[i:j]), lat=(data$End_lat[i:j]),popup="End",clusterOptions=markerClusterOptions())`
Run Code Online (Sandbox Code Playgroud)
我想知道是否有办法加入由公共交通路线协调的开始和结束(可能通过谷歌地图API或库内功能或失败,加入坐标直线?
寻找一个实现,Python但我可以翻译任何东西.
如果我有string "cats ",这就是cat后跟四个空格的单词,我怎样才能找到维持单词cat顺序的所有可能的排列.那就是我不是在寻找任何排列,其中a是第一个实际的字母,或者t等,而是所有可能的字母之间的空白排列cats.
一些例子:
"cats "
"c ats "
" cat s"
"c a t s "
" c a t s"
Run Code Online (Sandbox Code Playgroud) 我想知道如何获得date difference的two column在data.table使用lapply中data.table?
library(data.table)
dt <- fread(" ID Date ME_Mes DOB
A 2017-02-20 0.0000 2016-08-19
B 2017-02-06 2.3030 2016-03-11
C 2017-03-20 0.4135 2016-08-19
D 2017-03-06 0.0480 2016-10-09
E 2017-04-20 2.4445 2016-05-04")
> dt
ID Date ME_Mes DOB
1: A 2017-02-20 0.0000 2016-08-19
2: B 2017-02-06 2.3030 2016-03-11
3: C 2017-03-20 0.4135 2016-08-19
4: D 2017-03-06 0.0480 2016-10-09
5: E 2017-04-20 2.4445 2016-05-04
###I'd like to calculate the difference in weeks for every …Run Code Online (Sandbox Code Playgroud)