> setwd("/Users/qiao/Documents/R_test_two/new_test")
// 读取所有数据
> allData <- read.delim("all.test.tab.txt", header = T)
> colnames(allData)[1] <- "name"

> new_d2 <- scan("data2.txt")
Read 45 items
> new_d2
 // ......
 
// which 函数选择相应的行
> freq_d2 <- allData[which(allData$name %in% new_d2),]


> nrow(freq_d2)
[1] 45
> ncol(freq_d2)
[1] 221

> new_d3 <- scan("g3.txt")
Read 30 items

// subset函数选择相应的行
> freq_d3 <- subset(allData, name %in% new_d3)
> nrow(freq_d3)
[1] 30

> typeof(allData$name)
[1] "integer"

// 如果只选择一行数据, 可以直接用等号, 以下是针对字符串的用法
> allData$name <- as.character(allData$name)


> freq_d3_2 <- subset(allData, name == "106")

// 把数据写入文件
> write.table(data_2, file = "result_data.txt", quote = FALSE, sep = "\t", row.names = FALSE)