有没有更好的方法将列表字段的名称(一般数据帧)添加为数据帧列?
df1 <- data.frame(x = 1:3, y = 3:5)
df2 <- data.frame(x = 1:3, y = 3:5)
df3 <- data.frame(x = 1:3, y = 3:5)
list = list()
list[["DF1"]] <- df1
list[["DF2"]] <- df2
list[["DF3"]] <- df3
Run Code Online (Sandbox Code Playgroud)
它工作正常,但我希望尽可能避免循环.
for (i in 1:length(list)) {
list[[i]][,"name"] <- names(list[i])
}
Run Code Online (Sandbox Code Playgroud)
我在尝试什么:
lapply(list, FUN = function(df){
df$anothername <- names(list$df) #This return colnames.
return(df)
})
Run Code Online (Sandbox Code Playgroud)
输出我想得到:
$DF1
x y name
1 1 3 DF1
2 2 4 DF1
3 3 5 DF1
$DF2
x …Run Code Online (Sandbox Code Playgroud) 所以这是一个安装到 fastapi 的示例 dash 应用程序。我正在使用 app.mount 基于官方文档fastapi-adcanced-wsgi 中的这个示例。现在我被卡住了,因为我看不到可以挂载这个 dash 应用程序并添加 fastapi 依赖项的方法
我想通过向 fastapi 路由添加单个依赖项的方式向这个 dash 子应用程序添加令牌甚至基本身份验证:
from fastapi import Depends, FastAPI
from fastapi.security import HTTPBasic, HTTPBasicCredentials
app = FastAPI()
security = HTTPBasic()
@app.get("/users/me")
def read_current_user(credentials: HTTPBasicCredentials = Depends(security)):
return {"username": credentials.username, "password": credentials.password}
Run Code Online (Sandbox Code Playgroud)
FastAPI 示例与工作破折号应用程序。
from fastapi import FastAPI
from fastapi.middleware.wsgi import WSGIMiddleware
import dash
import dash_core_components as dcc
import dash_html_components as html
import pandas as pd
from datetime import datetime
# Create the Dash application, make …Run Code Online (Sandbox Code Playgroud) 在我的降价报告中,我使用了2个块.
第一:
```{r, include = FALSE, echo=FALSE, results='asis'}```
Run Code Online (Sandbox Code Playgroud)
我加载所有包并进行计算.
第二
{r, fig.margin = TRUE, fig.width=10,
fig.height=4.5, echo=FALSE, results='asis',
message=FALSE, warning = FALSE}
Run Code Online (Sandbox Code Playgroud)
我有循环的地方我过滤数据我在第一个块中生成,并为每个我制作ggplots.
我的问题是,当我产生第二块2个地块由我结合grid.arrange他们一个网格,但有更多的评论,我不希望显示.
TableGrob (2 x 2) "arrange": 2 grobs
z cells name grob
1 1 (1-2,1-1) arrange gtable[layout]
2 2 (1-2,2-2) arrange gtable[layout]
Run Code Online (Sandbox Code Playgroud)
title: "Test"
author: "Maybe It's You"
date: "2016.09.01"
output: pdf_document
---
```{r setup, include=FALSE}
knitr::opts_chunk$set(echo = TRUE)
library(grid)
library(gridExtra)
library(ggplot2)
lay <- rbind(c(1,2),
c(1,2))
gs <- list()
```
```{r cars}
summary(cars)
```
## Including Plots …Run Code Online (Sandbox Code Playgroud) 我想从我的字符串向量中获取模式
string <- c(
"P10000101 - Przychody netto ze sprzedazy produktów" ,
"P10000102_PL - Przychody nettozy uslug",
"P1000010201_PL - Handlowych, marketingowych, szkoleniowych",
"P100001020101 - - Handlowych,, szkoleniowych - refaktury",
"- Handlowych, marketingowych,P100001020102, - pozostale"
)
Run Code Online (Sandbox Code Playgroud)
结果我想得到正则表达式的精确匹配
result <- c(
"P10000101",
"P10000102_PL",
"P1000010201_PL",
"P100001020101",
"P100001020102"
)
Run Code Online (Sandbox Code Playgroud)
我试过这个pattern = "([PLA]\\d+)"和不同的组合value = T, fixed = T, perl = T.
grep(x = string, pattern = "([PLA]\\d+(_PL)?)", fixed = T)
Run Code Online (Sandbox Code Playgroud) 今天我用highcharter包开始冒险.我对钻井图感兴趣.
(快速检查我想要创建的没有r)
R代码与2个级别的钻取图的工作示例.
library("dplyr")
library("purrr")
library("highcharter")
df <- data_frame(
name = c("Animals", "Fruits", "Cars"),
y = c(5, 2, 4),
drilldown = tolower(name)
)
df
ds <- list.parse3(df)
names(ds) <- NULL
str(ds)
hc <- highchart() %>%
hc_chart(type = "column") %>%
hc_title(text = "Basic drilldown") %>%
hc_xAxis(type = "category") %>%
hc_legend(enabled = FALSE) %>%
hc_plotOptions(
series = list(
boderWidth = 0,
dataLabels = list(enabled = TRUE)
)
) %>%
hc_add_series(
name = "Things",
colorByPoint = TRUE,
data = ds
)
dfan …Run Code Online (Sandbox Code Playgroud) r ×4
drilldown ×1
fastapi ×1
ggplot2 ×1
gridextra ×1
highcharts ×1
javascript ×1
plotly-dash ×1
python ×1
r-markdown ×1
regex ×1
rstudio ×1