矢量的维数是多少?

时间:2017-10-31 01:41:45

标签: r

我对Advanced R的this section数据结构的分类感到困惑。

特别是,数组具有未定义的维度,原子向量为1d。你怎么用R证明它?这种分类是否应该反映dim()的输出?

> dim(c(1))
NULL
> dim(array(1))
[1] 1

previous post dim()听起来-Dfile.encoding=UTF-16解决了维度问题。

1 个答案:

答案 0 :(得分:3)

我认为 Sub tableOrder() Dim last_called As Integer, reference_by_numbered_list As Integer last_called = 0 selection.Find.Font.Bold = ture selection.HomeKey unit:=wdStory 'Selection.Find.ClearFormatting With selection.Find .Text = "Table [0-9]{1,}" .Format = True .Forward = True .Wrap = wdFindContinue .MatchWildcards = True Do .Execute If Not .Found Then Exit Do ElseIf .Found Then last_called = tOrder(selection.Text, last_called) End If Loop End With End Sub Function tOrder(AnyStr As String, last_call As Integer) Dim RegEx, mystr As String, myword As Words Set RegEx = CreateObject("vbscript.regexp") With RegEx .Global = True .Pattern = "\d+" End With Set sql = RegEx.Execute(selection.Text) For i = 0 To sql.count - 1 If Val(sql(i)) > last_call + 1 Then selection.Comments.Add Range:=selection.Range, Text:="incorrect citation order, table " & sql(i) & " detected before table " & last_call + 1 & ". " Else If Val(sql(i)) > last_call Then last_call = Val(sql(i)) End If End If If i + 1 <= sql.count - 1 Then 'make sure there is still one entry ahead If Val(sql(i)) >= Val(sql(i + 1)) Then selection.Comments.Add Range:=selection.Range, Text:="detected " & sql(i) & " before " & sql(i + 1) & ". This is wrong citation order." End If End If Next i tOrder = last_call Set RegEx = Nothing Set dict = Nothing End Function 的返回值不是您认为的。

dim的文档中:它返回

  

<强>值

     

对于数组(因此特别是对于矩阵),dim检索对象的dim属性。它是NULL或模式整数的向量。

它不返回对象的向量空间(1-d,2-d等)的维度。

如果某个对象没有设置dim属性,我们可以预期dim

NULL

在我看来,原子向量与其他数据类型的不同之处是没有atv <- c(1) attributes(atv) # NULL ara <- array(1) attributes(ara) #$dim #[1] 1 属性。只要将dim设置为原子矢量,它就会变成矩阵或数组。

dim