Almost finished a data analysis to make tradelinks

For my thesis I am currently trying to make tradelinks, but with the last lines to make a new csv document i get an error:

Error in i_set_vertex_attr(x, attr(value, "name"), index = value, value = attr(value, :
Length of new attribute value must be 1 or 207, the number of target vertices, not 1934.

This is the code on which the error is applied:

write.csv(d1,file=paste("ITN_", period+2010, "network.csv", sep=""),na=".")

  • colnames(links)[2+period] <- "wold"
  • }

How do i fix this?

I hope you are trying to save tabular data and not a graph/network object of some kind ?

I am a complete beginner, but I am using two csv files as imports. 1 shows country codes and trade value over a period of 11 years and the other shows country codes and country names.

I am also indeed trying to save tabular data in the form of a csv file

It seems like you may have shared two lines of code , one that works and one that doesnt ?

DId you intend

write.csv(d1,file=paste("ITN_", period+2010, "network.csv", sep=""),na=".")

Does it error ? Does it work?

colnames(links)[2+period] <- "wold"

Is this the problem ?
We would need to know what links was and also period to know what to expect from this.

The first line gives the error, the second does not.

lets make sure we gather some facts about d1
what does

str(d1)

show up ?

str(d1)

Gives:

Error in str(d1) : object 'd1' not found

But I also found out that only at the closing bracket, where it says 'unexpected' does it give the error. Does this mean that is should be able to find the csv document somewhere?

I suggest you go back to your code that was supposed to make d1, because that is what hasn't worked.

Here you can read about reprex in general. but it seems you need to take more time to identify your first point of failure. always tackle errors from the top down and not from the bottom up. goodluck !

Thank you for your help!!

I have found my first problem, it is with this code:

V(g)$pop<-links[,c(2+endper+period)]

I get the following error:

Error in i_set_vertex_attr(x, attr(value, "name"), index = value, value = attr(value, :
Length of new attribute value must be 1 or 44, the number of target vertices, not 1770

Do you know how to resolve this?

links is a csv file with 1770 obs. and 41 variables
endper is 12
period is 1
i do not know what c is, could this be the issue?

c is a function for concatenating items in R, but its also not needed in this operation, and its also not the cause of any problem.

You are basically here taking the 15th column of links (2+12+1 = 15 ) and trying to put the 1770 facts/information there into some attached pop name to the vertex list of your graph.
The error messsage implies there are only 44 locations in V(g)$pop, so stuffing 1770 different facts into 44 piegeon holes isnt going to work ...

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.