Can someone please explain me this code? especially the role of “function x and [[x]]”?

前端 未结 2 1956
清歌不尽
清歌不尽 2021-01-28 07:50

This is the code in R and I\'m having trouble understanding the role of function(x) and qdata[[x]] in this line of code. Can someone elaborate me this

2条回答
  •  野趣味
    野趣味 (楼主)
    2021-01-28 08:39

    This code generate a series of histograms, one for each of columns 12 to 35 of dataframe qdata. The lapply function iterates over the columns. At each iteraction, the name of the current column is passed as argument "x" to the anonymous function defined by "function(x)". The body of the function is a call to the hist() function, which creates the histogram. qdata[[x]] (where x is the name of a column) extracts the data from that column. I am actually confused by "data=qdata".

提交回复
热议问题