在R中查找变量的类 [英] Finding the class of a variable in R

查看:92
本文介绍了在R中查找变量的类的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

所以我在使用R时遇到了这个问题。我有一个表,我需要查找变量的类是什么(即,我假设这将引用列中的数据)。

So I have this problem with R. I have a table and I need to find what is the class of the variable (i.e. I'm presuming that would be referring to the data in the columns).

数据很大,即行很多。

每当我编写 class(dataofname)不起作用,每当我写 class( titleofthecolumn)时,它就会带回我字符,即引用列标题,这不是我追求...

Whenever I write class(nameofthedata) it doesn't work and whenever I write class("titleofthecolumn") it gives me back "character i.e. referring to the title of the column which is not what I'm after...

推荐答案

我建议以下解决方案:

# Load sample data
data(mtcars)
# Classes
sapply(mtcars, class)

您可以轻松地识别数据框中所有变量的类:

You can the convinetly identify classes of all variables in the data frame:

>> t(t(sapply(mtcars, class)))
     [,1]     
mpg  "numeric"
cyl  "numeric"
disp "numeric"
hp   "numeric"
drat "numeric"
wt   "numeric"
qsec "numeric"
vs   "numeric"
am   "numeric"
gear "numeric"
carb "numeric"

t()仅用于代码演示。

t() used only for the code presentation.

这篇关于在R中查找变量的类的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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