{ "cells": [ { "cell_type": "markdown", "id": "6254fe95", "metadata": {}, "source": [ "# DataFrame\n", "\n", "\n", "\n", "\n", "**Author:** \n", "This notebook tutorial was automatically generated with ROOTBOOK-izer from the macro found in the ROOT repository on Tuesday, May 19, 2026 at 08:27 PM." ] }, { "cell_type": "code", "execution_count": 1, "id": "dcbf0c3d", "metadata": { "collapsed": false, "execution": { "iopub.execute_input": "2026-05-19T20:27:26.856055Z", "iopub.status.busy": "2026-05-19T20:27:26.855938Z", "iopub.status.idle": "2026-05-19T20:27:27.179641Z", "shell.execute_reply": "2026-05-19T20:27:27.179261Z" } }, "outputs": [ { "name": "stderr", "output_type": "stream", "text": [ "input_line_44:1:23: error: expected namespace name\n", "using namespace ROOT::R;\n", " ~~~~~~^\n" ] } ], "source": [ "using namespace ROOT::R;" ] }, { "cell_type": "markdown", "id": "382967eb", "metadata": {}, "source": [ "Creating variables" ] }, { "cell_type": "code", "execution_count": 2, "id": "8d1b6b4c", "metadata": { "collapsed": false, "execution": { "iopub.execute_input": "2026-05-19T20:27:27.181430Z", "iopub.status.busy": "2026-05-19T20:27:27.181303Z", "iopub.status.idle": "2026-05-19T20:27:27.386164Z", "shell.execute_reply": "2026-05-19T20:27:27.385613Z" } }, "outputs": [], "source": [ "TVectorD v1(3);\n", "std::vector v2 {0.101, 0.202, 0.303};\n", "std::array v3{ {1,2,3} };\n", "std::list names {\"v1\", \"v2\", \"v3\"};" ] }, { "cell_type": "markdown", "id": "e341f3ce", "metadata": {}, "source": [ "Assigning values" ] }, { "cell_type": "code", "execution_count": 3, "id": "39afe26e", "metadata": { "collapsed": false, "execution": { "iopub.execute_input": "2026-05-19T20:27:27.388202Z", "iopub.status.busy": "2026-05-19T20:27:27.388084Z", "iopub.status.idle": "2026-05-19T20:27:27.595348Z", "shell.execute_reply": "2026-05-19T20:27:27.594859Z" } }, "outputs": [ { "name": "stderr", "output_type": "stream", "text": [ "input_line_54:6:11: error: 'TRInterface' is not a class, namespace, or enumeration\n", "auto &r = TRInterface::Instance();\n", " ^\n", "input_line_54:6:11: note: 'TRInterface' declared here\n" ] } ], "source": [ "v1[0]=1;\n", "v1[1]=2;\n", "v1[2]=3;\n", "\n", "auto &r = TRInterface::Instance();" ] }, { "cell_type": "markdown", "id": "d94ecb10", "metadata": {}, "source": [ "Creating dataframe object with its labels" ] }, { "cell_type": "code", "execution_count": 4, "id": "b31ccea9", "metadata": { "collapsed": false, "execution": { "iopub.execute_input": "2026-05-19T20:27:27.596744Z", "iopub.status.busy": "2026-05-19T20:27:27.596621Z", "iopub.status.idle": "2026-05-19T20:27:27.804131Z", "shell.execute_reply": "2026-05-19T20:27:27.803654Z" } }, "outputs": [ { "name": "stderr", "output_type": "stream", "text": [ "input_line_55:2:2: error: unknown type name 'TRDataFrame'\n", " TRDataFrame df1(Label[\"var1\"]=v1,Label[\"var2\"]=v2,Label[\"var3\"]=v3,Label[\"strings\"]=names);\n", " ^\n", "input_line_55:2:19: error: unknown type name 'Label'\n", " TRDataFrame df1(Label[\"var1\"]=v1,Label[\"var2\"]=v2,Label[\"var3\"]=v3,Label[\"strings\"]=names);\n", " ^\n", "input_line_55:2:25: error: value of type 'const char[5]' is not implicitly convertible to 'unsigned long'\n", " TRDataFrame df1(Label[\"var1\"]=v1,Label[\"var2\"]=v2,Label[\"var3\"]=v3,Label[\"strings\"]=names);\n", " ^~~~~~\n", "input_line_55:2:24: error: no viable conversion from 'TVectorD' (aka 'TVectorT') to 'int'\n", " TRDataFrame df1(Label[\"var1\"]=v1,Label[\"var2\"]=v2,Label[\"var3\"]=v3,Label[\"strings\"]=names);\n", " ^ ~~\n", "/github/home/ROOT-CI/build/include/TVectorT.h:92:11: note: candidate function\n", " inline operator std::span()\n", " ^\n", "/github/home/ROOT-CI/build/include/TVectorT.h:96:11: note: candidate function\n", " inline operator std::span() const\n", " ^\n", "input_line_55:2:24: note: passing argument to parameter here\n", " TRDataFrame df1(Label[\"var1\"]=v1,Label[\"var2\"]=v2,Label[\"var3\"]=v3,Label[\"strings\"]=names);\n", " ^\n", "input_line_55:2:36: error: unknown type name 'Label'\n", " TRDataFrame df1(Label[\"var1\"]=v1,Label[\"var2\"]=v2,Label[\"var3\"]=v3,Label[\"strings\"]=names);\n", " ^\n", "input_line_55:2:42: error: value of type 'const char[5]' is not implicitly convertible to 'unsigned long'\n", " TRDataFrame df1(Label[\"var1\"]=v1,Label[\"var2\"]=v2,Label[\"var3\"]=v3,Label[\"strings\"]=names);\n", " ^~~~~~\n", "input_line_55:2:41: error: no viable conversion from 'std::vector' (aka 'vector') to 'int'\n", " TRDataFrame df1(Label[\"var1\"]=v1,Label[\"var2\"]=v2,Label[\"var3\"]=v3,Label[\"strings\"]=names);\n", " ^ ~~\n", "input_line_55:2:41: note: passing argument to parameter here\n", "input_line_55:2:53: error: unknown type name 'Label'\n", " TRDataFrame df1(Label[\"var1\"]=v1,Label[\"var2\"]=v2,Label[\"var3\"]=v3,Label[\"strings\"]=names);\n", " ^\n", "input_line_55:2:59: error: value of type 'const char[5]' is not implicitly convertible to 'unsigned long'\n", " TRDataFrame df1(Label[\"var1\"]=v1,Label[\"var2\"]=v2,Label[\"var3\"]=v3,Label[\"strings\"]=names);\n", " ^~~~~~\n", "input_line_55:2:58: error: no viable conversion from 'std::array' (aka 'array') to 'int'\n", " TRDataFrame df1(Label[\"var1\"]=v1,Label[\"var2\"]=v2,Label[\"var3\"]=v3,Label[\"strings\"]=names);\n", " ^ ~~\n", "input_line_55:2:58: note: passing argument to parameter here\n", "input_line_55:2:70: error: unknown type name 'Label'\n", " TRDataFrame df1(Label[\"var1\"]=v1,Label[\"var2\"]=v2,Label[\"var3\"]=v3,Label[\"strings\"]=names);\n", " ^\n", "input_line_55:2:76: error: value of type 'const char[8]' is not implicitly convertible to 'unsigned long'\n", " TRDataFrame df1(Label[\"var1\"]=v1,Label[\"var2\"]=v2,Label[\"var3\"]=v3,Label[\"strings\"]=names);\n", " ^~~~~~~~~\n", "input_line_55:2:75: error: no viable conversion from 'std::list' (aka 'list >') to 'int'\n", " TRDataFrame df1(Label[\"var1\"]=v1,Label[\"var2\"]=v2,Label[\"var3\"]=v3,Label[\"strings\"]=names);\n", " ^ ~~~~~\n", "input_line_55:2:75: note: passing argument to parameter here\n" ] } ], "source": [ "TRDataFrame df1(Label[\"var1\"]=v1,Label[\"var2\"]=v2,Label[\"var3\"]=v3,Label[\"strings\"]=names);" ] }, { "cell_type": "markdown", "id": "fd3daeae", "metadata": {}, "source": [ "Passing dataframe to R's environment" ] }, { "cell_type": "code", "execution_count": 5, "id": "2398f507", "metadata": { "collapsed": false, "execution": { "iopub.execute_input": "2026-05-19T20:27:27.805540Z", "iopub.status.busy": "2026-05-19T20:27:27.805420Z", "iopub.status.idle": "2026-05-19T20:27:28.010811Z", "shell.execute_reply": "2026-05-19T20:27:28.010294Z" } }, "outputs": [ { "name": "stderr", "output_type": "stream", "text": [ "In module 'Matrix':\n", "/github/home/ROOT-CI/build/include/TVectorT.h:142:26: warning: inline function 'TVectorT::operator[]' is not defined [-Wundefined-inline]\n", " inline Element &operator[](Int_t index) { return (*this)(index); }\n", " ^\n", "input_line_54: note: used here\n", "input_line_57:2:3: error: use of undeclared identifier 'r'\n", " (r[\"df1\"] << df1)\n", " ^\n", "input_line_57:2:15: error: use of undeclared identifier 'df1'\n", " (r[\"df1\"] << df1)\n", " ^\n", "Error in : Error evaluating expression (r[\"df1\"] << df1)\n", "Execution of your code was aborted.\n" ] } ], "source": [ "r[\"df1\"]<> ((*(TVectorD*)0x7f92d4019000)))\n", " ^\n", "Error in : Error evaluating expression (r[\"c(-1,-2,-3)\"] >> ((*(TVectorD*)0x7f92d4019000)))\n", "Execution of your code was aborted.\n" ] } ], "source": [ "r[\"c(-1,-2,-3)\"]>>v4;" ] }, { "cell_type": "markdown", "id": "689424c0", "metadata": {}, "source": [ "adding new colunm to df1 with name var4" ] }, { "cell_type": "code", "execution_count": 8, "id": "d14e74a4", "metadata": { "collapsed": false, "execution": { "iopub.execute_input": "2026-05-19T20:27:28.427328Z", "iopub.status.busy": "2026-05-19T20:27:28.427206Z", "iopub.status.idle": "2026-05-19T20:27:28.632632Z", "shell.execute_reply": "2026-05-19T20:27:28.631953Z" } }, "outputs": [ { "name": "stderr", "output_type": "stream", "text": [ "input_line_62:2:3: error: use of undeclared identifier 'df1'\n", " (df1[\"var4\"] = ((*(TVectorD*)0x7f92d4019000)))\n", " ^\n", "Error in : Error evaluating expression (df1[\"var4\"] = ((*(TVectorD*)0x7f92d4019000)))\n", "Execution of your code was aborted.\n" ] } ], "source": [ "df1[\"var4\"]=v4;" ] }, { "cell_type": "markdown", "id": "2657ff58", "metadata": {}, "source": [ "updating df1 in R's environment" ] }, { "cell_type": "code", "execution_count": 9, "id": "60bbddd9", "metadata": { "collapsed": false, "execution": { "iopub.execute_input": "2026-05-19T20:27:28.634232Z", "iopub.status.busy": "2026-05-19T20:27:28.634106Z", "iopub.status.idle": "2026-05-19T20:27:28.839423Z", "shell.execute_reply": "2026-05-19T20:27:28.838917Z" } }, "outputs": [ { "name": "stderr", "output_type": "stream", "text": [ "input_line_64:2:3: error: use of undeclared identifier 'r'\n", " (r[\"df1\"] << df1)\n", " ^\n", "input_line_64:2:15: error: use of undeclared identifier 'df1'\n", " (r[\"df1\"] << df1)\n", " ^\n", "Error in : Error evaluating expression (r[\"df1\"] << df1)\n", "Execution of your code was aborted.\n" ] } ], "source": [ "r[\"df1\"]<: Error evaluating expression (r << \"print(df1)\")\n", "Execution of your code was aborted.\n" ] } ], "source": [ "r<<\"print(df1)\";" ] }, { "cell_type": "markdown", "id": "163029c8", "metadata": {}, "source": [ "Getting dataframe from R's environment" ] }, { "cell_type": "code", "execution_count": 11, "id": "ad9dea40", "metadata": { "collapsed": false, "execution": { "iopub.execute_input": "2026-05-19T20:27:29.047208Z", "iopub.status.busy": "2026-05-19T20:27:29.047086Z", "iopub.status.idle": "2026-05-19T20:27:29.256921Z", "shell.execute_reply": "2026-05-19T20:27:29.256427Z" } }, "outputs": [ { "name": "stderr", "output_type": "stream", "text": [ "input_line_67:2:2: error: unknown type name 'TRDataFrame'\n", " TRDataFrame df2;\n", " ^\n", "input_line_67:4:1: error: use of undeclared identifier 'r'\n", "r<<\"df2<-data.frame(v1=c(0.1,0.2,0.3),v2=c(3,2,1))\";\n", "^\n", "input_line_67:5:1: error: use of undeclared identifier 'r'\n", "r[\"df2\"]>>df2;\n", "^\n" ] } ], "source": [ "TRDataFrame df2;\n", "\n", "r<<\"df2<-data.frame(v1=c(0.1,0.2,0.3),v2=c(3,2,1))\";\n", "r[\"df2\"]>>df2;\n", "\n", "TVectorD v(3);\n", "df2[\"v1\"]>>v;\n", "v.Print();\n", "\n", "df2[\"v2\"]>>v;\n", "v.Print();" ] }, { "cell_type": "markdown", "id": "e34bb33e", "metadata": {}, "source": [ "Working with colunms between dataframes" ] }, { "cell_type": "code", "execution_count": 12, "id": "528df9ea", "metadata": { "collapsed": false, "execution": { "iopub.execute_input": "2026-05-19T20:27:29.258265Z", "iopub.status.busy": "2026-05-19T20:27:29.258145Z", "iopub.status.idle": "2026-05-19T20:27:29.463269Z", "shell.execute_reply": "2026-05-19T20:27:29.462810Z" } }, "outputs": [ { "name": "stderr", "output_type": "stream", "text": [ "input_line_69:2:3: error: use of undeclared identifier 'df2'\n", " (df2[\"v3\"] << df1[\"strings\"])\n", " ^\n", "input_line_69:2:16: error: use of undeclared identifier 'df1'\n", " (df2[\"v3\"] << df1[\"strings\"])\n", " ^\n", "Error in : Error evaluating expression (df2[\"v3\"] << df1[\"strings\"])\n", "Execution of your code was aborted.\n" ] } ], "source": [ "df2[\"v3\"]<: Error evaluating expression (r[\"df2\"] << df2)\n", "Execution of your code was aborted.\n" ] } ], "source": [ "r[\"df2\"]<> df1[\"var1\"])\n", " ^\n", "input_line_73:2:16: error: use of undeclared identifier 'df1'\n", " (df2[\"v3\"] >> df1[\"var1\"])\n", " ^\n", "Error in : Error evaluating expression (df2[\"v3\"] >> df1[\"var1\"])\n", "Execution of your code was aborted.\n" ] } ], "source": [ "df2[\"v3\"]>>df1[\"var1\"];" ] }, { "cell_type": "markdown", "id": "e8442023", "metadata": {}, "source": [ "Updating df1 in R's environment" ] }, { "cell_type": "code", "execution_count": 15, "id": "a557cb07", "metadata": { "collapsed": false, "execution": { "iopub.execute_input": "2026-05-19T20:27:29.877555Z", "iopub.status.busy": "2026-05-19T20:27:29.877440Z", "iopub.status.idle": "2026-05-19T20:27:30.082588Z", "shell.execute_reply": "2026-05-19T20:27:30.082078Z" } }, "outputs": [ { "name": "stderr", "output_type": "stream", "text": [ "input_line_75:2:3: error: use of undeclared identifier 'r'\n", " (r[\"df1\"] << df1)\n", " ^\n", "input_line_75:2:15: error: use of undeclared identifier 'df1'\n", " (r[\"df1\"] << df1)\n", " ^\n", "Error in : Error evaluating expression (r[\"df1\"] << df1)\n", "Execution of your code was aborted.\n" ] } ], "source": [ "r[\"df1\"]<