It mentions differing number of rows. This most likely means something is wrong with your "mylist" file.
I can think of two issues that could cause this. The first one, and probably most likely since you are working with some sort of external .RData file you say (which isn't really an internal data format used within an R script but is instead is the format R uses to store all data + environment into while performing the script, correct me if i'm wrong here.)
So it's likely your mylist is in fact some type of multi dimensional type (i.e. a list of list, or a list of dataframes etc) containing multiple data types with differing lengths.
For example, this is some PCA data i worked on a while back... called a.pca.res
You can see that it's not a data.frame or list, but a 'list of 5' type. If you then look at the data itself, you can see it contains 5 individual "double" type's. If this is in fact some sort of object with different data's contained within it, the easiest way to normally grab that specifiic datatype is by calling it using a $. Most objects are made that way. So for example if i'm interested in rotation, i can call it up using a.pca.res$rotation.
A second reason this error comes up could be that your list or data.frame contains empty cells. R doesn't like to handle data that isn't consistent and will often throw errors if you try to do something like that. I can't easily reproduce a data frame with fixed colums but differing row lengths. But essentially it's comes down to this
That being said, i have had data imported into R that does actually contain inconsistent row lengths or column lengths due to empty cells. Often happens with .csv or .tsv files where a tabs or commas were missing. Normally while reading the file you would handle these by putting some (na.strings = "NA") while doing read.table or whatever you are doing.
Hope this helps, if not let me know and provide an example of your data or script so we can look closer at it, as this is not an issue of R or NCBI, but of your script, to which only you are privy.
Cheers,
Lesley
Can you show an example of some of your data?
dput(mylist[1:5])
Can you also give an example of what you want your excel sheet to look like?
Use
write.xlsx2
withlapply
. You may have to find a way to make adding sheet names work.file:///Users/samirrahman/Desktop/Screen%20Shot%202021-03-10%20at%203.15.21%20PM.png
Hi everyone. Thank you for the responses. I attached an image of what the file looks like on Rstudio. I am not a bioinformatician myself, so I have limited knowledge. My colleague gave me this file which basically contains lists of genes associated with different chromatin loops that have been assigned different chromatin states.
Use these directions: How to add images to a Biostars post
I don't know if you will be able to see that image. Here is an example of what one list looks like:
Thanks, and can you also describe what you want your resulting excel file to look like?
I would like to get a separate sheet for every list, with the Ensembl IDs in a single column. Do you know how I can convert the ensembl IDs to gene names?
Use biomaRt. Search the site - there are plenty of discussions on getting HGNC symbols from ENSG identifiers. Those two identifiers do not have 1:1 correspondence for all genes though, so watch out for that.
As for one sheet per list item, your list seems to be a named list. Like I mentioned in my comment, you may want to use
names(mylist)
for the sheet names. I think you may have to use a loop since you'd be iterating in parallel through two 1D objects:mylist
andnames(mylist)