从R中的3个不同向量中找出最长的长度 [英] Finding longest length out of 3 different vectors in R

查看:93
本文介绍了从R中的3个不同向量中找出最长的长度的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我不知道是否有此功能,但是我有3个不同长度的数据框.我想知道是否有一种方法可以找到最大长度的那个并将其加载到变量中.例如:

I do not know if there is a function for this but I have 3 dataframes with different lengths. I was wondering if there is a way to find which one is the largest length and load that into a variable. For example:

x <- c(1:10)
y <- c(1:20)
z <- c(1:40)

我想使用z作为变量,因为它的长度最长.是否有一个函数可以搜索这三个变量(x,y,z)并给我最长的变量?

I would want to use z as my variable because it has the longest length. Is there a function that can search through these 3 variables (x,y,z) and give me back the one with the longest length?

谢谢

推荐答案

我们可以将其放在list中,使用lengths创建最大长度的索引,然后从list

We can place it in a list, use lengths to create an index of maximum length and extract those element from the list

lst[which.max(lengths(lst))]

数据

lst <- list(x, y, z)

这篇关于从R中的3个不同向量中找出最长的长度的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆