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(file.name.and.path) : NAs introduced by coercion
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
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.
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.
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
rm(list=ls())
Step 1 Load the activpalProcessing package and library
install.packages("activpalProcessing")
library(activpalProcessing)
Step 2 Insert the path to your working directory inside of the quotations
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 "template.log.on.off.csv" 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 "log.on.off.csv", 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 "log.on.off" 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:
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.
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?
This one is log.on.off
|id|visit|study|date.on.month|date.on.day|date.on.year|time.on.hour|time.on.minute|
|1001|1|SBIntervention|10|14|2019|0|0|
|1001|1|SBIntervention|10|18|2019|9|30|
|1001|1|SBIntervention|10|22|2019|9|30|
|1001|1|SBIntervention|10|22|2019|9|30|
|1002|1|SBIntervention|10|14|2019|0|0|
|1003|1|SBIntervention|10|14|2019|0|0|
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.