1
我想列表一些小字符向量的值,並將製表結果附加到字符串。對於下面的可重複的例子,我所需的輸出會是這個樣子:R - 列表字符向量 - 自定義輸出
states responsible
1 KS Joe(2);Suzie(3)
2 MO Bob(4)
3 CO Suzie(1);Bob(2);Ralph(3)
4 NE Joe(1)
5 MT Suzie(3);Ralph(1)
這裏的示例數據:
states <- c("KS", "MO", "CO", "NE", "MT")
responsible <- list(c("Joe", "Joe", "Suzie", "Suzie", "Suzie"), c("Bob", "Bob", "Bob", "Bob"), c("Suzie", "Bob", "Ralph", "Ralph", "Bob", "Ralph"), "Joe", c("Suzie", "Ralph", "Suzie", "Suzie"))
df <- as.data.frame(cbind(states, responsible))
#Tabulating using table()
resp.tab <- lapply(responsible, table)
#Is there a way I can do tabulation without converting to factors?
# OR
#Is there a way to access the factor label and value, then paste them together?
'table'還與'character'載體。 – akrun