Sunday, 15 May 2011

r - Need help creating a table from survey data -



r - Need help creating a table from survey data -

i sense simple problem should able figure out myself, can't seem come solution.

i've been reading various posts both here , elsewhere can't seem come across illustration of want (maybe i'm not using right terminology?).

i've got survey info structured this:

df <- data.frame(id = c(101,102,103,104,105,106,107), q1_1 = c(1,3,3,2,5,4,2), q1_2 = c(3,4,5,5,2,1,1), q1_3 = c(5,5,2,2,3,1,4)) df

i can create table gives me response proportions:

round(prop.table(table(df$q1_1)),3)*100

what want though build same table, multiple rows (each row beingness different question) , columns beingness response levels. how do that?

this driving me nuts. help appreciated. thanks!

it's pretty simple:

> out <- lapply(df, function(x) round(prop.table(table(x)),3)*100) > do.call(rbind, out[2:4]) 1 2 3 4 5 q1_1 14.3 28.6 28.6 14.3 14.3 q1_2 28.6 14.3 14.3 14.3 28.6 q1_3 14.3 28.6 14.3 14.3 28.6

r

No comments:

Post a Comment