[R] R problem: Error in data[2:4] : object of type 'closure' is not subsettable

Michael Sumner mdsumner at gmail.com
Thu Dec 12 07:41:07 CET 2013


That message refers to the function (closure) "data", which is a
function in R and that you have not overwritten with a data.frame in
that session. Note how you two versions of the code:

dat1 <- read.csv("Human_Rights_Excel_Data.csv") #converted .xlsx to .csv

and

#data<-readcsv("HumanRightsExcelData")

Just makes sure you use dat1[,2:4] instead, or rename your variable to
suit. Working up a reproducible example in a fresh session (even if
only you can run it) will catch problems like this.

(And in future, when you see that error message think "ah it means I'm
trying to index a function (probably) rather than my data object". )

HTH






On Thu, Dec 12, 2013 at 4:41 PM, arun <smartpink111 at yahoo.com> wrote:
> Hi,
> May be this helps:
>
> dat1 <- read.csv("Human_Rights_Excel_Data.csv") #converted .xlsx to .csv
>
> mat1 <- log10(t(as.matrix(dat1[,2:4])))
> mat1[!is.finite(mat1)] <- 0
>
> par(mar=c(5,22,4,0.2))
> COLOR<-c('red','brown4','black')
> barplot(mat1,beside=T,horiz=T,las=2,col=COLOR,main='KilingsinGaza,\nWestBank,andIsrael',names.arg=t(dat1$X),xlab='Base10totheNnumberofKillings')
> par(new=T,mar=c(0,0,0,0))
> plot(0,0,type="n")
> legend("bottomleft",legend=c("Gaza","West Bank","Israel"),text.col=COLOR,bty="n",cex=1.5)
>
> A.K.
>
>
>
>
> Human_Rights_Excel_Data.xlsx
>
> Above is the attachment for my excel data.
>
> I am having this problem: Error in data[2:4] : object of type 'closure' is not subsettable
>
> Here is my code
> #data<-readcsv("HumanRightsExcelData")
> par(mar=c(5,22,4,0.2))
> COLOR<-c('red','brown4','black')
> barplot(log10(t(as.matrix(data[,2:4]))),beside=T,horiz=T,las=2,names.arg=t(data$X),col=COLOR,main='KilingsinGaza,\nWestBank,andIsrael',xlab='Base10totheNnumberofKillings')
> par(new=T,mar=c(0,0,0,0))
> plot(0,0,type="n")
> legend("bottomleft",legend=c("Gaza","West Bank","Israel"),text.col=COLOR,bty="n",cex=1.5)
>
> When ever I type in this code
>
> barplot(log10(t(as.matrix(data[,2:4]))),beside=T,horiz=T,las=2,names.arg=t(data$X),col=COLOR,main='KilingsinGaza,\nWestBank,andIsrael',xlab='Base10totheNnumberofKillings')
>
> I get this message
>
> Error in data[2:4] : object of type 'closure' is not subsettable
>
> Can someone please help me out? Also I am terrible with R so please try and make your responses idiot proof hahahaha.
>
> ______________________________________________
> R-help at r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.



-- 
Michael Sumner
Hobart, Australia
e-mail: mdsumner at gmail.com



More information about the R-help mailing list