1
library(data.table)

train <- fread(input = "../train.csv", header = TRUE, sep = ",", 
           stringsAsFactors = FALSE, data.table = TRUE)

train$Response <- "" #create new column with values ""
train$Response <- paste(train[, 15:20, with = FALSE], collapse = "")

RStudio console:
> is.data.frame(train)
[1] TRUE
> is.data.table(train)
[1] TRUE

Columns with indexes from 15 to 20 has values = 1 or 0 of int type.

I have tryied to make one column "response" (character type) with values "0101..." as result of concatenation values 1 and 0 of columns, described above.

After this procedure I see abnormal behaviour of R studio, can't access to train etc.

Maybe something wrong?

1
  • This doesn't make a lot of sense at the moment (since data.tables don't naturally use the "$"-operator). If train is a data.table then you should edit your question to construct an example that creates an object similar to your use case. Commented Nov 21, 2016 at 2:51

1 Answer 1

1

We can specify the columns to paste in .SDcols, use paste0 with do.call on the Subset of Data.table (.SD), and assign (:=) to create the 'Response' column.

train[, Response := do.call(paste0, .SD), .SDcols = 15:20]
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.