error in data.frame

I am completely new to r and although I have seen this problem on numerous sites the answers don't seemt to help me fix mine! I understand that there are differing rows but where exactly are the different rows? sorry for the stupid question!

Error in data.frame(study = study, sub = as.numeric(s), visit = v, date = unique(data$date), :
arguments imply differing number of rows: 1, 0, 37379
In addition: Warning message:
In activpal.file.reader( : NAs introduced by coercion

You need to know what you are using to make the df out of.
How big are each of study, s, v, unique(data$date) ?
Try length() on them to find out

[1] 1
[1] 3
[1] 15
[1] 15
[1] 1

im not seeing a relationship between the objects you are measuring now, and the objects you told us you were making the data frame out of...

Thanks for your reply

[1] 1

[1] 1
[1] 1
[1] 1

Is this what you meant?

Hello Gail.
by wrapping your object name in quotation marks you are asking length() function to treat it as a simple characer vector with the name of your object as its content rather than passing the object itself

try :



I have tried that and I am getting object not found

Does your code feature a step where v would be created?

alternatively, if you could provide some example input data , and some cleaned up minimal code that takes you from a clear start point to the point of error in your code, then it would be possible for us to analyse it with you.


No there is nothing in the code to create a 'v'

consider omitting this from your dataframe that was not building correctly for you.

Error in data.frame(study = study, sub = as.numeric(s) ,visit = v, date = unique(data$date), :


I am just wondering why it works up until id number 1102 and then comes up with the error. I have checked this file numerous times now and cannot see anything that is different to the other files.

[1] 1001
[1] "1"
[1] "SBIntervention"
[1] 1002
[1] "1"
[1] "SBIntervention"
[1] 1003
[1] "1"
[1] "SBIntervention"
[1] 1004
[1] "1"
[1] "SBIntervention"
[1] 1005
[1] "1"
[1] "SBIntervention"
[1] 1006
[1] "1"
[1] "SBIntervention"
[1] 1007
[1] "1"
[1] "SBIntervention"
[1] 1008
[1] "1"
[1] "SBIntervention"
[1] 1101
[1] "1"
[1] "SBIntervention"
[1] 1102
[1] "1"
[1] "SBIntervention"
Error in data.frame(study = study, sub = as.numeric(s), visit = v, date = unique(data$date), :
arguments imply differing number of rows: 1, 0, 37379
In addition: Warning message:
In activpal.file.reader( : NAs introduced by coercion

I dont have your data, so I cant help you.

did you resolve something about visit = v ? previously you said your code didnt make v. Can you describe in your mind what the origin of v is ?
I might suspect that v is a column in some other dataframe that you have not mentioned

yes v is visit in all of the different subject logs (e.g. sleep time log, wear log) that create the dataframe. Below are the instructions and code that I have been given to use if that is of any information to you


Step 1 Load the activpalProcessing package and library



Step 2 Insert the path to your working directory inside of the quotations

directory <- identifyDirectory("/Users/jsmith/Documents/PAI_Directory/")

Step 3 Load example logs

example.log.subjects <- log.subjects
example.log.bed <- log.bed <-

Step 4 Export example logs as .csv files to your working directory. If the code below is used the logs will be named "template.log.subjects.csv", "template.log.bed.csv" and "" in your working directory.


Step 5 Open these templates and insert your data to create your own logs. Resave the files as .csv files as "log.subjects.csv", "log.bed.csv", and "", respectively.

Step 6 Use the function "process.AP" to loop through the AP events data in the specified working directory and estimate PA and SB variables for the given data set. There are 18 independent functions provided in the package activpalProcessing. These functions are used within the function "process.AP". These functions can also be used according the manual provided within this package. If a bed log and on/off log were not used, replace both "log.bed" and "" with NULL (no quotations)


I'm sorry, what you have shared doesn't provide a direct means to help you with the particulars of the error you are requesting help with.

I have a suggestion. If its clear to you the line of code that errors, so that you can select to run all the code up to and not beyond that point. Then I would ask you to being a fresh session. (your code implicitly does this the rm(list=ls()) effectively clears out the objects in your environment). So my request might amount to running your script from and including that line, up to just where you error occurs.

At the point where you can type interactively , you can copy and paste the following:

 sapply(ls(),FUN = function(x){class(get(x))[[1]]})

what this does is get a list of names of objects current loaded in your environment and gets the corresponding class
an example from my own machine :

sapply(ls(),FUN = function(x){class(get(x))[[1]]})

    allsteps          df1          df2          ndf            p           p2           p3 
 "character" "data.frame"     "tbl_df"  "character"     "plotly"     "plotly"     "plotly" 
          p4          pjs        step1        step2        step3        step4 
    "plotly"       "json"       "list"       "list"       "list"  "character"  

this shows i have two dataframe called df1, df2. I have a character vector ndf etc.
Perhaps by reviewing what you have in your environment, we can determine what is going on in the dataframe declation that is erroring for you.

thank you so much I will try that now

This is after running everything again

sapply(ls(),FUN = function(x){class(get(x))[[1]]})
directory example.log.bed example.log.subjects
"character" "data.frame" "data.frame" "data.frame"

ok great. so there are 4 dataframes that you have, from which you could try to make this new dataframe...
presumably 'study' 'subject' 'visit' 'date' are variables that should come from one or several of these 4. Is it clear to you which of the 4 dataframes you need to access to get the 4 columns of interest ? or should I suggest a way to look at the contents of the dataframes so we can see what they contain together?

Hi, This is an example of log.bed dataframe


This one is

and this is log.subjects


This is an example of the accelerometer data to make up the dataframe:

Time|DataCount(samples)|Interval(s)|ActivityCode|CumulativeStepCount|Activity ScoreMET.h)|Sum(Abs(DiffX)|Sum(Abs(DiffY)|Sum(Abs(DiffZ)

14/10/2019 16:59:52|0|2584.5|0|0|0.897395833|9778|12972|16841
14/10/2019 17:42:57|25845|10.3|1|0|0.00400|983|1571|1392
14/10/2019 17:43:07 25948 4.9 2 1 0.002627778 592 819 660
14/10/2019 17:43:12 25997 1.1 2 2 0.00115 387 310 478
14/10/2019 17:43:13 26008 5.8 2 3 0.002977778 1129 1073 1342

how do you wish to combine these different dataframes ?

This is the code in the package which loops through the dataframes and takes the times of non-wear of the device for example, away from the total daily physical activity levels for each participant.