No Dimensions of Non-Empty Numeric Vector in R

No dimensions of non-empty numeric vector in R

Because it is a one-dimensional vector. It has length. Dimensions are extra attributes applied to a vector to turn it into a matrix or a higher dimensional array:

x <- 1:6
dim( x )
#NULL

length( x )
#[1] 6

dim( matrix( x , 2 , 3 ) )
#[1] 2 3

No dimensions of non-empty numeric vector in R

Because it is a one-dimensional vector. It has length. Dimensions are extra attributes applied to a vector to turn it into a matrix or a higher dimensional array:

x <- 1:6
dim( x )
#NULL

length( x )
#[1] 6

dim( matrix( x , 2 , 3 ) )
#[1] 2 3

Cohens_d error due to non-numeric vector...but where is it?

Using the effsize package instead of rstatix the test ran successfully:

LST_Weather_dataset %>% group_by(Month, .add = FALSE)
# A tibble: 456 x 14
# Groups: Month [12]
Buffer Date LST Month Year JulianDay TimePeriod
<int> <date> <dbl> <dbl> <dbl> <dbl> <dbl>
1 100 2010-01-15 0.581 1 2010 15 1
2 100 2010-02-16 0.971 2 2010 47 1
3 100 2010-03-20 1.63 3 2010 79 1
4 100 2011-04-24 2.14 4 2011 114 1
5 100 2010-05-07 1.90 5 2010 127 1
6 100 2010-06-08 3.32 6 2010 159 1
7 100 2011-07-13 1.67 7 2011 194 1
8 100 2010-08-11 2.74 8 2010 223 1
9 100 2010-09-12 2.27 9 2010 255 1
10 100 2011-10-17 0.987 10 2011 290 1
# ... with 446 more rows, and 7 more variables: Humidity <dbl>,
# Wind_speed <dbl>, Wind_gust <dbl>, Wind_trend <dbl>,
# Wind_direction <dbl>, Pressure <dbl>, Pressure_trend <dbl>
> CohenD2 <- cohen.d(
+ LST ~ TimePeriod | Subject(Buffer), paired = TRUE
+ )
> CohenD2

Cohen's d

d estimate: 0.5875947 (medium)
95 percent confidence interval:
lower upper
0.4328020 0.7423874

> ungroup(LST_Weather_dataset)
# A tibble: 456 x 14
Buffer Date LST Month Year JulianDay TimePeriod
<int> <date> <dbl> <dbl> <dbl> <dbl> <dbl>
1 100 2010-01-15 0.581 1 2010 15 1
2 100 2010-02-16 0.971 2 2010 47 1
3 100 2010-03-20 1.63 3 2010 79 1
4 100 2011-04-24 2.14 4 2011 114 1
5 100 2010-05-07 1.90 5 2010 127 1
6 100 2010-06-08 3.32 6 2010 159 1
7 100 2011-07-13 1.67 7 2011 194 1
8 100 2010-08-11 2.74 8 2010 223 1
9 100 2010-09-12 2.27 9 2010 255 1
10 100 2011-10-17 0.987 10 2011 290 1
# ... with 446 more rows, and 7 more variables: Humidity <dbl>,
# Wind_speed <dbl>, Wind_gust <dbl>, Wind_trend <dbl>,
# Wind_direction <dbl>, Pressure <dbl>, Pressure_trend <dbl>
> CohenD2 <- cohen.d(
+ LST ~ TimePeriod | Subject(Buffer), paired = TRUE
+ )
> CohenD2

Cohen's d

d estimate: 0.5875947 (medium)
95 percent confidence interval:
lower upper
0.4328020 0.7423874

Grouping the data using group_by made no difference as | Subject() does this within the function.

R drop by empty index on vector inconsistent behaviour

This doesn't work because which(d > 100) and -which(d > 100) are the same object: there is no difference between an empty vector and the negative of that empty vector.

For example, imagine you did:

d = 1:10

indexer = which(d > 100)
negative_indexer = -indexer

The two variables would be the same (which is the only consistent behavior- turning all the elements of an empty vector negative leaves it the same since it has no elements).

indexer
#> integer(0)
negative_indexer
#> integer(0)
identical(indexer, negative_indexer)
#> [1] TRUE

At that point, you couldn't expect d[indexer] and d[negative_indexer] to give different results. There is also no place to provide an error or warning: it doesn't know when passed an empty vector that you "meant" the negative version of that empty vector.


The solution is that for subsetting there's no reason you need which() at all: you could use d[d > 10] instead of your original example. You could therefore use !(d > 100) or d <= 100 for your negative indexing. This behaves as you'd expect because d > 10 or !(d > 100) are logical vectors rather than vectors of indices.

Empty numeric value in a numeric vector in R

If I'm understanding your question properly, you can use a named vector to create a data dictionary linking letters to corresponding numbers:

# data dictionary
dat <- 1:26
names(dat) <- letters

then map dictionary onto your vector

characterVec <- c("a", "b", "", "d")
numVec <- dat[characterVec]

gives

   a    b <NA>    d 
1 2 NA 4

You can remove the vector names with unname():

numVec <- unname(dat[characterVec])

function not filling empty vector in R

I agree with @Nathan G, but something did catch my attention: You are trying to cbind two things that cannot be bound together, since they have different dimensions. We don't know what kind of data type your simulation function returns, but it clearly is not NULL. Consider this:

df1 <- NULL
df2 <- data.frame(x = 1:10, y = 11:20)
cbind(df1, df2)
cbind(df2, df1)

Both cbind statements give errors. Do you get an error? If this is what's going on, you should initialize simulated_results not as NULL but as an empty version of whatever the function simulation returns.

EDIT

iter = 10
set.seed(iter)
J <- 1:1500
# critical to preallocate the list size for speed
res <- vector("list", iter)
for (i in 1: iter) {
res[[i]] <- simulation(J,4* (length(J)^2),0.0007,duration = 10,start)
}
str(res)
res[[1]]

Now I don't think I'm using this quite the way you ultimately intend, but perhaps this will give you enough to get to what you actually want.



Related Topics



Leave a reply



Submit