lynnyi lynnyi - 1 year ago 78
R Question

How to make specific table in R?


x <- c('typeA', 'typeB', 'typeC')
and a number
I want to make a table:

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

I know how to use various sapplys to get the value of each of the columns, i.e.
['/home/lynnyi/typeA/typeA_1.txt', .... ... , '/home/lynnyi/typeC/typeC_n.txt']

But then I lose the ability to join them based in type and num...

How do I have them all in one table / data frame?


ira ira
Answer Source

If n is same for all types, this can be done as follows:

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)
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download