벡터에서 모든 데이터 프레임을 나열하고 벡터 (list_all)에서 데이터 프레임을 호출하여 데이터 프레임에 대해 다른 연산을 수행합니다. 첫 번째 행을 사용하여 각 데이터 프레임에 colnames를 할당하려고합니다. 내가 선으로이 코드 줄을 실행하면R 환경에서 첫 번째 행의 여러 데이터 프레임에 대해 colnames를 할당하는 방법
#table_1
V1 V2 V3 V4 V5
1: caffeine ACHE Adora1 ADORA1 Adora2a
2: 7.25- 7.25 15.00- 44.00 44.00- 49.00 9.40- 48.10
#table_2
V1 V2
1: paraxanthine daf-12
2: NA
#table_3
V1 V2 V3 V4
1: theophylline Adora1 ADORA1 Adora2a
2: 0.70- 26.00 0.00- 20.00 1.31- 25.30
list_all <- c("table_1","table_2","table_3") # this list was derived from previous code of 60 lines
n_drugs <- 3
drug_names <- c("caffeine","paraxanthine","theophylline")
output_final <- matrix(ncol=n_drugs , nrow=1)
for (t in 1:length(list_all)){
output_final[t] <- paste(drug_names[t],"output_final", sep = "_")
names_all <- c()
names_all[t,] <- unlist(c(as.character(get(noquote(list_all[t]))[1,]))) #saving colnames in 'names_all'
names_all[t,1] <- c("drug_name") # change first column name
assign(output_final[t],setnames(get(noquote(list_all[t])),colnames(get(noquote(list_all[t]))),names_all[t,]))
}
작동하지만 연료 소모량을 나는 취득으로 오류를
"오류를 얻고 그 연료 소모량 실행할 때 (을 noquote (list_all [t])) : 객체 ' NA '을 (를) 찾을 수 없습니다. 도와주세요
COLNAMES 당신의 dataframe의 첫 번째 행에 표시하는 것은 당신이 뭔가를 했어야 사인 일반적으로'읽기 .csv (..., header = TRUE)'를 먼저 읽고 데이터를 읽었을 때 그 시점에서 시도하는 것이 무엇이든 시도하는 것보다 훨씬 쉽습니다. – Marius
작동하지 않는 코드를 제공하십시오 – HubertL
다른 프로그래밍 언어에서 의미가있는 것처럼 보이지만 R이 아닌 것 같아요 ... 당신이하려는 일에 대한 자세한 내용은 도움이 될 것입니다 – Rilcon42