My data frame (g) contains 2 columns with continues data and other columns with categorical data. I want to test for correlations between the 2 continues variables, in diffe
I think you want this inside of function r
:
if ((length(x[[1]]))>2)
cor.test(x[[1]],x[[2]],use="pairwise.complete.obs")[3:4] else NA
x[[1]]
is a vector, whereas x[[1]][1]
is a single element of that vector. You clearly want vectors for cor.test
and not single elements.
In addition, a vector has a length
but nrow
is not appropriate.
The error that you get is a result of nrow(x[[1]][1])
evaluating to NULL
, so nrow(x[[1]][1]) > 2
evaluates to logical(0)
. The argument to if
should be a logical
of length 1.