user14269252
user14269252

Reputation: 450

Error in `.rowNamesDF<-`(x, value = value) : duplicate 'row.names' are not allowed. using reshape in R

I have a DataFrame with 737 rows, a sample of data is as follows, I want to use reshape on my data. I get error as Error in `.rowNamesDF<-`(x, value = value) : duplicate 'row.names' are not allowed In addition: Warning message: non-unique values when setting 'row.names':

It tells me that I have duplicate 'row.names', but also in my sample data set I have duplicates, and it gives me the answer correctly just on my whole data set, it produce this error, where is the problem?

Note: the code below doesn't produce error on sample data that includes duplicates, but it does produce in whole data set.

The whole data set can be found in link below: https://www.dropbox.com/s/1rxzvqszvl1vzb9/ccc.csv?dl=0


df <- structure(list('User Name' = c("WolfelFigaro", "WolfelFigaro",  "DeEvolver247", "DeEvolver247", "Raymond46194270", "Raymond46194270",  "merapimanf"),
                     part1 = c("bonglez", "bonglez", "bonglez", "bonglez",  "x", "bonglez", "9NewsQueensland"),
                     part2 = c("bonglez", "bonglez",  NA, "xx", NA, NA, NA),
                     part3 = c("bonglez", "bonglez", NA, NA,  NA, NA, NA)), 
                class = "data.frame", row.names = c("1", "2", "3",  "4", "5", "6", "7"))


df3<-reshape(df,
                direction = "long",
                varying = list(names(df)[2:4]),
                v.names = "Link",
                idvar = c("user_name"))


The code for whole dataset:

df2 = read.csv("ccc.csv") 


row.names(df2)
print(tbl_df(df2), n=737)
df4<-reshape(df2,
            direction = "long",
            varying = list(names(df2)[2:4]),
            v.names = "x",
            idvar = c("MENTION"))

df4["time"] <-NULL
df4["user_name"] <-NULL
df4["Row"] <-NULL
row.names(df4) <- NULL


net1 <- graph_from_data_frame(df4)
relationsp = get.adjacency(net1, sparse = FALSE)             

Upvotes: 0

Views: 5623

Answers (1)

Ronak Shah
Ronak Shah

Reputation: 389055

You can try :

library(igraph)
library(dplyr)
library(tidyr)

read.csv('ccc.csv') %>%
  pivot_longer(cols = starts_with('part')) %>%
  select(MENTION, value) -> df4


net1 <- graph_from_data_frame(df4)
relationsp = get.adjacency(net1, sparse = FALSE) 

Upvotes: 1

Related Questions