0

Libraries:

library(ggplot2)
library(BlandAltmanLeh)

I am trying to use the Bland Altman Plot. This is the code:

pl<-bland.altman.plot(A,B, graph.sys = "ggplot2")

It works if I use numeric values for A and B. But if I fill in something like:

pl<-bland.altman.plot(dataset[,c(2)],dataset[,c(3)], graph.sys = "ggplot2")

it gives me the error:

Error in bland.altman.stats: group1 is not numeric.

Is there a way to use specific columns without defining the column name my workaround was:

A<-dataset$ABI_0L

However, I do not want to use column names but numbers! Is there a way to use the function without defining A and B first?

2 Answers2

0

Welcome to stackoverflow!

Some things in advance: please provide reproducible data and state the package you are using. Further, be more precise in your title since there are many situations when one wonders how to extract certain data in R.

Anyway, using the code you provided works fine for me:

library("BlandAltmanLeh")
set.seed(1)
dataset <- data.frame(matrix(rnorm(100*3), ncol= 3))
bland.altman.plot(dataset[,c(2)],dataset[,c(3)], graph.sys = "ggplot2")

Gives me following plot: Bland Altman Plot

EDIT:

You don't need to use "c(2)" since it is the same as "2" alone. It seems like your data is not numeric. You can use

# make it numerics
dataset[, 2:3] <- apply(dataset[, 2:3],2,as.numeric)
# make a plot
bland.altman.plot(dataset[, 2],dataset[, 3], graph.sys = "ggplot2")

Altough you should be careful since it depends on what type the columns 2 and 3 are. If the columns are factors you should have a look here.

0

Maybe I got it figured out, maybe not the cleanest way, so IF somebody has a better way of doing it, please tell me :)

pl<-bland.altman.plot(apply(datatest[,c(2)],2,as.numeric),apply(datatest[,c(3)],2,as.numeric), graph.sys = "ggplot2")