Hi,
I have output from blastn. The output format is 6. -outfmt "6 qseqid sseqid stitle pident qcovs" and I have saved it as csv file.
So I have multiple csv blast output files in a directory. I want to work on cleaning up the csv files all at once using R studio. Each csv file has the same number of columns (1 column) and a different number of rows.
To read all the csv files at once, i used:
fnames <- list.files()
csv <- lapply(fnames, read.csv)
This creates a list of data frames. Now I want to split the one column into multiple ones based on tab spaces. I tried to use:
strings <- str_split_fixed(csv$col1, " ", 5)
However, this is not working, as it creates no data at all:
Is there another way with which I could split the column on all the csv's all at once?
P.S. I am posting on behalf of someone, so they may respond here to any questions for clarification.
Thanks!
Can you post some of your data using
dput(head(csv[[1]]))
?Thank you. Since I have differing number of rows this is not working. The error i get is
Add some example data to your post, and an example of the desired output.
This is how the single column is on multiple csv file.
I would like to separate the columns based on tab space and make it into to 5 columns.
I don't see a tab separator, but I do potentially see a pipe separator
|
.When you refer to this as the single column in your files, are you saying that this is the only column in the data.frame after importing it, or are you rather saying that this is the one column out of many that you have that you want to split?
It's always better to post an example of your data using
dput(head(csv[[1]]))
to avoid confusion like this.Even if I have to separate using a pipe separator, how would i do that in a list of files?
I have tried
strings <- str_split_fixed(csv$col1, "|", 8)
it doesnt work.
I am unable to attach an image or run dput(head(csv[[1]])). I apologize. My computer security settings is not letting me do it.
copy and paste the output from it into a comment. After, select all the code and then press the button with 0's and 1's just above the post to format it as code.
Thank you. Actually it worked.
strings <- str_split_fixed(csv$col1, " ", 5)
Even though the strings said "no data available", the actual csv list has separated into 5 columns. I apologize for not noticing this earlier.
Provide example data as plain text. Your links to images do not work.