Trying to find regression & p-value for every row of a csv file in R Hi I'm fairly new to R and am having some trouble with trying to do linear regression per row.  Someone suggested I post to Cross Validated as well so here's my problem:-
I can't attach the actual dataset because I'm not allowed to share it but this is the basic outline:
       Jan Feb Mar Apr May Jun Jul Aug Sep Oct Nov Dec (...total 12 cols)              
Type 1
Type 2 
Type 3 
(... total 1680 rows)

The values are level of inventory for each type, numeric (no strings).

Basically what I want to do is outlined here: 
(1) Linear Regression with time as independent variable
(2) ANOVA Test to see if coefficient of time is statistically significant.  
What I want to do is regression analysis for every row (i.e. for every "type"), with time as the independent variable and then output a p-value for each row which will be added to the row in a new column. The purpose is to use p-value to see if there's trends in inventory for each individual type without having to graph 1680 different types of product, because that would be very hard to analyse.
I've looked through a lot of similar questions using lm() for each row but none that include how I would go about outputting a p-value instead of the coefficients themselves. Hope someone can help!
 A: This is simple once your data are in the right format; the response variable should be in a single column. I assumed that what you want to do is simple linear regression, which requires recoding the months as numbers.
There are a number of ways to get the job done. I happen to enjoy using packages in the "tidyverse", so that is the route taken below.
library(tidyverse)

# generate some data; note the format doesn't match the OP's question
data <- data.frame(type=rep(1:3, each=4), month=rep(1:4, times=3), value=round(rnorm(12),2))

# spreading the data out... not really helpful, but done to show the inverse operation
wide.data <- data %>% spread(key=month, value=value)

head(wide.data)

#output
#  type     1    2     3     4
#1    1 -1.87 1.33 -0.54 -0.93
#2    2 -0.78 1.81 -1.10  2.23
#3    3  1.28 0.59 -0.50  0.25

# get to the correctd format... the key variable is coded as a factor by default;
# convert/mutate to a numeric quantity

long.data <- gather(wide.data, key=month, value=value, -type) %>%
  mutate(month = as.numeric(month))

head(long.data)

#output
# type month value
# 1    1     1 -1.87
# 2    2     1 -0.78
# 3    3     1  1.28
# 4    1     2  1.33
# 5    2     2  1.81
# 6    3     2  0.59

# do fitting for each type and compile the p-values
fits <- group_by(long.data, type) %>%
  do({
    fit <- lm(value ~ month, data=.)
    data.frame(p.value = summary(fit)$coefficients[2,4])
  }) %>%
  ungroup()

fits #results will differ
# # A tibble: 3 x 2
# type p.value
# <int>   <dbl>
#   1     1   0.909
# 2     2   0.541
# 3     3   0.271

