user1919 user1919 - 1 month ago 7
R Question

How to find the minimum value of a column in R?

I am new in R and I am trying to do something really simple. I had load a txt file with four columns and now I want to get the minimum value of the second column.
This is the code that I have:

## Choose the directory of the file

setwd("//Users//dkar//Desktop")

## Read the txt file

data<-read.table("export_v2.txt",sep="",header=T)

str(data)

## this command gives me the minimum for all 4 columns!!
a<-apply(data,2,min)


Actually, if I want to do something like this: min (data(:,2)). But I don't know how to do it in R. Any help?

Answer

If you need minimal value for particular column

min(data[,2])
Comments