【问题标题】:Find rows (name) of people with the biggest difference between values, R查找值之间差异最大的人的行(姓名),R
【发布时间】:2021-09-10 09:34:10
【问题描述】:

我想找到“Action”中的值差异最大的两个名称。这是数据:

data = structure(list(`First Name` = c("Till", "Roland", "Otmar", "Christoph"), Action = c(2, 1, 2, 1), Reflection = c(6, 7, 6, 7), Flexibility_Thinking = c(2, 3, 3, 1), Structure = c(6, 4, 4, 7)), row.names = c(NA, -4L), class = c("tbl_df", "tbl", "data.frame"))

感谢您的帮助!

【问题讨论】:

    标签: r difference


    【解决方案1】:

    您可以使用argmax()argmin(),如下所示:

    data = pd.DataFrame({'Name': ['Till', 'Roland', 'Otmar', 'Christoph'], 'Action': [2,1,4,7]})  
    [data.loc[data['Action'].argmax(), "Name"], data.loc[data['Action'].argmin(), "Name"]]
    

    输出:

    ['Christoph', 'Roland']
    

    【讨论】:

    • 非常感谢您的回答!我刚刚意识到我必须用 R 而不是 Python...
    • @Theresa_S 随意使用pythonR :))) 。并阅读此链接:meta.stackexchange.com/questions/5234/…
    • 我用你的代码试了一下,它给了我一个错误:“[”中的意外'[',你知道为什么吗?我在问题中将我的数据更新为 R 格式。
    • 它在 R 中,我必须使用 R
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2017-04-18
    • 1970-01-01
    • 1970-01-01
    • 2020-09-17
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多