0

I have no clue how to do this in R

I have an excel table with numbers from 0 to 9999. Each is characterised by a tex (eg. 110 -sleep).

Know I created a second excel table that consists SOME of the numbers from excel table 1.

I would like to create table 3 that match the name of the numbers from excel table 1 with excel table 2.

example

Table 1.csv

0     Other personal care
110   Sleep
111   Sleep in bed

Table 2.csv

0
111

Output

Table 3.csv

    0     Other personal care
    111   Sleep in bed
Rstudent
  • 887
  • 4
  • 12

2 Answers2

1

merge the two dataframes

df1<-data.frame(ID=c(1,2,3),text=c("Other personal care","Sleep","Sleep in bed"))
df2<-data.frame(ID=c(1,2))
new_dataset <- merge(df1,df2, by=c("ID"))
Rajith Thennakoon
  • 3,975
  • 2
  • 14
  • 24
0
table1 <- data.frame(num=1:6,
                 text=c("a", "b", "c", "d", "e", "f"))

table2 <- data.frame(num=c(1,2,4,6))

table3 <- table1[table1$num %in% table2$num, ]

Use %in% and possibly which() or subset().

Kidae Kim
  • 499
  • 2
  • 9