向量被存储为数据框而不是向量

时间:2018-10-18 05:40:31

标签: r

我是r和rstudio的新手,我需要创建一个向量来存储程序读取的csv文件的前100行。但是,尽管进行了所有尝试,但变量v1最终变成了数据帧,而不是int向量。我可以知道该怎么做吗?这是我的代码:

library(readr)
library(readr)
cup_data <- read_csv("C:/Users/Asus.DESKTOP-BTB81TA/Desktop/STUDY/YEAR 2/
          YEAR 2 SEM 2/PREDICTIVE ANALYTICS(1_PA_011763)/Week 1 (Intro to PA)/
                     Practical/cup98lrn variable subset small.csv")
# Retrieve only the selected columns
cup_data_small <- cup_data[c("AGE", "RAMNTALL", "NGIFTALL", "LASTGIFT", 
                     "GENDER", "TIMELAG", "AVGGIFT", "TARGET_B", "TARGET_D")]
str(cup_data_small)
cup_data_small

#get the number of columns and rows
ncol(cup_data_small)
nrow(cup_data_small)
cat("No of column",ncol(cup_data_small),"\nNo of Row :",nrow(cup_data_small))

#cat
#Concatenate and print
#Outputs the objects, concatenating the representations. 
#cat performs much less conversion than print.

#Print the first 10 rows of cup_data_small
head(cup_data_small, n=10)

#Create a vector V1 by selecting first 100 rows of AGE 
v1 <- cup_data_small[1:100,"AGE",]

这就是我的环境所说的: enter image description here

1 个答案:

答案 0 :(得分:2)

aws s3 rb s3://hierarchy --force fatal error: An error occurred (AccessDenied) when calling the ListObjects operation: Access Denied 是一个小标题,它是数据框的经过稍微修改的版本,其规则略有不同,目的是为了避免标准数据框中的某些常见问题/不一致性。例如。在标准数据帧中,cup_data_small为您提供矢量,而df[, c("a")]为您提供一个数据帧-您使用的是相同的语法,因此可以说它们应该提供相同类型的结果。

要仅从小标题中获取矢量,则必须显式传递df[, c("a", "b")],例如:

drop = TRUE