Chris Evans
2017-Sep-26 06:53 UTC
[R] Surprising message "Error in FUN(newX[, i], ...) : all arguments must have the same length"
I am hitting an odd message "Error in FUN(newX[, i], ...) : all arguments must have the same length". I can't supply the data as it's a huge data frame but I think this has enough diagnostic information to show the issue. I am sure I am missing something obvious. I've put some extra comments in but otherwise this is cut and pasted from Rstudio. ### I wanted a table of the values in four columns:> apply(datTAF[,75:78],2,table,na.rm=TRUE)Error in FUN(newX[, i], ...) : all arguments must have the same length ### odd, surely as it's a data frame all x going into table() should be same length. Check:> apply(datTAF[,75:78],2,length)RiskSuicide RiskSelfHarm RiskHarmOth RiskLegal 3009 3009 3009 3009 ### I has reasons to think the tables should all be the same length. Check:> apply(datTAF[,75:78],2,function(x){length(table(x))})RiskSuicide RiskSelfHarm RiskHarmOth RiskLegal 6 6 6 6 ### Now I'm a bit baffled. Try str:> apply(datTAF[,75:78],2,str)Named chr [1:3009] "." "." "." "0" "0" "0" "0" "0" "0" "3" "0" "0" "0" "." "0" "0" "0" "0" "0" "." ... - attr(*, "names")= chr [1:3009] "1" "2" "3" "4" ... Named chr [1:3009] "0" "0" "0" "0" "0" "0" "0" "1" "0" "0" "0" "0" "0" "." "0" "0" "0" "0" "0" "." ... - attr(*, "names")= chr [1:3009] "1" "2" "3" "4" ... Named chr [1:3009] "0" "0" "0" "0" "0" "0" "0" "0" "0" "3" "0" "0" "0" "." "0" "0" "0" "0" "0" "." ... - attr(*, "names")= chr [1:3009] "1" "2" "3" "4" ... Named chr [1:3009] "0" "0" "0" "0" "0" "0" "0" "0" "0" "0" "0" "0" "1" "." "0" "0" "0" "0" "0" "." ... - attr(*, "names")= chr [1:3009] "1" "2" "3" "4" ... NULL ### Not sure where that trailing "NULL" came from:> str(datTAF[,78])chr [1:3009] "0" "0" "0" "0" "0" "0" "0" "0" "0" "0" "0" "0" "1" "." "0" "0" "0" "0" "0" "." "0" ...> Sys.info()sysname release version nodename machine login "Windows" ">= 8 x64" "build 9200" "HPLP166" "x86-64" "Chris.Evans" user effective_user "Chris.Evans" "Chris.Evans" Anyone see what I'm missing? TIA, Chris
Eric Berger
2017-Sep-26 07:41 UTC
[R] Surprising message "Error in FUN(newX[, i], ...) : all arguments must have the same length"
Hi Chris,
Maybe the na.rm=TRUE is affecting things. Try this
apply(datTAF[,75:78],2,function(x){ sum(!is.na(x)) })
HTH,
Eric
On Tue, Sep 26, 2017 at 9:53 AM, Chris Evans <chrishold at psyctc.org>
wrote:
> I am hitting an odd message "Error in FUN(newX[, i], ...) : all
arguments
> must have the same length". I can't supply the data as it's a
huge data
> frame but I think this has enough diagnostic information to show the
> issue. I am sure I am missing something obvious. I've put some extra
> comments in but otherwise this is cut and pasted from Rstudio.
>
> ### I wanted a table of the values in four columns:
> > apply(datTAF[,75:78],2,table,na.rm=TRUE)
> Error in FUN(newX[, i], ...) : all arguments must have the same length
>
> ### odd, surely as it's a data frame all x going into table() should be
> same length. Check:
> > apply(datTAF[,75:78],2,length)
> RiskSuicide RiskSelfHarm RiskHarmOth RiskLegal
> 3009 3009 3009 3009
>
> ### I has reasons to think the tables should all be the same length.
> Check:
> > apply(datTAF[,75:78],2,function(x){length(table(x))})
> RiskSuicide RiskSelfHarm RiskHarmOth RiskLegal
> 6 6 6 6
>
> ### Now I'm a bit baffled. Try str:
> > apply(datTAF[,75:78],2,str)
> Named chr [1:3009] "." "." "." "0"
"0" "0" "0" "0" "0"
"3" "0" "0" "0"
> "." "0" "0" "0" "0"
"0" "." ...
> - attr(*, "names")= chr [1:3009] "1" "2"
"3" "4" ...
> Named chr [1:3009] "0" "0" "0" "0"
"0" "0" "0" "1" "0"
"0" "0" "0" "0"
> "." "0" "0" "0" "0"
"0" "." ...
> - attr(*, "names")= chr [1:3009] "1" "2"
"3" "4" ...
> Named chr [1:3009] "0" "0" "0" "0"
"0" "0" "0" "0" "0"
"3" "0" "0" "0"
> "." "0" "0" "0" "0"
"0" "." ...
> - attr(*, "names")= chr [1:3009] "1" "2"
"3" "4" ...
> Named chr [1:3009] "0" "0" "0" "0"
"0" "0" "0" "0" "0"
"0" "0" "0" "1"
> "." "0" "0" "0" "0"
"0" "." ...
> - attr(*, "names")= chr [1:3009] "1" "2"
"3" "4" ...
> NULL
>
> ### Not sure where that trailing "NULL" came from:
> > str(datTAF[,78])
> chr [1:3009] "0" "0" "0" "0"
"0" "0" "0" "0" "0"
"0" "0" "0" "1" "."
"0"
> "0" "0" "0" "0" "."
"0" ...
>
> > Sys.info()
> sysname release version nodename
> machine login
> "Windows" ">= 8 x64" "build
9200" "HPLP166"
> "x86-64" "Chris.Evans"
> user effective_user
> "Chris.Evans" "Chris.Evans"
>
> Anyone see what I'm missing? TIA,
>
> Chris
>
> ______________________________________________
> R-help at r-project.org mailing list -- To UNSUBSCRIBE and more, see
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/
> posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
>
[[alternative HTML version deleted]]
Chris Evans
2017-Sep-26 08:14 UTC
[R] Surprising message "Error in FUN(newX[, i], ...) : all arguments must have the same length"
Quite so. Very sorry everyone. I realised that I meant "useNA="always"" not "na.rm=TRUE" within minutes of sending that Email ... by which time I was travelling and no longer had internet to beat you to this Eric. Clear evidence that I should never touch the keyboard without the first coffee of the day. Thanks! Chris> From: "Eric Berger" <ericjberger at gmail.com> > To: "Chris Evans" <chrishold at psyctc.org> > Cc: "R. Help" <r-help at r-project.org> > Sent: Tuesday, 26 September, 2017 08:41:33 > Subject: Re: [R] Surprising message "Error in FUN(newX[, i], ...) : all > arguments must have the same length"> Hi Chris, > Maybe the na.rm=TRUE is affecting things. Try this > apply(datTAF[,75:78],2, function(x){ sum(! is.na (x)) })> HTH, > Eric> On Tue, Sep 26, 2017 at 9:53 AM, Chris Evans < chrishold at psyctc.org > wrote:>> I am hitting an odd message "Error in FUN(newX[, i], ...) : all arguments must >> have the same length". I can't supply the data as it's a huge data frame but I >> think this has enough diagnostic information to show the issue. I am sure I am >> missing something obvious. I've put some extra comments in but otherwise this >> is cut and pasted from Rstudio.>> ### I wanted a table of the values in four columns: >> > apply(datTAF[,75:78],2,table,na.rm=TRUE) >> Error in FUN(newX[, i], ...) : all arguments must have the same length>> ### odd, surely as it's a data frame all x going into table() should be same >> length. Check: >> > apply(datTAF[,75:78],2,length) >> RiskSuicide RiskSelfHarm RiskHarmOth RiskLegal >> 3009 3009 3009 3009>> ### I has reasons to think the tables should all be the same length. Check: >> > apply(datTAF[,75:78],2,function(x){length(table(x))}) >> RiskSuicide RiskSelfHarm RiskHarmOth RiskLegal >> 6 6 6 6>> ### Now I'm a bit baffled. Try str: >> > apply(datTAF[,75:78],2,str) >> Named chr [1:3009] "." "." "." "0" "0" "0" "0" "0" "0" "3" "0" "0" "0" "." "0" >> "0" "0" "0" "0" "." ... >> - attr(*, "names")= chr [1:3009] "1" "2" "3" "4" ... >> Named chr [1:3009] "0" "0" "0" "0" "0" "0" "0" "1" "0" "0" "0" "0" "0" "." "0" >> "0" "0" "0" "0" "." ... >> - attr(*, "names")= chr [1:3009] "1" "2" "3" "4" ... >> Named chr [1:3009] "0" "0" "0" "0" "0" "0" "0" "0" "0" "3" "0" "0" "0" "." "0" >> "0" "0" "0" "0" "." ... >> - attr(*, "names")= chr [1:3009] "1" "2" "3" "4" ... >> Named chr [1:3009] "0" "0" "0" "0" "0" "0" "0" "0" "0" "0" "0" "0" "1" "." "0" >> "0" "0" "0" "0" "." ... >> - attr(*, "names")= chr [1:3009] "1" "2" "3" "4" ... >> NULL>> ### Not sure where that trailing "NULL" came from: >> > str(datTAF[,78]) >> chr [1:3009] "0" "0" "0" "0" "0" "0" "0" "0" "0" "0" "0" "0" "1" "." "0" "0" "0" >> "0" "0" "." "0" ...>> > Sys.info() >> sysname release version nodename machine login >> "Windows" ">= 8 x64" "build 9200" "HPLP166" "x86-64" "Chris.Evans" >> user effective_user >> "Chris.Evans" "Chris.Evans">> Anyone see what I'm missing? TIA,>> Chris>> ______________________________________________ >> R-help at r-project.org mailing list -- To UNSUBSCRIBE and more, see >> https://stat.ethz.ch/mailman/listinfo/r-help >> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html >> and provide commented, minimal, self-contained, reproducible code.[[alternative HTML version deleted]]
Maybe Matching Threads
- Surprising message "Error in FUN(newX[, i], ...) : all arguments must have the same length"
- cannot change file permissions
- Error with custom function in apply: Error in FUN(newX[, i], ...) : unused argument(s) (newX[, i])
- Trouble with FUN(newX[, i], ...)
- Error in FUN(newX[, i], ...) : no complete element pairs in R 2.7.0 patched