Home adding multiple dynamic variables to a dataframe in R
Reply: 0

adding multiple dynamic variables to a dataframe in R

user629
1#
user629 Published in April 26, 2018, 5:22 pm

I'd like to add a series variables to a dataframe:

patent <- c(1,2,2)
temp1 <- c(TRUE,FALSE,FALSE)
temp2 <- c(FALSE,TRUE,TRUE)
df <- data.frame(patent,temp1,temp2)
df

  patent temp1 temp2
       1  TRUE FALSE
       2 FALSE  TRUE
       2 FALSE  TRUE

What I would like to do is to generate column sums for each temp var, by patent, in a loop / function / using dplyr / etc. Here is what I'm ultimately looking for:

  patent temp1 temp2 new1 new2
       1  TRUE FALSE    1    0
       2 FALSE  TRUE    0    2
       2 FALSE  TRUE    0    2
You need to login account before you can post.

About| Privacy statement| Terms of Service| Advertising| Contact us| Help| Sitemap|
Processed in 0.498096 second(s) , Gzip On .

© 2016 Powered by mzan.com design MATCHINFO