Isn't this much shorter and produces roughly the same:
df = read.csv('file.csv')
df = df[df$pval < 0.05,]
hist(df$value)
This should at least get you started.
Some remarks regarding the code:
- You use a lot of reserved names (var, file) as an object name, that is a bad idea.
- If you want the program to work with user input, you need to check it before doing anything with it.
- There is no need to explicitly loop over rows in a data.frame, R is vectorized (e.g. see how I subsetted
df
above). This style looks like Fortran, there is no need for it in R.