I am trying to create a dataframe by selecting data from several dataframes...basically a simple SQL type exercise but with R. Sample data is created below. Dataframe A, and B. To select from both dataframes and create a new dataframe is straightforward such as:
AB<-data.frame(COLUMN1=A$ID, COLUMN2=B$ONE, COLUMNS3=B$TWO, COLUMN4=A$JOB, COLUMN5=B$THREE)
or selecting the data by an index instead of the column name as:
AB<-data.frame(COLUMN1=A[,1], COLUMN2=B$ONE, COLUMNS3=B$TWO, COLUMN4=A$JOB, COLUMN5=B$THREE)
What I actually need to do however is create a dataframe and instead of naming the new columns in "AB", I need to designate them by index so they are in the right order. I tried this as the following but it didn't work obviously. Any help would be appreciated
AB<-data.frame([,1]=A$ID, [,2]=B$ONE, [,3]=B$TWO, [,4]=A$JOB, [,5]=B$THREE)
SAMPLE DATA
A<-data.frame (ID=c("A", "B", "C"), CUSTOMER=c("1", "2", "3"), JOB=c("ONE", "TWO", "THREE"))
B<-data.frame (ONE=c("X", "Y", "Z"), TWO=c("10", "20", "30"), THREE=c("SMALL", "MEDIUM", "LARGE"))