I am trying to read a network data (graph of ids) in R. The file is named 'network.txt' and data is as follows:
4 0
5 0
6 0
7 0
8 0
9 0
4029 1
4030 1
4031 1
4032 1
4033 1
19088 9040
19089 9040
19090 9040
19091 9040
19092 9040
19093 9040
19094 9040
19095 9040
19096 9040
19097 9040
And, I am reading it using read.table() module.
data = read.table("network.txt",sep="\t",header=FALSE)
colnames( data ) <- unlist(c('to', 'from'))
Error in `colnames<-`(`*tmp*`, value = c("to", "from")) :
'names' attribute [2] must be the same length as the vector [1]
So, how to assign column names? Is there any mistake reading the original data file ?
You can either provide the column names within the read.table
function call, as such:
read.table("network.txt", col.names = c("Col1", "Col2"))
Or, you can also do it in a similar fashion to your attempt with the names
function:
test1 <- read.table("Question1.txt")
names(test1) <- c("col1", "col2")
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With