【问题标题】:select function error: no applicable method for select_' applied to an object of class "character"选择函数错误:没有适用于 select_' 的方法应用于“字符”类的对象
【发布时间】:2019-04-04 04:05:37
【问题描述】:

我只是想在此数据“dd2.survey.data.csv”中选择第 6 到 53 列

但选择功能不适用于该错误

file.raw.items % select(7:53) %T>% print

UseMethod("select_") 中的错误:没有适用于“select_”的方法 应用于“字符”类的对象

getwd()
setwd("C:/Users/bargsang/Desktop")
dir()
dir("dd2.survey.data.csv")

library(tidyverse)
library(magrittr) # %T>% 
install.packages("psych")
install.packages("psy")
library(psych) # pca, fa
library(psy) # screeplot
library(dplyr)
library(ggplot2)
library(magrittr)

file.raw <- "dd2.survey.data.csv"
file.raw

file.raw.items <- file.raw %>% select(6:53) %T>% print
##At this moment, 
##select function doesn't work. how can i solve it?

【问题讨论】:

    标签: r select read.csv


    【解决方案1】:

    您需要使用read.csv() 或类似功能来读取您的文本文件。

    我不确定您的代码是否还有其他错误,但您目前在哪里:

    file.raw.items <- file.raw %>% select(6:53) %T>% print
    

    您可能需要将其更改为:

    file.raw.items <- read.csv(file = file.raw) %>% select(6:53) %T>% print()
    

    除了缺少 read.csv() 来读取您的文件注释之外,您还省略了 print() 末尾的 ()

    请注意,这将首先将整个文件读入内存,然后选择 6:53 列,然后将 data.frame 保存到 file.raw.items

    有关指定标头的选项,请参阅?read.csv

    另外,请注意您是否要使用 stringsAsFactors = FALSE 的附加选项来确保文本保持为文本(当然,除非您希望将文本作为因子读取)。 Imported a csv-dataset to R but the values becomes factors

    【讨论】:

    • 这真的很基本。非常感谢。
    • 因此,我无法启动它。谢谢
    • @bargsang 很高兴为您提供帮助。如果它回答了您的问题,请不要忘记将答案标记为选中,如果有必要,请投票:What should I do when someone answers my question?
    猜你喜欢
    • 2023-04-06
    • 1970-01-01
    • 2020-05-25
    • 1970-01-01
    • 2021-10-09
    • 1970-01-01
    • 1970-01-01
    • 2019-04-07
    • 1970-01-01
    相关资源
    最近更新 更多