R: converting dataframe to table

前端 未结 2 1037
孤城傲影
孤城傲影 2020-12-29 14:47

I have a dataframe in R with three variables named for example df$V1, df$V2, df$V3. df$V1 and df$V2 are both

相关标签:
2条回答
  • 2020-12-29 15:32

    This is an alternative to table:

    xtabs(V3 ~ V1 + V2, df)
    
    0 讨论(0)
  • 2020-12-29 15:37

    As mentioned by ran2, you can use the reshape package. Here is an example:

    df <- data.frame(V1 = factor(sample(letters[1:5],100,replace=TRUE)),
                     V2 = factor(toupper(sample(letters[1:5],100,replace=TRUE))),
                     V3 = runif(100))
    library(reshape)
    cast(df, V1 ~ V2, mean)
    
    0 讨论(0)
提交回复
热议问题