How to get columns from XLS files in R

3

Using the R tool, I was able to open an XLS file as follows:

require(xlsx)
coln = function(x) { 
  y = rbind(seq(1, ncol(x)))
  colnames(y) = colnames(x)
  rownames(y) = "col.number"
  return(y)
}
data = read.xlsx2(path, 1)  
coln(data)
x = 3 
data = read.xlsx2(path, 1, colClasses = c(rep("character", x), rep("numeric", ncol(data)-x+1)))

I can see everything on my worksheet. But I would like to get only the data from column A and only then use the data from column B to compute a function.

How can I get this information separate?

    
asked by anonymous 04.09.2015 / 19:30

1 answer

1

The read.xlsx2 function has a parameter called colIndex in which you can specify which columns (by the position) you want to extract.

So, in the code below, for example, putting colIndex = c(1,3,4) you would extract columns 1, 3, and 4.

data = read.xlsx2(path, 1, 
                  colClasses = c(rep("character", x), 
                                 rep("numeric", ncol(data)-x+1)), 
                  colIndex = c(1,3,4))
    
04.09.2015 / 20:54