Error constructing a dataframe, arguments imply differing number of rows

Hello everyone. I have downloaded some windspeed data from the ECMWF and I want to build and save a dataframe with some of it. Unfortunately, I obtain an error when doing so.

I start by opening the file and reading the variables in question

ncnameECMWF <- "_mars-webmars-public-svc-green-005-6fe5cac1a363ec1525f54343b6cc9fd8-rJIrn0"  
ncfnameECMWF <- paste(ncpath, ncnameECMWF, ".nc", sep="")
ncinECMWF <- nc_open(ncfnameECMWF)
dataECMWF_U <- ncvar_get(ncinECMWF, "u")
dataECMWF_T <- as.POSIXct(ncvar_get(ncinECMWF, "time"), origin = "1900-01-01 00:00", tz = "UTC")


data_UV_jaime_all_here_Square <- data.frame(UEnsembleSquare, dataECMWF_T)

Then, I obtain the following error

Error in data.frame(UEnsembleSquare,dataECMWF_T :
arguments imply differing number of rows: 361, 31.

UEnsembleSquare is a 4D matrix of size 36120150*31 and dataECMWF_T is a 31 membler srting.

I am very new to R and I don't understand it propperly, but as far as I kow, in R, one can make datasets with variables with different dimensions each.

Can someone please tell me what I am doing wrong?

Any answer is appreciated.

Your data frame needs to have all its columns fill up every row. If x is a vector variable, then length(x) tells you how many items the vector contains.

Are you really starting with a 4 dimensional matrix, a by b by c by d? I woud advise starting with 2 dimensioal matrices if you are new to R.

This topic was automatically closed 21 days after the last reply. New replies are no longer allowed.

If you have a query related to it or one of the replies, start a new topic and refer back with a link.

Thanks for the answer. If I have understood propperly, I cannot do what I want, which is having a dataframe with "UEnsembleSquare" a 3612015031 and "dataECMWF_T" a 311; I would need "dataECMWF_T" to be a 361*1 vector for the dataframe to be constructed. Is that right?

About starting with 2D matrices, I know I should start with something easier, but I have just started a collaboration with another university; I have traditionally used other languages, but I am trying to adapt to what my collaborators use and their code, which requieres working with 4D matrices.

Thanks again for answering.