比列名更多的列?

时间:2016-07-11 16:26:24

标签: r

我正在尝试读取一个包含24个列标题但另外包含14个空值的文件。请参见链接:https://www.elections.il.gov/ElectionInformation/CandDataFile.aspx?id=51

每当我运行下面的代码时,我都会收到消息

  

"列数多于列名。"

我觉得答案可能很简单。有什么想法吗?

candidates <- read.csv(file = "candidates.txt", sep = ",", 
                        header = TRUE, stringsAsFactors = FALSE)

3 个答案:

答案 0 :(得分:8)

一种解决方案是仅使用一个命令读取标题,一秒钟内没有标题的数据,然后删除多余的列并设置名称。

NAMES <- read.table("candidates.txt", nrow = 1, stringsAsFactors = FALSE, sep = ",")
DATA <- read.table("candidates.txt", skip = 1, stringsAsFactors = FALSE, sep = ",")
DATA <- DATA[, 1:24]
names(DATA) <- NAMES 

答案 1 :(得分:0)

在通过docker运行时,我遇到了类似的问题。因此,我必须先下载文件,然后再读取csv文件。

import QtQuick3D 1.15
import QtQuick 2.15
import QtQuick.Timeline 1.0

Node {
    id: rOOT

    property alias currentFrame: timeline0.currentFrame
    

    Node {
        id: light
        x: 407.625
        y: 590.386
        z: -100.545
        eulerRotation.x: -132.466
        eulerRotation.y: 72.7792
        eulerRotation.z: -169.256
        scale.x: 1
        scale.y: 1
        scale.z: 1

        PointLight {
            id: light_Orientation
            eulerRotation.x: -90
            color: "#ffffffff"
            brightness: 10000
            quadraticFade: 1
        }
    }

    Node {
        id: camera
        x: 524.195
        y: 308.297
        z: -485.887
        eulerRotation.x: -105.604
        eulerRotation.y: 44.346
        eulerRotation.z: -179.999

        PerspectiveCamera {
            id: camera_Orientation
            eulerRotation.x: -90
            clipNear: 0.1
            clipFar: 100
            fieldOfView: 39.5978
            fieldOfViewOrientation: Camera.Horizontal
        }
    }

    Node {
        id: empty_002

        Model {
            id: node01_Base
            y: 3.23133
            z: 21.8115
            source: "meshes/node01_Base.mesh"

            PrincipledMaterial {
                id: plastico_Negro_material
                baseColor: "#ff010101"
                metalness: 0
                roughness: 0.8
                normalMap: Texture {
                    source: "maps/0.png"
                    
                }
                cullMode: Material.NoCulling
            }
            materials: [
                plastico_Negro_material
            ]
        }

        Model {
            id: node02_Base_rim
            y: 3.23133
            z: 21.8115
            eulerRotation.z: 180
            scale.x: 0.121224
            scale.y: 0.361819
            scale.z: 1.3171
            source: "meshes/node02_Base_rim.mesh"

            PrincipledMaterial {
                id: aluminio_galvanizado_material
                baseColor: "#ff383838"
                roughness: 0.5
                cullMode: Material.NoCulling
            }
            materials: [
                aluminio_galvanizado_material
            ]
        }

        Model {
            id: node03_Base_controls
            eulerRotation.x: 8.46812
            scale.x: 0.0367964
            scale.y: 0.271225
            scale.z: 0.271225
            source: "meshes/node03_Base_controls.mesh"

            PrincipledMaterial {
                id: aluminio_negro_material
                baseColor: "#ff080808"
                roughness: 0.5
                cullMode: Material.NoCulling
            }
            materials: [
                aluminio_galvanizado_material,
                aluminio_negro_material
            ]
        }

        Model {
            id: node04_Bottom_seat
            y: 32.6284
            tessellationMode: Model.NPatch
            receivesShadows: false
            isWireframeMode: false
            source: "meshes/node04_Bottom_seat.mesh"

            PrincipledMaterial {
                id: cUERO_NEGRO_material
                baseColor: "#ff534d30"
                metalness: 0
                roughness: 0.389465
                normalMap: Texture {
                    source: "maps/0.png"
                    tilingModeHorizontal: Texture.Repeat
                    tilingModeVertical: Texture.Repeat
                }
                cullMode: Material.NoCulling
            }
            materials: cUERO_NEGRO_material
        }
        
        Model {
            id: node05_Bottom_sides
            source: "meshes/node05_Bottom_sides.mesh"
            materials: cUERO_NEGRO_material
        }
        
        Model {
            id: node06_Back_seat
            y: -7.04048
            z: 6.17094
            eulerRotation.x: -1.59834
            source: "meshes/node06_Back_seat.mesh"
            materials: cUERO_NEGRO_material
        }
        
        Model {
            id: node07_Seat_back_sides
            source: "meshes/node07_Seat_back_sides.mesh"
            materials: cUERO_NEGRO_material
        }
        
        Model {
            id: node08_Upper_neck
            y: 222.546
            z: 199.645
            source: "meshes/node08_Upper_neck.mesh"
            materials: cUERO_NEGRO_material
        }
        
        Model {
            id: node09_Header
            isWireframeMode: true
            source: "meshes/node09_Header.mesh"
            materials: cUERO_NEGRO_material
        }
    }

    Timeline {
        id: timeline0
        startFrame: 0
        endFrame: 30
        currentFrame: 0
        enabled: true
        animations: [
            TimelineAnimation {
                duration: 30
                from: 0
                to: 30
                running: true
            }
        ]

        KeyframeGroup {
            target: empty_002
            property: "position"

            Keyframe {
                frame: 0
                value: Qt.vector3d(0, 0, 0)
            }
        }

        KeyframeGroup {
            target: empty_002
            property: "eulerRotation"

            Keyframe {
                frame: 0
                value: Qt.vector3d(0, 0, 0)
            }
            Keyframe {
                frame: 1
                value: Qt.vector3d(0, 6, 0)
            }
            Keyframe {
                frame: 2
                value: Qt.vector3d(0, 12, 0)
            }
            Keyframe {
                frame: 3
                value: Qt.vector3d(0, 18, 0)
            }
            Keyframe {
                frame: 4
                value: Qt.vector3d(0, 24, 0)
            }
            Keyframe {
                frame: 5
                value: Qt.vector3d(0, 30, 0)
            }
            Keyframe {
                frame: 291.667
                value: Qt.vector3d(0, 36, 0)
            }
            Keyframe {
                frame: 6
                value: Qt.vector3d(0, 42, 0)
            }
            Keyframe {
                frame: 7
                value: Qt.vector3d(0, 48, 0)
            }
            Keyframe {
                frame: 8
                value: Qt.vector3d(0, 54, 0)
            }
            Keyframe {
                frame: 9
                value: Qt.vector3d(0, 60, 0)
            }
            Keyframe {
                frame: 10
                value: Qt.vector3d(0, 66, 0)
            }
            Keyframe {
                frame: 11
                value: Qt.vector3d(0, 72, 0)
            }
            Keyframe {
                frame: 12
                value: Qt.vector3d(0, 78, 0)
            }
            Keyframe {
                frame: 13
                value: Qt.vector3d(0, 84, 0)
            }
            Keyframe {
                frame: 14
                value: Qt.vector3d(0, 90, 0)
            }
            Keyframe {
                frame: 15
                value: Qt.vector3d(0, 96, 0)
            }
            Keyframe {
                frame: 16
                value: Qt.vector3d(0, 102, 0)
            }
            Keyframe {
                frame: 17
                value: Qt.vector3d(0, 108, 0)
            }
            Keyframe {
                frame: 18
                value: Qt.vector3d(0, 114, 0)
            }
            Keyframe {
                frame: 19
                value: Qt.vector3d(0, 120, 0)
            }
            Keyframe {
                frame: 20
                value: Qt.vector3d(0, 126, 0)
            }
            Keyframe {
                frame: 21
                value: Qt.vector3d(0, 132, 0)
            }
            Keyframe {
                frame: 22
                value: Qt.vector3d(0, 138, 0)
            }
            Keyframe {
                frame: 23
                value: Qt.vector3d(0, 144, 0)
            }
            Keyframe {
                frame: 24
                value: Qt.vector3d(0, 150, 0)
            }
            Keyframe {
                frame: 25
                value: Qt.vector3d(0, 156, 0)
            }
            Keyframe {
                frame: 26
                value: Qt.vector3d(0, 162, 0)
            }
            Keyframe {
                frame: 27
                value: Qt.vector3d(0, 168, 0)
            }
            Keyframe {
                frame: 28
                value: Qt.vector3d(0, 174, 0)
            }
            Keyframe {
                frame: 29
                value: Qt.vector3d(0, 182, 0)
            }
            
            Keyframe {
                frame: 30
                value: Qt.vector3d(0, 190, 0)
            }
            
            
        }

        KeyframeGroup {
            target: empty_002
            property: "scale"

            Keyframe {
                frame: 0
                value: Qt.vector3d(1, 1, 1)
            }
        }
    }
}

答案 2 :(得分:0)

我遇到了类似的问题,我认为问题出在标题上。因为当我删除标题(文件开头以“#”开头的行)时,不会发生错误。最后,下面链接中的解决方案解决了问题。它将参数 'skip' 设置为 1 以跳过文件的第一行(标题)。

https://community.rstudio.com/t/more-columns-than-column-names-error/43517