I have imported a datafile in R. It has different columns. There is one column that has the name of Operating System belonging to that row information. I wanted to get the percentage share of each unique OS (windows, linux, ios etc) from this column and plot it. I am very new to R and would like to know if there is any inbuilt way to do this in R.
It seems the
barplot() will be your friend in that case, e.g.
x <- sample(c("Win","Linux","Mac"), 100, replace=TRUE) barplot(table(x))
You could replace
table(x)/sum(table(x))*100 to express data as % rather than counts. I know there are more elegant solutions in additional packages, but I can't remember their names actually. The
table() function will also work for two-way classification, and marginal totals can easily be computed in a similar way; e.g.
apply(table(x, y), 1, sum) gives rows marginal frequencies.
Simulating some data for a good start
The good practice is to hold such categorical variables as factors; one can convert character vector to factor with
plot called on it will make a barplot with counts; to convert it into per-cents, you can use
table that makes counts of each level:
t<-table(x); barplot(t/sum(t)*100,ylab="Per cent")