如何让POSIXct与==一起使用(How to get POSIXct to work with ==)
我注意到
==
似乎不适用于POSIXct:a <- structure(c(1466985600, 1464652800, 1464652800, 1464652800, 1472428800, 1466985600, 1468195200, 1472428800, 1472428800, 1474848000, 1464652800, 1468195200, 1476057600, 1464652800, 1472428800, 1472428800, 1460332800, 1460332800, 1460332800, 1460332800), class = c("POSIXct", "POSIXt" ), tzone = "UTC") a
[1]“2016-06-27 UTC”“2016-05-31 UTC”“2016-05-31 UTC”“2016-05-31 UTC”“2016-08-29 UTC”“2016-06-27 UTC “”2016-07-11 UTC“”2016-08-29 UTC“[9]”2016-08-29 UTC“”2016-09-26 UTC“”2016-05-31 UTC“”2016-07-11 UTC“”2016-10-10 UTC“”2016-05-31 UTC“”2016-08-29 UTC“”2016-08-29 UTC“[17]”2016-04-11 UTC“”2016-04- 11 UTC“”2016-04-11 UTC“”2016-04-11 UTC“
table(a=="2016-06-27")
FALSE 20
table(a=="2016-06-27 UTC")
FALSE 20
table(a==as.POSIXct("2016-06-27 UTC"))
FALSE 20
table(a==as.POSIXct("2016-06-27"))
FALSE 20
a[a=="2016-06-27"]
character(0)
我怎样才能让它发挥作用?
这可行,但我真的希望这不是我唯一的选择:
a[a==1466985600]
[1] "2016-06-27 UTC" "2016-06-27 UTC"
I've noticed that
==
doesn't seem to work with POSIXct:a <- structure(c(1466985600, 1464652800, 1464652800, 1464652800, 1472428800, 1466985600, 1468195200, 1472428800, 1472428800, 1474848000, 1464652800, 1468195200, 1476057600, 1464652800, 1472428800, 1472428800, 1460332800, 1460332800, 1460332800, 1460332800), class = c("POSIXct", "POSIXt" ), tzone = "UTC") a
[1] "2016-06-27 UTC" "2016-05-31 UTC" "2016-05-31 UTC" "2016-05-31 UTC" "2016-08-29 UTC" "2016-06-27 UTC" "2016-07-11 UTC" "2016-08-29 UTC" [9] "2016-08-29 UTC" "2016-09-26 UTC" "2016-05-31 UTC" "2016-07-11 UTC" "2016-10-10 UTC" "2016-05-31 UTC" "2016-08-29 UTC" "2016-08-29 UTC" [17] "2016-04-11 UTC" "2016-04-11 UTC" "2016-04-11 UTC" "2016-04-11 UTC"
table(a=="2016-06-27")
FALSE 20
table(a=="2016-06-27 UTC")
FALSE 20
table(a==as.POSIXct("2016-06-27 UTC"))
FALSE 20
table(a==as.POSIXct("2016-06-27"))
FALSE 20
a[a=="2016-06-27"]
character(0)
How can I get this to work?
This would work, but I really hope it's not my only option:
a[a==1466985600]
[1] "2016-06-27 UTC" "2016-06-27 UTC"
原文:https://stackoverflow.com/questions/40662112
最满意答案
你可以使用这样一个简单的循环:
#include "stdafx.h" #include <stdio.h> #include <iostream> #include <string> using namespace std; int main() { string answer = ""; while(answer != "exit") { cout << "What do you want to learn?"; cin >> answer; if (answer = "show") cout << "You have been shown the light"; } return 0; }
请记住,这是一个伪代码示例,您应该能够从此处继续使用在线可用的大量资源来查找正确的语法,以使其处于正常工作状态。
这是一个很棒的网站,可以在您学习c ++的过程中参考
You could make use of a simple loop such as this:
#include "stdafx.h" #include <stdio.h> #include <iostream> #include <string> using namespace std; int main() { string answer = ""; while(answer != "exit") { cout << "What do you want to learn?"; cin >> answer; if (answer = "show") cout << "You have been shown the light"; } return 0; }
Keeping in mind that this is a pseudo code example, you should be able to continue from here and use the vast amount of resources available online to find the correct syntax to get this in working order.
Here's a great website to reference throughout your journey learning c++
相关问答
更多-
您可以使用Cordova“暂停”事件,该事件会在您的应用程序发送到后台时触发。 document.addEventListener("pause", yourCallbackFunction, false); http://docs.phonegap.com/en/2.9.0/cordova_events_events.md.html#pause 但是,您需要查看iOS怪癖以确保它们适合您的用例。 You can use the Cordova "pause" event, which is trigger ...
-
您需要挂接到控制台退出事件而不是您的进程。 http://geekswithblogs.net/mrnat/archive/2004/09/23/11594.aspx 捕获控制台退出C# You need to hook to console exit event and not your process. http://geekswithblogs.net/mrnat/archive/2004/09/23/11594.aspx Capture console exit C#
-
(1)如何安全地退出C ++控制台应用程序,(How to safely exit C++ console application while working inside while(1))[2022-09-25]
RAII是你的朋友。 把你的init / uninit包含在一个保证在作用域结束时被破坏的对象中。 例: class Initializer { public: Initializer() { initLibrary(); } ~Initializer() { deInitLibrary(); } }; int wmain() { Initializer init; while (1) { ... -
我该如何退出我的应用程序?(How can I exit from my app?)[2023-10-27]
在这个方法中你可以在任何地方调用exit()函数并从应用程序退出。 所以要在任何时候关闭应用程序,请在Intent中使用FLAG_ACTIVITY_CLEAR_TOP标志,然后使用system.exit(); 注意:我认为它不会打破Android生命周期 在您需要从应用程序执行EXIT的位置 public void exit() { startActivity(new Intent(this, HomeActivity.class). setFlags(Intent.FLAG_ACTIVIT ... -
当用户在C ++控制台应用程序中输入“退出”时,我将如何退出应用程序?(When user inputs “exit” in C++ console app, how would I exit the app?)[2022-02-27]
你可以使用这样一个简单的循环: #include "stdafx.h" #include#include #include using namespace std; int main() { string answer = ""; while(answer != "exit") { cout << "What do you want to learn?"; cin >> answer; if (answ ... -
看看那个MSDN论坛链接,似乎C ++ / DirectX中的后退按键逻辑与C#/ XAML的工作方式相同。 即如果设置处理标志command->Handled = true; 在Back键按下处理程序中,应用程序框架不会关闭应用程序。 如果您未设置标志,那么应用程序框架将关闭该应用程序。 Looking at that MSDN forum link it seems that the back key press logic in C++/DirectX works in the same way as ...
-
当用户按下“返回”时,Android不会停止应用程序。 应用程序将保留在内存中,直到Android需要内存用于其他应用程序。 当用户按下“后退”时正在运行的任何线程将继续运行。 传统上,您应该在Activity的onPause()方法上停止所有这些进程(另外,存储所有首选项和其他清理。) 此外,如果您已经启动了Service (如上所述),那么它将继续运行,直到您告诉它停止。 在极少数情况下,Android会杀死一个Service以释放资源,但在大多数情况下你必须杀死它。 Android won't sto ...
-
你可以在你的Application子类中添加onBackPressed()来拦截后退按钮: public static void onBackPressed(final Activity activity) { AlertDialog.Builder builder = new AlertDialog.Builder(activity); builder.setTitle(R.string.on_back_button_title); builder.setMessage(R.str ...
-
谢谢乔纳森的小费。 我看到处理程序是在它自己的线程上调用的。 如果处理程序返回,则整个进程被强制退出,因此我们需要给主线程时间自己退出。 bool done = false; BOOL ctrl_handler(DWORD event) { if (event == CTRL_CLOSE_EVENT) { done = true; Sleep(20000); // force exit after 20 seconds return TRUE; ...
-
当您在发送过程中输入exit ,它会跳出循环,关闭其管道末端并退出。 当另一个进程尝试从管道读取时,它将获得一个EOF,由read()返回0 。 但是,您的代码从不检查这一点,它只在read()或write()返回一个负值来指示错误(EOF不是错误)时退出。 因此它返回到循环的顶部并要求输入发送到其他进程。 当它试图写入封闭的管道时,它会得到一个EPIPE错误或一个SIGPIPE信号,然后它将退出。 将您的阅读代码更改为: int n = read(readpipe[0],buf,sizeof(buf)); ...