相关疑难解决方法(0)

对R中事物类型的综合调查; 'mode'和'class'和'typeof'是不够的

语言R让我困惑.实体具有模式,但即使这不足以完全描述实体.

这个答案

在R中,每个"对象"都有一个模式和一个类.

所以我做了这些实验:

> class(3)
[1] "numeric"
> mode(3)
[1] "numeric"
> typeof(3)
[1] "double"
Run Code Online (Sandbox Code Playgroud)

到目前为止公平,但后来我传入了一个向量:

> mode(c(1,2))
[1] "numeric"
> class(c(1,2))
[1] "numeric"
> typeof(c(1,2))
[1] "double"
Run Code Online (Sandbox Code Playgroud)

这没有意义.当然,整数向量应该具有与单个整数不同的类或不同的模式吗?我的问题是:

  • R中的所有内容都有(只有一个)吗?
  • R中的所有内容都有(只有一种)模式吗?
  • 什么,如果有的话,'typeof'告诉我们什么?
  • 完整描述实体还需要哪些其他信息?(例如,'矢量'存储在哪里?)

更新:显然,文字3只是长度为1的向量.没有标量.好吧但是......我试过mode("string")"character",让我觉得字符串是一个字符向量.但如果这是真的,那么这应该是真的,但事实并非如此!c('h','i') == "hi"

r language-lawyer r-faq

43
推荐指数
4
解决办法
9350
查看次数

为什么`select_if(., is_double)` 返回日期?

使用is_doublewith 时select_if,返回值包括 lubridatedate数据类型的列。为什么是这样?

这是一个使用该today()函数的简单示例。

library(tidyverse)
library(lubridate)

mtcars %>% 
    as_tibble() %>% # Convert to tibble
    mutate(today = today()) %>% # Create a date column
    select_if(is_double) # Select double columns
Run Code Online (Sandbox Code Playgroud)

输出:

# A tibble: 32 x 12
     mpg   cyl  disp    hp  drat    wt  qsec    vs    am  gear  carb today     
   <dbl> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl> <date>    
 1  21       6  160    110  3.9   2.62  16.5     0     1     4     4 2020-06-25 …
Run Code Online (Sandbox Code Playgroud)

r lubridate dplyr

2
推荐指数
1
解决办法
119
查看次数

标签 统计

r ×2

dplyr ×1

language-lawyer ×1

lubridate ×1

r-faq ×1