RE: Incorrect Number of Dimensions

Hello there,

I'm trying to use a function that I have created, but I seem to keep getting the error "Incorrect Number of Dimensions" I've been spending hours on this, but I can't seem to discover what the problem is, here is my data (this part works)

island <- c("Barbados","Cuba","Guadaloupe","Jamaica","Martinique","Puerto Rico","Trinidad")
year <- c("1850","1851","1852","1853","1854","1855","1856","1857","1858","1859","1860")

Barbados_sugar <- c(27, 30, 38, 29, 34, 54, 35, 32, 54, 56)
Cuba_sugar <- c( 65, 43, 23, 65, 86, 43, 45, 45, 53, 34)
Guadaloupe_sugar <- c(54, 32, 75, 45, 52, 24, 24, 35, 89, 56)
Jamaica_sugar <- c(43, 2, 56, 63, 24, 65, 12, 58, 43, 45)
Martinique_sugar <- c(23, 34, 64, 24, 53, 54, 34, 56, 76, 73)
Puerto_Rico_sugar <- c(12, 21, 34, 53, 45, 65, 38, 92, 23, 13)
Trinidad_sugar <- c(23, 54, 37, 85, 4, 43, 46, 56, 73, 36)

island_sugar <- c(Barbados_sugar, Cuba_sugar, Guadaloupe_sugar, Jamaica_sugar, Martinique_sugar, Puerto_Rico_sugar, Trinidad_sugar)

data1 <- matrix (island_sugar, 7, 11, byrow=T)

colnames (data1) <- c("1850","1851","1852","1853","1854","1855","1856","1857","1858","1859","1860")
rownames (data1) <- c("Barbados","Cuba","Guadaloupe","Jamaica","Martinique","Puerto Rico","Trinidad")

matplot(t(data1), type ="b", pch=15:18, col=c(1:4,6))
legend("bottomleft", inset=0.01, legend=island, col=c(1:4,6), pch=15:18, horiz=F)

data1

but when I create a function and try to use it, i get the error message "Error in data[rows, , drop = F] : incorrect number of dimensions":

myplot <- function(data, rows){
Data <- data[rows,, drop=F]
matplot(t(Data), type ="b", pch=15:18, col=c(1:4,6))
legend("bottomleft", inset=0.01, legend=island[rows], col=c(1:4,6), pch=15:18, horiz=F)
}

myplot(island_sugar)

any help would be much appreciated,

cheers,

Sami.

I have only had a quick look, but some possible issues:

two commas

Data <- data[rows,, drop=F]

function asks for data and rows, but you only supply data.

myplot(island_sugar)