0

how do you create a loop in the data.frame so that X1 = 2 up to X12 = 13?

 #Automate variable names trial
    Y <- dataL_TT$Bound_Count
    X1 <- dataL_TT$Days_conflict
    X2 <- dataL_TT$Broker360
    X3 <- dataL_TT$Broker720
    X4 <- dataL_TT$RURALPOP_2
    X5 <- dataL_TT$RURALPOP_M
    X6 <-  dataL_TT$PIP_Flag
    X7 <- dataL_TT$Trail
    X8 <- dataL_TT$Trail2
    X9 <- dataL_TT$Individual_2
    X10 <- dataL_TT$Individual_M
    X11 <- dataL_TT$Resolved_Conflict
    X12 <- dataL_TT$Priority

    d <- data.frame(Y = 1, X1 = 2, X2 = 3, X3 = 4, ....., X12 = 13)
2
  • 3
    Please post your attempt. What have you tried so far? Where do you run into problems? Take a look at how to ask for further help. Commented Feb 12, 2018 at 9:57
  • 1
    This is related to your other question: stackoverflow.com/questions/48742104/… Commented Feb 12, 2018 at 9:58

1 Answer 1

1

Not sure to have a good understanding, you can create news columns for your df :

d <- data.frame(Y = 1)
size <- 12 #Your Size

for(i in 1:size) d[,paste0("X",i)] <- i+1

Hope that will helps

Gottavianoni

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.