I got this error after runing write.csv(),
how I can fix it?
Thanks
write.csv (res_basic,"ceRNA_basic_result", row.names=TRUE)
Error in (function (..., row.names = NULL, check.rows = FALSE, check.names = TRUE, :
arguments imply differing number of rows: 43131, 10499
str(res_basic):
List of 2
$ cesig :'data.frame': 43131 obs. of 5 variables:
..$ targetce : chr [1:43131] "AASDHPPT" "AASDHPPT" "AASDHPPT" "AASDHPPT" ...
..$ anotherce : chr [1:43131] "ADGRG1" "AFAP1" "BCL3" "C1orf147" ...
..$ miRNAs : chr [1:43131] "hsa-miR-6837-3p" "hsa-miR-1185-1-3p" "hsa-miR-6837-3p" "hsa-miR-1185-1-3p" ...
..$ miRNAs_num: num [1:43131] 1 1 1 1 1 1 1 1 1 1 ...
..$ ratio : num [1:43131] 0.5 1 1 1 1 0.5 1 1 1 1 ...
$ cenotsig:'data.frame': 10499 obs. of 5 variables:
..$ targetce : chr [1:10499] "AASDHPPT" "AASDHPPT" "AASDHPPT" "AASDHPPT" ...
..$ anotherce : chr [1:10499] "ARCN1" "BACH1" "CDK6" "DNAJA1" ...
..$ miRNAs : chr [1:10499] "hsa-miR-1185-1-3p" "hsa-miR-1185-1-3p" "hsa-miR-7849-3p" "hsa-miR-6837-3p" ...
..$ miRNAs_num: num [1:10499] 1 1 1 1 1 1 1 1 1 1 ...
..$ ratio : num [1:10499] 0.333 0.25 0.2 0.333 0.333 ...
CodePudding user response:
We have a list
of data.frame
. Thus, we need to loop if we want to write as two separate datasets
Map(function(x, y) write.csv(x, paste0(y, ".csv"), row.names = TRUE),
res_basic, names(res_basic))
If it needs to be a single file, bind them together into a single data and then write it back
library(dplyr)
write.csv(bind_rows(res_basic, .id = 'grp'),
"ceRNA_basic_result.csv", row.names=TRUE)