Is there a general way of passing a data frame with arbitrary columns (integer/factor, numeric, character data) from r to c and back? Pointers to close enough examples would be greatly appreciated.
Thanks.
RT
To access a specific column in a dataframe by name, you use the $ operator in the form df$name where df is the name of the dataframe, and name is the name of the column you are interested in. This operation will then return the column you want as a vector.
In R Programming Language to apply a function to every integer type value in a data frame, we can use lapply function from dplyr package. And if the datatype of values is string then we can use paste() with lapply.
A data frame is the most common way of storing data in R and, generally, is the data structure most often used for data analyses. Under the hood, a data frame is a list of equal-length vectors. Each element of the list can be thought of as a column and the length of each element of the list is the number of rows.
The column items in a data frame in R can be accessed using: Single brackets [] , which would display them as a column. Double brackets [[]] , which would display them as a list. Dollar symbol $ , which would display them as a list.
data.frame type is a list with "data.frame" attribute.
This is example of creating data.frame in source of R (src/library/stats/src/model.c):
/* Turn the data "list" into a "data.frame" */
/* so that subsetting methods will work. */
PROTECT(tmp = mkString("data.frame"));
setAttrib(data, R_ClassSymbol, tmp);
UNPROTECT(1);
You can simulate data.frame manually this way:
l <- list(1:5)
attr(l, "class") <- "data.frame"
attr(l, "names") <- "Column 1"
attr(l, "row.names") <- paste("Row ", 1:5)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With