1

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 ...
3
  • can you show the str(res_basic). Commented Dec 21, 2022 at 16:54
  • write.csv expects a data.frame but your res_basic isn't a data.frame, it's a list (of two data.frames) Commented Dec 21, 2022 at 17:01
  • I need to export this list as file, could you help? Commented Dec 21, 2022 at 17:03

1 Answer 1

1

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)
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.