sr320 / course-austral-2015

0 stars 2 forks source link

Counting data in R #23

Open NicoSegoviaC opened 9 years ago

NicoSegoviaC commented 9 years ago

I made a script to count data in R. I share if anyone wants to use it sometime. Nico.

Counting data in R

Count occurrences in a column.

##read csv (or txt)
data<-read.csv("qDOD_Cgigas_GOslim_DISTINCT.csv",sep=",")
data

Make sure that the data are read.

Count lines and see the name of each column.

nrow(data)
names(data)
> nrow(data)
[1] 5734
> names(data)
[1] "CGI_ID"     "GOslim_bin" "aspect" 

Use plyr library (is in the basic package of R) Or you can install it with:

install.packages("plyr")
library(plyr)

Use the function "count" in the plyr library. To count in all dataset, set from 1 to X. Where x is number of lines in your data set and the name of the column in "vars".

count(data[1:5734,],vars="GOslim_bin")
                         GOslim_bin freq
1                    DNA metabolism   84
2                    RNA metabolism  485
3                     cell adhesion  128
4      cell cycle and proliferation  229
5  cell organization and biogenesis  454
6               cell-cell signaling   63
7                             death  238
8           developmental processes  487
9        other biological processes  919
10        other metabolic processes  779
11               protein metabolism  583
12              signal transduction  473
13                  stress response  294
14                        transport  518

You can make an object with that for graphics:

CountCGigas<-count(data[1:5734,],vars="GOslim_bin")

CountCGigas

attach(CountCGigas)
sr320 commented 9 years ago

Thanks for sharing - this is great! :+1: