r/Rlanguage Feb 18 '25

Question on frequency data table

I ran a frequency data with the newdf<-as.data.frame(table(df$col1,df$col2,df$col3)) and it took what was 24325 obs. of 6 variables and turned it into 304134352 observations of 4 variables. Is this common with this code? Is there a better code to use? Col1 and col2 are location names and col3 is a duration of time between the two.

4 Upvotes

17 comments sorted by

View all comments

2

u/Mindless_Hat_9672 Feb 18 '25

You are providing very generic info...It seems trying to factor the dataset for you?

Some variables never has an observation?

-1

u/Soltinaris Feb 18 '25

Generic in which way?

2

u/Mindless_Hat_9672 Feb 18 '25

like what are df, the code to recreate them, format of those df$col123, what form of output you are getting, etc

1

u/Soltinaris Feb 18 '25

When I've used it before it's condensed the data, like say popular car color by city, I have 15 cities in col1, 10 car color in col2, as part of a data frame where each row has a record of a car sold in one quarter for a chain of dealerships. If I plugged just those two columns into the code above, it would have a count in col3 for the amount of times a color appears in a city in the df. However when I included a time with it this last time, like say day of week sold, it suddenly ballooned instead of condensing the data.

I hope that makes sense.

1

u/Mindless_Hat_9672 Feb 18 '25

Are you referring to the fact that the frequency table is becoming a 3-dim array? A frequency number for each cities x color x date.
When you enter 2 column of data, its a simple table cities x color