Dollar sign before a variable

偶尔善良 提交于 2019-11-29 23:00:45
Sven Hohenstein

To access a column, use:

my_data[ , cond]

or

my_data[[cond]]

The ith row can be accessed with:

my_data[i, ]

Combine both to obtain the desired value:

my_data[i, cond]

or

my_data[[cond]][i]
rankthefirst

I guess you need get().

For example,
get(x,list), where list is the list and x is the variable(can be a string), which equals list$x.

But in get(x,list), x can be a variable while using $, x cannot be a variable.

$ works on columns, not individual column objects. It's a form of vectorization. The code

corrections$BookDate = as.Date(corrections$BookDate, format = "%m/%d/%Y")

converts the contents of the BookDate column of the corrections table from strings to Date objects. It performs it in one operation, assignment.

Do the following and it will fix your problem:

new_data <- rbind(new_data, c(cond, my_data$cond))
Naren

You will often want to select an entire column, namely one specific variable from a data frame. If you want to select all elements of the variable diameter, for example, both of these will do the trick:

dataframe_name[,column_position]
dataframe_name[,"column_name"]

However, there is a short-cut. If your columns have names, you can use the $ sign:

dataframe_name$column_name
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!