[R] Surprising message "Error in FUN(newX[, i], ...) : all arguments must have the same length"
Eric Berger
ericjberger at gmail.com
Tue Sep 26 09:41:33 CEST 2017
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]]
More information about the R-help
mailing list