我有一个包含2列的数据框:日期和返回值。
df <- tibble(
date = lubridate::today() +0:9,
return= c(1,2.5,2,3,5,6.5,1,9,3,2))
Run Code Online (Sandbox Code Playgroud)
现在,我想添加第三列,条件为ifelse。如果第t天的收益大于3.5,则第二天t + 1的重运行为NA(否则=第t天的收益)。
这是我想要的输出:
date return retrun_subsequent_day
<date> <dbl> <dbl>
1 2019-03-14 1 1
2 2019-03-15 2.5 2.5
3 2019-03-16 2 2
4 2019-03-17 3 3
5 2019-03-18 5 5
6 2019-03-19 6.5 NA
7 2019-03-20 1 NA
8 2019-03-21 9 9
9 2019-03-22 3 NA
10 2019-03-23 2 2
Run Code Online (Sandbox Code Playgroud)
有人可以描述我如何制定这种条件吗?
我想用 ifelse() 条件创建几个列。这是我的示例代码:
df <- tibble(
date = lubridate::today() +0:9,
return= c(1,2.5,2,3,5,6.5,1,9,3,2))
Run Code Online (Sandbox Code Playgroud)
现在我想添加具有升序条件的新列(从 1 到 8)。第一列应该只包含来自“return”列的大于 1 的值,第二列应该只包含大于 2 的值,依此类推...
我可以使用 mutate() 函数计算每一列:
df <- df %>% mutate( `return>1`= ifelse(return > 1, return, NA))
df <- df %>% mutate( `return>2`= ifelse(return > 2, return, NA))
df <- df %>% mutate( `return>3`= ifelse(return > 3, return, NA))
df <- df %>% mutate( `return>4`= ifelse(return > 4, return, NA))
df <- df %>% mutate( `return>5`= ifelse(return > 5, return, NA))
df <- …Run Code Online (Sandbox Code Playgroud) 我正在尝试在 Fedora 平台上的 R 中安装该软件包。但是,出现以下错误消息:configure: error: GDALAllRegister not found in libgdal。
\n我不知道如何处理错误消息。\n在这篇文章中已经有同样的问题,但在 Ubuntu 平台上:\
n在 rstudio 中安装 rgdal 库 - 在 libgdal 中找不到 GDALAllRegister
\n显然有解决方案不适合我。
\n谁能帮我解决这个问题吗?
> install.packages("rgdal")\nInstalliere Paket nach \xe2\x80\x98/home/user/R/x86_64-redhat-linux-gnu-library/4.2\xe2\x80\x99\n(da \xe2\x80\x98lib\xe2\x80\x99 nicht spezifiziert)\nversuche URL \'https://cran.rstudio.com/src/contrib/rgdal_1.6-5.tar.gz\'\nContent type \'application/x-gzip\' length 4465310 bytes (4.3 MB)\n==================================================\ndownloaded 4.3 MB\n\n* installing *source* package \xe2\x80\x98rgdal\xe2\x80\x99 ...\n** Paket \xe2\x80\x98rgdal\xe2\x80\x99 erfolgreich entpackt und MD5 Summen \xc3\xbcberpr\xc3\xbcft\n** using staged installation\nconfigure: R_HOME: /usr/lib64/R\nconfigure: CC: gcc\nconfigure: CXX: g++ -std=gnu++14\nconfigure: CFLAGS: -O2 -fexceptions -g -grecord-gcc-switches -pipe -Wall -Werror=format-security …Run Code Online (Sandbox Code Playgroud)