简体   繁体   English

R:“ [.. data.frame”中的错误和“未使用的参数”

[英]R: “Error in `[.data.frame ” and “unused arguments”

I have a vector of 20 elements and i want that only 15 elements are assigned to a new vector. 我有一个包含20个元素的向量,我希望仅将15个元素分配给一个新向量。 When I do that, R poped me up an error, and I tried different combinations. 当我这样做时,R弹出一个错误,我尝试了不同的组合。 I want to assign elements from 6 to 19. 我想分配6到19之间的元素。

> carbo<-read.csv(file="6cwga", header=TRUE, sep=",")
> carbo2 <- carbo[-1,-2,-3,-4,-5,,-20]
Error in `[.data.frame`(carbo, -1, -2, -3, -4, -5, , -20) : 
  unused arguments (-4, -5, , -20)
> carbo2 <- carbo[-1,-2,-3,-4,-5,-20]
Error in `[.data.frame`(carbo, -1, -2, -3, -4, -5, -20) : 
  unused arguments (-4, -5, -20)
> carbo2 <- carbo[-1,-2,-3,-4,-5,-20,]
Error in `[.data.frame`(carbo, -1, -2, -3, -4, -5, -20, ) : 
  unused arguments (-4, -5, -20, )

You didn't subset the data frame properly. 您没有正确子集数据框架。 The general form to subset a data frame is <dataframe_name>(row,column) . 子集数据帧的一般形式是<dataframe_name>(row,column) To subset using multiple rows or columns you have to combine them using c() . 要使用多个行或列作为子集,您必须使用c()将它们组合在一起。

See below for corrected code. 请参阅下面的更正代码。

carbo<-read.csv(file="6cwga", header=TRUE, sep=",")
## to select the columns -1, -2, -3, -4, -5, -20
carboselectcol <- carbo[,c(-1,-2,-3,-4,-5,-20)]

## to select the numbers as rows.
carboselectrow<- carbo[c(-1,-2,-3,-4,-5,-20),]

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM