我的数据集包含两列:
Date
类,因此不是字符串yyyy-mm-dd
; 我想删除2017年的所有行。
df$date > "2016-12-31"
(因此使用>符号)不断发出警告
"日期错误> " 2016年12月31日" : 比较(6)仅适用于原子和列表类型"
在很多很多方面我尝试过它。似乎只是"<"虽然这些是大多数在线解决方案,但是无法使用。知道如何以另一种方式删除特定年份的行吗?
答案 0 :(得分:4)
使用df <- df[format(df$date,'%Y') != "2017", ]
:
//-- onCreate
inAppPurchase = new InAppPurchase(this);
//--- calling on button click
inAppPurchase.purchase(this, "android.test.purchased", "123");
//--- class InAppPurchase
public class InAppPurchase {
public static final String BASE64_ENCODED_PUBLIC_KEY = "XXXXXXXXXXX"; // CONSTRUCT_YOUR_KEY_AND_PLACE_IT_HERE
public static final int RC_REQUEST = 10001;
String playStoreProductId;
IabHelper mHelper;
Activity activity;
public InAppPurchase() {
// TODO Auto-generated constructor stub
}
public InAppPurchase(Activity activity) {
// TODO Auto-generated constructor stub
mHelper = new IabHelper(activity, BASE64_ENCODED_PUBLIC_KEY);
mHelper.enableDebugLogging(true);
// Start setup. This is asynchronous and the specified listener will be called once setup completes.
Log.d("", "Starting setup.");
mHelper.startSetup(new IabHelper.OnIabSetupFinishedListener()
{
public void onIabSetupFinished(IabResult result)
{
if (!result.isSuccess())
{
Log.e("", "Problem setting up in-app billing: " + result);
}
else
{
Log.e("", "Setup successful. Querying inventory.");
}
}
});
}
public void purchase(Activity activity, String playStoreProductId, String orderId)
{
this.activity = activity;
this.playStoreProductId = playStoreProductId;
String payload = orderId;
mHelper.launchPurchaseFlow(activity, playStoreProductId, RC_REQUEST, mPurchaseFinishedListener, payload);
}
// Callback for when a purchase is finished
IabHelper.OnIabPurchaseFinishedListener mPurchaseFinishedListener = new IabHelper.OnIabPurchaseFinishedListener()
{
public void onIabPurchaseFinished(IabResult result, Purchase purchase)
{
Log.e("", "Purchase finished: " + result + ", purchase: " + purchase);
if (result.isFailure())
{
Log.e("", "Error purchasing: " + result);
}
else if(purchase.getSku().equals(playStoreProductId))
{
Log.e("", "Purchase product. Starting product consumption." + playStoreProductId);
mHelper.queryInventoryAsync(mGotInventoryListener);
}
}
};
// Listener that's called when we finish querying the items and subscriptions we own
IabHelper.QueryInventoryFinishedListener mGotInventoryListener = new IabHelper.QueryInventoryFinishedListener()
{
public void onQueryInventoryFinished(IabResult result, Inventory inventory)
{
Log.e("", "Query inventory finished.");
if (result.isFailure())
{
Log.e("", "Failed to query inventory: " + result);
}
else //if(result.isSuccess())
{
Log.e("", " else We have product. Consuming it." + playStoreProductId);
Purchase purchase = inventory.getPurchase(playStoreProductId);
if (purchase != null)
{
Log.e("", "We have product. Consuming it.");
mHelper.consumeAsync(inventory.getPurchase(playStoreProductId), mConsumeFinishedListener);
}
}
}
};
// Called when consumption is complete
IabHelper.OnConsumeFinishedListener mConsumeFinishedListener = new IabHelper.OnConsumeFinishedListener()
{
public void onConsumeFinished(Purchase purchase, IabResult result)
{
Log.e("", "Consumption finished. Purchase: " + purchase + ", result: " + result);
if (result.isSuccess())
{
// Save Data
Log.e("", "Consumption successful. Provisioning.");
}
else
{
Log.e("", "Error while consuming: " + result);
}
}
};
}
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
Log.e("", "onActivityResult(" + requestCode + "," + resultCode + "," + data);
super.onActivityResult(requestCode, resultCode, data);
if (requestCode == InAppPurchase.RC_REQUEST)
{
int responseCode = data.getIntExtra("RESPONSE_CODE", 0);
String purchaseData = data.getStringExtra("INAPP_PURCHASE_DATA");
String dataSignature = data.getStringExtra("INAPP_DATA_SIGNATURE");
Log.e("", ""+responseCode + " " + purchaseData + " " + dataSignature);
if (resultCode == RESULT_OK)
{
if(responseCode == IabHelper.BILLING_RESPONSE_RESULT_OK)
{
try
{
JSONObject jo = new JSONObject(purchaseData);
String mOrderId = jo.getString("orderId");
String mPackageName = jo.getString("packageName");
String mSku = jo.getString("productId");
long mPurchaseTime = jo.getLong("purchaseTime");
int mPurchaseState = jo.getInt("purchaseState");
String mDeveloperPayload = jo.getString("developerPayload");
String mToken = jo.optString("token", jo.getString("purchaseToken"));
}
catch (JSONException e)
{
Log.e("", "Failed to parse purchase data.");
e.printStackTrace();
}
}
else if(responseCode == IabHelper.BILLING_RESPONSE_RESULT_USER_CANCELED)
{
}
else if(responseCode == IabHelper.BILLING_RESPONSE_RESULT_SERVICE_UNAVAILABLE)
{
Toast.makeText(getApplicationContext(), "Network connection is down", 1).show();
}
}
else if (resultCode == RESULT_CANCELED)
{
Toast.makeText(getApplicationContext(), "Payment Canceled", 1).show();
}
}
}
答案 1 :(得分:3)
如果df$date
与班级Date
相符则应该有效。参见示例:
> df <- data.frame(date = as.Date(runif(10, -200, 200), origin = Sys.Date()))
> df
date
1 2017-03-02
2 2017-05-09
3 2016-09-08
4 2016-10-27
5 2016-12-03
6 2016-07-05
7 2017-02-21
8 2017-05-24
9 2016-07-04
10 2016-09-06
>
> df$date > "2016-12-31"
[1] TRUE TRUE FALSE FALSE FALSE FALSE TRUE TRUE FALSE FALSE