names of a dataset returns NULL- R version 3.2.4 Revised-Ubuntu 14.04 LTS <p>I have a small issue regarding a dataset I am using. Suppose I have a dataset called <code>mergedData2</code> defined using those command lines from a subset of <code>mergedData</code>: </p> <pre><code>mergedData=rbind(test_set,training_set) lookformean&lt;-grep("mean()",names(mergedData),fixed=TRUE) lookforstd&lt;-grep("std()",names(mergedData),fixed=TRUE) varsofinterests&lt;-sort(c(lookformean,lookforstd)) mergedData2&lt;-mergedData[,c(1:2,varsofinterests)] </code></pre> <p>If I do <code>names(mergedData2)</code>, I get: </p> <pre><code> [1] "volunteer_identifier" "type_of_experiment" [3] "body_acceleration_mean()-X" "body_acceleration_mean()-Y" [5] "body_acceleration_mean()-Z" "body_acceleration_std()-X" </code></pre> <p>(I takes this 6 first names as MWE but I have a vector of 68 names)</p> <p>Now, suppose I want to take the average of each of the measurements per <code>volunteer_identifier</code> and <code>type_of_experiment</code>. For this, I used a combination of <code>split</code> and <code>lapply</code>:</p> <pre><code>mylist&lt;-split(mergedData2,list(mergedData2$volunteer_identifier,mergedData2$type_of_experiment)) average_activities&lt;-lapply(mylist,function(x) colMeans(x)) average_dataset&lt;-t(as.data.frame(average_activities)) </code></pre> <p>As <code>average_activities</code> is a list, I converted it into a data frame and transposed this data frame to keep the same format as <code>mergedData</code> and <code>mergedData2</code>. The problem now is the following: when I call <code>names(average_dataset)</code>, it returns <code>NULL</code> !! But, more strangely, when I do:<code>head(average_dataset)</code> ; it returns : </p> <pre><code> volunteer_identifier type_of_experiment body_acceleration_mean()-X body_acceleration_mean()-Y 1 1 0.2773308 -0.01738382 2 1 0.2764266 -0.01859492 3 1 0.2755675 -0.01717678 4 1 0.2785820 -0.01483995 5 1 0.2778423 -0.01728503 6 1 0.2836589 -0.01689542 </code></pre> <p>This is just a small sample of the output, to say that the names of the variables are there. So why <code>names(average_dataset)</code> returns <code>NULL</code> ?</p> <p>Thanks in advance for your reply, best </p> <p>EDIT: Here is an MWE for mergedData2:</p> <pre><code> volunteer_identifier type_of_experiment body_acceleration_mean()-X body_acceleration_mean()-Y 1 2 5 0.2571778 -0.02328523 2 2 5 0.2860267 -0.01316336 3 2 5 0.2754848 -0.02605042 4 2 5 0.2702982 -0.03261387 5 2 5 0.2748330 -0.02784779 6 2 5 0.2792199 -0.01862040 body_acceleration_mean()-Z body_acceleration_std()-X body_acceleration_std()-Y body_acceleration_std()-Z 1 -0.01465376 -0.9384040 -0.9200908 -0.6676833 2 -0.11908252 -0.9754147 -0.9674579 -0.9449582 3 -0.11815167 -0.9938190 -0.9699255 -0.9627480 4 -0.11752018 -0.9947428 -0.9732676 -0.9670907 5 -0.12952716 -0.9938525 -0.9674455 -0.9782950 6 -0.11390197 -0.9944552 -0.9704169 -0.9653163 gravity_acceleration_mean()-X gravity_acceleration_mean()-Y gravity_acceleration_mean()-Z 1 0.9364893 -0.2827192 0.1152882 2 0.9274036 -0.2892151 0.1525683 3 0.9299150 -0.2875128 0.1460856 4 0.9288814 -0.2933958 0.1429259 5 0.9265997 -0.3029609 0.1383067 6 0.9256632 -0.3089397 0.1305608 gravity_acceleration_std()-X gravity_acceleration_std()-Y gravity_acceleration_std()-Z 1 -0.9254273 -0.9370141 -0.5642884 2 -0.9890571 -0.9838872 -0.9647811 3 -0.9959365 -0.9882505 -0.9815796 4 -0.9931392 -0.9704192 -0.9915917 5 -0.9955746 -0.9709604 -0.9680853 6 -0.9988423 -0.9907387 -0.9712319 </code></pre> <p>My duty is to get this average_dataset (which is a dataset which contains the average value for each physical quantity (column 3 and onwards) for each volunteer and type of experiment (e.g 1 1 mean1 mean2 mean3...mean68 2 1 mean1 mean2 mean3...mean68, etc)</p> <p>After this I will have to export it as a txt file (so I think using write.table with row.names=F, and col.names=T). Note that for now, if I do this and import the dataset generated using read.table, I don't recover the names of the columns of the dataset; even while specifying col.names=T.</p>