2016-11-10 1 views
-2

x <- c('typeA', 'typeB', 'typeC') 감안할 수 n, 내가 테이블 만들고 싶어 :R에서 특정 테이블을 만드는 방법은 무엇입니까?

type file  path_to_file 
typeA typeA_1 /home/lynnyi/typeA/typeA_1.txt 
typeA typeA_2 /home/lynnyi/typeA/typeA_2.txt 
... 
typeA typeA_n /home/lynnyi/typeA/typeA_3.txt 
typeB typeB_1 /home/lynnyi/typeB/typeB_1.txt 
... 
typeB typeB_n /home/lynnyi/typeB/typeB_1.txt 
typeC typeC_1 /home/lynnyi/typeC/typeB_1.txt 
... 
typeC typeC_n /home/lynnyi/typeC/typeB_1.txt 

내가, 컬럼의 각각의 값을 얻기 위해 다양한 sapplys을 사용하는 방법을 알고를 즉 ['typeA_1',...,'typeA_n',.......,'typeC_n']

['/home/lynnyi/typeA/typeA_1.txt', .... ... , '/home/lynnyi/typeC/typeC_n.txt'] 그러나 그런 다음 유형 및 숫자에 기초하여 이들을 합칠 수있는 능력을 잃습니다.

어떻게 하나의 테이블/데이터 프레임에 모두 포함시킬 수 있습니까?

감사합니다. n은 모든 종류의 같은 경우 다음과 같이

답변

0

이 수행 할 수 있습니다 :

x <- c('typeA', 'typeB', 'typeC') 
n <- 10 

types <- sort(rep(x, 10)) 
files <- paste(types, rep(1:n, 3), sep = "_") 
paths <- paste("/homme/lynnyi", types, paste0(files, ".txt"), sep = "/") 

data <- cbind(types, files, paths) 
관련 문제