语言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)
这没有意义.当然,整数向量应该具有与单个整数不同的类或不同的模式吗?我的问题是:
更新:显然,文字3只是长度为1的向量.没有标量.好吧但是......我试过mode("string")了"character",让我觉得字符串是一个字符向量.但如果这是真的,那么这应该是真的,但事实并非如此!c('h','i') == "hi"
使用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)