简体   繁体   中英

Plotting densities from a table in R

I'm currently trying to plot densities from a table/list where column 1 is just the names/labels of the data and column 2 is the actual numbers I want plotted.

If I just have a file of numbers, I can get my code to work using the scan function. However when I have my table, I get a argument 'x' must be numeric error.

Here is my code:

library(gplots)
dataLine = read.table("fileLocation")

den = density(dataLine)

plot(den, col = "red", ylim = c(0, 50), xlim = c(0.045,1))

Should I be using something like what this previous question has done with selecting for a specific column? Plotting densities in R .

ie should I have change my code to be d <- density(table[dataLine$position==2,]$rt) ?

Because that gives me an error saying object of type'closure' is not subsettable

Any suggestions on what I should do to plot my column of numbers? Apologies if my code doesn't make sense; I'm fairly new to R

Your dataline object is a data frame with multiple columns, you need to pass only the column of data to the density function. To pass the 2nd column of the data frame you can do this:

density(dataline[[2]])

See the help page ?'[[' for more options to use just part of a data frame.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM