How do I create new dataset by selecting columns from existing dataset?


#1

Hi , I am a new R user.

I want to learn how to create a new dataset by selecting columns from existing dataset and group them with name.

I have attached sample data here. I look forward to the advice. Apologies if my question too elementary. Regards, J


#2

Assuming you have two data sets with a common colname name, say "ID", you can combine them simply with

`new_df <- inner_join(first_df, second_df, by = "ID")'

You may bend up with some duplicate columns, foo.x, foo.y, which you can deal with by select and colnames

revised_df <-new_df %>% select(-field.y, fileld2.y ...)

`colnames(revised_df) <- c("nice1", "nice2", "nice3", .. "niceX")

And, by the way, this is a friendly place, and no one needs to apologize for needing help at any level.


#3

Thank you very much. I appreciate this support. Regards, J


#4

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.