代码之家  ›  专栏  ›  技术社区  ›  Thundersheep

在r[关闭]中将我的日志(值)添加到数据帧

  •  -4
  • Thundersheep  · 技术社区  · 7 年前

    好吧,我在记录一些距离变量 -示例;

    loghospital=log(hospital_2015_distance, base=exp(1))
    

    我得到了可以在回归中运行的值。

    但是对于我的套索回归,最好指定一个数据集。 所以我想要一个这些日志(值)的数据框架。

    或者,我希望将这些日志(值)添加到我现有的名为(data)的数据帧中。

    你知道怎么做到吗?如果没有,我还应该做些什么来达到同样的效果呢?

    1 回复  |  直到 7 年前
        1
  •  1
  •   s_baldur    7 年前

    添加到您的 data.frame 你可以用 $ :

    data$loghospital = log(hospital_2015_distance, base=exp(1))
    

    你也可以用 [[ [ 或许应该 <- 而不是 = 任务:

    # Examples:
    data[["loghospital"]] <- log(hospital_2015_distance, base=exp(1))
    data["loghospital"]   <- log(hospital_2015_distance, base=exp(1))
    data[, "loghospital"] <- log(hospital_2015_distance, base=exp(1))