Relative Content

Tag Archive for rdataframe

Pooled Cross Section Lags in R

I have pooled cross section data (df)of different states at different points in time. I’m trying to see how weather events during crops’ growing period affected how the crops are currently priced. To do so, I would like to lag my precipitation variable by 1 month, 2 months, and 3 months and add these new variables to df . My current df looks like this:

How to transform frequency table?

I am generating a frequency table with code table(data$col1, data$col2). col1 has Yes/No variables while col2 has count of U/R variables The resulting table has structure

Turning dataframe into table in R

I read the excel file shown in the image below into R using the read_excel() from the readxl package. Is there a way for me to turn the data into a table where it counts the number of Locations by Company as shown in the image below? Thanks.