Make a list of values that belong to each region


Make a list of values that belong to each region
I have a little trouble in R. I'm pretty new R users.
So I have a dataframe which looks like that (but much more longer) :
My first problem is that my file have no header, I upload my file with this command :
My_data=read.table("/home/toto/test.bed",sep="t", dec=".",fill=TRUE,header = FALSE)
And after try to make a header like that
names(My_data)=c("chr", "start","end","Region_type","Region_id")
But when I want to take a column
My_column<-My_data$Region_type
It does not work. So I must to do like that :
My_column<-My_data[,4]
But I don't understand why the header doesn't work...
My second problem is that I'm trying to make a list of all the clones (clone is represented by chrX Start-End) that belong to each region (MACS_peak_xxx).
To do this I tried something like that :
region_list <- levels(My_data[,4])
region_list_clones <- lapply(region_list, function(x) which( My_data[,4] == x))
I'm pretty sure that's it's very easy to do...
Thank you for your help, I hope that's my example is clear :)
By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.