简体   繁体   中英

Error in opening a CSV file with specifying row.name using R

I have a big df (CSV format) that looks like:

miRNAs <- c('mmu_mir-1-3p','mmu_mir-1-5p','mmu-mir-6-5p','mmu-mir-6-3p')
cca <- c('12854','5489','54485','2563')
ccb <- c('124','589','5465','25893')
taa <- c('12854','589','5645','763')
df <- data.frame(miRNAs,cca,ccb,taa)

and I want to use this df in DESeq2 analyses. I made this df unique by using unique(df) and tried to open using countData <- as.matrix(read.csv(file="df.csv", row.name="miRNAs", sep = ",")) but it gives this error

Error in read.table(file = file, header = header, sep = sep, quote = quote, : duplicate 'row.names' are not allowed

Since I made the df unique I don't know why this error keeps popping up. Basically why I want to read my df in that way is that I want to get the list of my column headers (except the first column) when I type colnames(df) . Because I need to do FALSE TRUE test to see if match these are matching with row names of another file called phenotype.csv all(rownames(phenotype) == colnames(countData))

In the row.name="miRNAs" argument you are not accessing the respective column, but are using a length one character vector. That then gets recycled and that's why you get the error. Import without the row.names argument and if you really want that variable as row names instead of a column, then do that after the import:

df <- data.frame(
  miRNAs = c('mmu_mir-1-3p','mmu_mir-1-5p','mmu-mir-6-5p','mmu-mir-6-3p'),
  cca = c('12854','5489','54485','2563'),
  ccb = c('124','589','5465','25893'),
  taa = c('12854','589','5645','763')
  )

rownames(df) <- df$miRNAs
df$miRNAs <- NULL
df
#>                cca   ccb   taa
#> mmu_mir-1-3p 12854   124 12854
#> mmu_mir-1-5p  5489   589   589
#> mmu-mir-6-5p 54485  5465  5645
#> mmu-mir-6-3p  2563 25893   763

Created on 2020-02-19 by the reprex package (v0.3.0)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM