error while making first column as row names

Hi All,

I am trying to make first column as a row name but it shows error, could anyone please help with this?

> head(targets, 10) [,1:5]
# A tibble: 10 × 5
   Sample_ID Sentrix_ID   Sentrix_Position Barcode             Batch   
   <chr>     <chr>        <chr>            <chr>               <chr>   
 1 DC103     202915600062 R07C01           202915600062_R07C01 Batch 13
 2 DC115     202915600134 R02C01           202915600134_R02C01 Batch 15
 3 DC118     202995640096 R04C01           202995640096_R04C01 Batch 7 
 4 DC122     202915600016 R06C01           202915600016_R06C01 Batch 18
 5 DC124     202915600134 R05C01           202915600134_R05C01 Batch 15
 6 DC126     202915590071 R05C01           202915590071_R05C01 Batch 14
 7 DC127     202915590071 R02C01           202915590071_R02C01 Batch 14
 8 DC131     202995640096 R08C01           202995640096_R08C01 Batch 7 
 9 DC133     202915600085 R02C01           202915600085_R02C01 Batch 14
10 DC139     200848860168 R02C01           200848860168_R02C01 Batch 5 
> names(targets)[1] <- ""
> # first column as row names
> targets2<-targets[,-1]
> rownames(targets2)<-targets[,1]
Error in `.rowNamesDF<-`(x, value = value) : invalid 'row.names' length
In addition: Warning message:
Setting row names on a tibble is deprecated.

Many thanks,

row names are generally seen as a not great idea, and the tidyverse is not designed to handle them gracefully; If i was in your shoes I would be making a choice for this piece of work to
a) focus on base functionality, because for a special reason I must use rownames ; as a consequence make a plain data.frame and not a tibble.
b) continue with tidyverse and tibbles etc, and simply don't use rownames.

Dear @nirgrahamuk ,

Actually my file has long numeric number in data sheet so if I read them using read.table as txt or csv file then it convert these numbers into scientific notation, so I was trying to read them as excel sheet.
now I was trying read excel with (readxl) R packages by making first column as row but it shows error?

> library(readxl)
> targets <-  readxl::read_excel("LS_BMI.xlsx", row.names=1)
Error in readxl::read_excel("LS_BMI.xlsx",  : 
  unused argument (row.names = 1)

If I don't have row names in this files then how to modify this below command to match with first column instead;

> all(rownames(targets) %in% colnames(mval))

will it be ok to use instead; to match first coulmn of this file with colnames of another file

> all(targets [ ,  1 ]%in% colnames(mval))

Many thanks,

So Actually , I want to put samples in same order in both files; betaval and targets

head(betaval, 10) [,1:5]

# A tibble: 10 × 5
   ``          DC103  DC115  DC118  DC122
   <chr>       <dbl>  <dbl>  <dbl>  <dbl>
 1 cg26928153 0.929  0.862   0.680 0.890 
 2 cg16269199 0.836  0.604   0.589 0.679 
 3 cg13869341 0.826  0.830   0.704 0.786 
 4 cg24669183 0.768  0.810  NA     0.765 
 5 cg26679879 0.388  0.428   0.438 0.344 
 6 cg22519184 0.412  0.445   0.391 0.345 
 7 cg15560884 0.640  0.551  NA     0.676 
 8 cg01014490 0.0207 0.0290  0.148 0.0226
 9 cg10692041 0.916  0.828  NA     0.847 
10 cg02339369 0.933  0.939  NA     0.892
> head(targets, 10) [,1:5]
# A tibble: 10 × 5
   ``    Sentrix_ID   Sentrix_Position Barcode             Batch   
   <chr> <chr>        <chr>            <chr>               <chr>   
 1 DC103 202915600062 R07C01           202915600062_R07C01 Batch 13
 2 DC115 202915600134 R02C01           202915600134_R02C01 Batch 15
 3 DC118 202995640096 R04C01           202995640096_R04C01 Batch 7 
 4 DC122 202915600016 R06C01           202915600016_R06C01 Batch 18
 5 DC124 202915600134 R05C01           202915600134_R05C01 Batch 15
 6 DC126 202915590071 R05C01           202915590071_R05C01 Batch 14
 7 DC127 202915590071 R02C01           202915590071_R02C01 Batch 14
 8 DC131 202995640096 R08C01           202995640096_R08C01 Batch 7 
 9 DC133 202915600085 R02C01           202915600085_R02C01 Batch 14
10 DC139 200848860168 R02C01           200848860168_R02C01 Batch 5

If you are talking about merging on DC*** values, you will have to pivot_longer your betaval

This topic was automatically closed 7 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.