删除嵌套在列表中的非匹配数据框名称

时间:2019-03-04 16:16:53

标签: r

我有两个由数据帧组成的列表-df_quintile和disease_df_quintile。我不知道如何简洁地表示它们,但这是它们在Rstudio中的外观:

enter image description here

enter image description here

注意,疾病_df_quintile由5个数据帧(数据帧1至5)组成,而疾病_df_quintile由4个数据帧(2至5数据帧)组成。我想交叉检查两个列表,并删除两个列表都不共享的任何数据帧-因此,在这种情况下,我想从df_quintile列表中删除第一个数据帧。我该如何实现?

谢谢。

2 个答案:

答案 0 :(得分:1)

与列表内容无关,您可以首先找到重复的名称,然后对列表进行子设置:

public class HandleAndLogErrorAttribute : HandleErrorAttribute
{
    public override void OnException(ExceptionContext filterContext)
    {
        if (filterContext.ExceptionHandled || !filterContext.HttpContext.IsCustomErrorEnabled)
            return;
        var statusCode = filterContext.HttpContext.Response.StatusCode; //always 200
        LogManager.Error(filterContext.Exception);

        filterContext.Result = CreateActionResult(filterContext, statusCode);
        filterContext.ExceptionHandled = true;
        filterContext.HttpContext.Response.Clear();
        filterContext.HttpContext.Response.StatusCode = statusCode;
        //filterContext.HttpContext.Response.TrySkipIisCustomErrors = true;
    }

    protected virtual ActionResult CreateActionResult(ExceptionContext filterContext, int statusCode)
    {
        var ctx = new ControllerContext(filterContext.RequestContext, filterContext.Controller);
        var statusCodeName = ((HttpStatusCode)statusCode).ToString();
        var viewName = "~/Views/Shared/Error.cshtml";
        var controllerName = (string)filterContext.RouteData.Values["controller"];
        var actionName = (string)filterContext.RouteData.Values["action"];
        var model = new HandleErrorInfo(filterContext.Exception, controllerName, actionName);
        var result = new ViewResult
        {
            ViewName = viewName,
            ViewData = new ViewDataDictionary<HandleErrorInfo>(model),
        };
        result.ViewBag.StatusCode = statusCode;
        return result;
    }
}

答案 1 :(得分:1)

您可以匹配列表的名称并保留常用名称。

keep <- match(names(disease_df_quintile), names(df_quintile))
new_df_quintile <- df_quintile[keep]