我想知道是否有一个函数可以将数据集1中的观察值与数据集2中的标题进行匹配,并返回数据集2中的特定观察值,
例如
v1<-1:4
v2<-5:8
data1<-as.data.table(cbind(v1,v2))
data1
colnames(data1)<-c("dog","cat")
data1
v3<-c("dog","cat")
v4<-c("tiger","lion")
data2<-as.data.table(cbind(v3,v4))
if (dat2[1,1]==colnames(data1)) { I would like to get the first observation
in data1 under the column header dog}
desired output: 1
我应该得到值1.是否有一个函数可以适合{我想在列标题dog下的data1中获得第一个观察结果返回该特定值?
答案 0 :(得分:0)
这将返回data2中任意值的任何列的第一行data1:
@Controller
public MyController {
@Autowired Helper helper; // CRepository is correctly autowired
@RequestMapping(...)
public void processRequest() {
A a = new A();
...
helper.doSomething(a);
}
}
@Service
public class Helper {
// A a; remove dependency to A to make it stateless
@Autowired
CRepository repo;
public Helper() {
}
public void doSomething(A a) {
...
repo.save(a);
}
}