我有一个表有五列年份,收入,养老金,收入和工资.在这张表中,我使用下面的代码进行了计算:
library(dplyr)
#DATA
TEST<-data.frame(
Year= c(2000,2001,2002,2003,2004,2005,2006,2007,2008,2009,2010,2011,2012,2013,2014,2015,2016,2017,2018,2019,2020,2021),
Revenue =c(8634,5798,6022,6002,6266,6478,6732,7224,6956,6968,7098,7620,7642,8203,9856,20328,22364,22222,23250,25250,26250,27250),
Pensions =c(8734,5798,7011,7002,7177,7478,7731,7114,7957,7978,7098,7710,7742,8203,9857,10328,11374,12211,13150,15150,17150,17150),
Income =c(8834,5898,6033,6002,6366,6488,6833,8334,6956,6968,8098,8630,8642,8203,9856,30328,33364,32233,33350,35350,36350,38350),
Wages =c(8834,5598,8044,8002,8488,8458,8534,5444,8958,8988,5098,5840,5842,8203,9858,40328,44384,42244,43450,45450,48450,45450)
)
#FUNCTION
fun1 <- function(x){ ((x - lag(x))/lag(x))*100}
#CALCULATION
ESTIMATION_0<-mutate(TEST,
Nominal_growth_Revenue=fun1(Revenue),
Nominal_growth_Pensions=fun1(Pensions),
Nominal_growth_Income=fun1(Income),
Nominal_growth_Wages=fun1(Wages)
)
Run Code Online (Sandbox Code Playgroud)
但我的目的是优化此代码并使用apply函数(或类似的东西)进行此计算.即为此计算我写了4个代码行,但我喜欢用一个代码行来完成.所以有人可以帮我解决这个问题吗?
我正在使用预测包进行预测。以下是我的预测结果。
#CODE
library(forecast)
DATA_SET<-data.frame(TEST=c(200,220,200,260,300,290,320,340,360,500,200,300,400,250,350,390,400,450,470,350,300,220,580,450,120,250,360,470)
)
View(DATA_SET)
# Making TS object
TS_DATA_SET<-ts(DATA_SET,start=c(2010,1),frequency = 12)
# Forecasting
TS_FORECAST<-auto.arima(TS_DATA_SET)
Run Code Online (Sandbox Code Playgroud)
所以现在我想从 checkresiduals 函数中提取 p 值到数据框中,
#Checking residuals
checkresiduals(TS_FORECAST, plot = FALSE)
## Ljung-Box test
##
## data: Residuals from ARIMA(0,0,0) with non-zero mean
## Q* = 4.5113, df = 4.6, p-value = 0.4237
##
## Model df: 1. Total lags used: 5.6
Run Code Online (Sandbox Code Playgroud)
我正在尝试使用下面的代码,但我有问题
p-value<-data.frame(checkresiduals(TS_FORECAST, plot = FALSE))
p_value
#data frame with 0 columns and 0 rows
Run Code Online (Sandbox Code Playgroud)
那么任何人都可以帮助我如何从 checkresiduals 函数中提取 p 值(p 值 = 0.4237)到 …
我使用的数据集包含存储为字符的数字。下面您可以看到使用 dput 函数提取的数据的数据示例:
structure(list(Y_O_13_Males = c("10", "0", "0", "0", "0", "0",
"0", "0", "0", "0"), Y_O_13_Females = c("1", "0", "0", "0", "0",
"0", "0", "0", "0", "0"), Y_O_13_Unknown = c("7", "0", "0", "0",
"0", "0", "0", "0", "0", "0"), Y14_17_Males = c("2", "0", "0",
"0", "0", "0", "0", "0", "0", "0"), Y14_17_Females = c("0", "0",
"0", "0", "0", "0", "0", "0", "0", "0"), Y14_17_Unknown = c("0",
"0", "0", "0", "0", "0", "0", "0", "0", "0"), Y18_34_Males = c("0",
"0", "0", …Run Code Online (Sandbox Code Playgroud) 我正在 R 环境中使用 Jupyter。我讨厌看到来自不同 R 包的警告。为了做到这一点,我尝试了Python代码中的同一行:
import warnings
warnings.filterwarnings('ignore')
Run Code Online (Sandbox Code Playgroud)
但警告仍然存在。那么有人可以帮助我如何解决这个问题吗?
我试图提取列标题的名字,例如pack_10、pack_18和pack_20,并将它们全部用 sum 分组。下面你可以看到我的数据
df<-data.frame(
packs_10_value5=c(100,0,0,0,0),
packs_18_value9=c(200,0,0,0,0),
packs_20_value13=c(300,0,0,0,0),
packs_10_value15=c(100,0,0,0,0),
packs_18_value17=c(200,0,0,0,0),
packs_20_value18=c(300,0,0,0,0)
)
df
Run Code Online (Sandbox Code Playgroud)
那么有人可以帮我解决这个问题吗?
这是我的数据集的小例子。该集包含大约 52 周的每周数据。您可以使用以下代码查看数据:
# CODE
#Data
ARTIFICIALDATA<-dput(structure(list(week = c(1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12,
13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28,
29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44,
45, 46, 47, 48, 49, 50, 51, 52), `2019 Series_1` = c(534.771929824561,
350.385964912281, 644.736842105263, 366.561403508772, 455.649122807018,
533.614035087719, 829.964912280702, 466.035087719298, 304.421052631579,
549.473684210526, 649.719298245614, 537.964912280702, 484.982456140351,
785.929824561404, 576.736842105263, 685.508771929824, 514.842105263158, …Run Code Online (Sandbox Code Playgroud) 我正在尝试从以下网页下载一份 Word 文档。当您按下按钮时,Word文档将自动下载,而不显示任何下载链接。
现在我正在尝试使用 XPath,在 R 中下载此文档。
library(rvest)
# send an HTTP GET request to the URL
url <- "https://ec.europa.eu/taxation_customs/tedb/taxDetails.html?id=4205/1672527600"
page <- read_html(url)
# locate the link to the Word document using CSS selector
doc_link <- page %>%
html_nodes(xpath='//*[@id="action_word_export"]')%>%
html_attr("href")
Run Code Online (Sandbox Code Playgroud)
但不幸的是,这不起作用,并且无法下载任何内容。那么有人可以帮助如何解决这个问题并在R环境中下载Word文档吗?
我想用 ggplot2 绘制这些数据。下面你可以看到我的数据和代码:
library(ggplot2)
library(dplyr)
# Sample data frame (replace this with your actual dataset)
data <- data.frame(
Column1 = c(1, 2, 3, 4),
Column2 = c(5, 6, 7, 8),
Column3 = c(9, 10, 11, 12),
Column4 = c(13, 14, 15, 16)
)
# Calculate cumulative sums for each column
data <- data %>%
mutate(
Cumulative_Column1 = cumsum(Column1),
Cumulative_Column2 = cumsum(Column2),
Cumulative_Column3 = cumsum(Column3),
Cumulative_Column4 = cumsum(Column4))
Run Code Online (Sandbox Code Playgroud)
现在我尝试用下面的代码绘制这些数据:
ggplot(data, aes(x = Column1)) +
geom_area(aes(y = Cumulative_Column1, fill = "Cumulative_Column1"), alpha …Run Code Online (Sandbox Code Playgroud) 我尝试使用 ggplot 进行绘图。因此,在 R-Studio 中绘图时,evereting 是可以的。但是当我尝试制作 PDF 并将此图从 R 输出到外部时出现问题。即字母重叠。你可以在下面的图片中看到,我已经用黄色标记了。
对于绘图,我使用这行代码
# Plotting with ggplot2
p<-ggplot(data_plot, aes(x=y, y=z)) +
stat_pareto(point.color = "red",
point.size = 3,
line.color = "black",
size.line = 1,
bars.fill = c("blue", "orange")
) +
xlab(' ') +
ylab('')
# Output in pdf
pdf(file=paste("out.pdf",sep=""),width=10, height=5)
op <- par(mgp=c(1,0,0),mar=c(2, 2, 1, 1),# Room for the title and legend: 1_bottom,2_left,3_up,4_right
mfrow=c(1,2))
plot(p)
Run Code Online (Sandbox Code Playgroud)
那么任何人都可以帮助获得更好的 x 轴值、较小字体的字母或其他任何东西并修复此错误吗?
我的数据集:
dt<-data.frame(GrossIncome=seq(0, 10000, by = 1000),
Turnover= seq(0, 100000, by = 10000),
Sellers= seq(0, 1, by = 0.1),
Buyers=seq(0, 1, by = 0.1))
Run Code Online (Sandbox Code Playgroud)
所以我现在想总结这个数据并除以 1000GrossIncome和Turnover。
OUTPUT<-data.frame(
"GrossIncome"=round(sum(dt$GrossIncome)/1000,1),
"Turnover"=round(sum(dt$Turnover)/1000,1),
"GrossIncomeAndTurnover"=round(((sum(dt$Turnover)+sum(dt$Turnover))/1000),1),
"Sellers"=round(sum(dt$Sellers),1),
"Buyers"=round(sum(dt$Buyers),1))
Output
GrossIncome Turnover GrossIncomeAndTurnover Sellers Buyers
1 55 550 1100 5.5 5.5
Run Code Online (Sandbox Code Playgroud)
那么对于比上面的解决方案更优雅的解决方案有什么建议吗?我尝试使用下面的代码,但此代码仅适用于前两项(GrossIncome和Turnover),但不适用于其余项目。
dt %>%
dplyr::select(GrossIncome,Turnover)%>%
dplyr:: summarise_all(sum,na.rm=TRUE)/1000
Run Code Online (Sandbox Code Playgroud)
那么有人可以帮助我如何解决这个问题吗?
我正在使用 Keras Tuner 包。我尝试使用此处解释的示例进行超参数调整https://www.tensorflow.org/tutorials/keras/keras_tuner。代码运行得很好,但是当我开始编写代码时,但是当我尝试第二次和第三次开始时,我遇到了问题。
tuner.search(X_train, Y_train, epochs=50, validation_split=0.2, callbacks=[stop_early])
# Get the optimal hyperparameters
best_hps=tuner.get_best_hyperparameters(num_trials=1)[0]
print(f"""
The hyperparameter search is complete. The optimal number of units in the first densely-connected
layer is {best_hps.get('units')} and the optimal learning rate for the optimizer
is {best_hps.get('learning_rate')}.
""")
Run Code Online (Sandbox Code Playgroud)
第二次执行后,代码不会启动并显示上一次的结果。
INFO:tensorflow:Oracle triggered exit
The hyperparameter search is complete. The optimal number of units in the first densely-connected
layer is 128 and the optimal learning rate for the optimizer
is 0.001.
Run Code Online (Sandbox Code Playgroud)
那么知道如何解决这个问题吗?
r ×10
dplyr ×4
ggplot2 ×3
dataframe ×2
python ×2
apply ×1
forecasting ×1
keras ×1
keras-tuner ×1
pdf ×1
rvest ×1
web-scraping ×1