Massive44
Massive44

Reputation: 29

Adding attribute "dimensions" in a grid data

I've a very limited knowledge on R programming, I'm currently working on my thesis and I encountered an error while working with climate datasets.

"Error in aperm.default(array3D, match(c("time", "lat", "lon"), dimNames)) : 
  'perm' is of wrong length 3 (!= 2)"

I have two datasets both in same format. The first one is correct (df1) with three dimensions (time, lat, lon) the second one (df2) have one/two dimension (time and loc) I don't know what "loc" means.

The datasets are available at the following link

https://www.dropbox.com/s/ztyoqtpl9kedbuv/dfs.zip?dl=0

If I load and view the data, I obtain the following attribute dimensions at the end.

load("df1.rda")
load("df2.rda")
...
....
df1$Data
attr(,"dimensions")
[1] "time" "lat"  "lon" 
        
df2$Data
...
.....
attr(,"dimensions")
[1] "time" "loc" 

I would like both dataset to have same dimensions ie,.

attr(,"dimensions")
[1] "time" "lat"  "lon" 

The time (date) longitudes and latitudes are all present in the datasets and can be accessed by the following lines

lon <- df2$xyCoords$x
lat <- df2$xyCoords$y
time <- df2$Dates

Any Idea with this please,.. Thanks.

Upvotes: 0

Views: 65

Answers (1)

Mohamed Desouky
Mohamed Desouky

Reputation: 4425

If you want both dataset have the same dimensions , you can use

attr(df2$Data , "dimensions") <- attr(df1$Data , "dimensions")
  • output
> attributes(df1$Data)
$dim
[1] 1805    5    7

$dimensions
[1] "time" "lat"  "lon" 

> attributes(df2$Data)
$dim
[1] 4748   10

$dimensions
[1] "time" "lat"  "lon" 

Upvotes: 2

Related Questions