[R] Unequal column lengths
Jim Lemon
drjimlemon at gmail.com
Fri Apr 15 02:41:15 CEST 2016
Hi Tom,
What you want is a list rather than a data frame. So:
df<-read.table(text=" Dat1 Dat2 Dat3
1 1 5 4
2 7 7 9
3 3 3 5
4 2 NA 5
5 9 NA NA",
header=TRUE)
dflist<-as.list(df)
na.remove<-function(x) return(x[!is.na(x)])
sapply(dflist,na.remove)
Jim
On Fri, Apr 15, 2016 at 7:33 AM, Tom Mosca <tom at vims.edu> wrote:
> Hello,
>
> I’ve tried several times to learn R, but have never gotten past a particular gate. My data are organized by column in Excel, with column headers in the first row. The columns are of unequal lengths. I export them as CSV, then import the CSV file into R. I wish to summarize the data by column. R inserts NA for missing values, then refuses to operate on columns with NA. R is importing my data into a data frame, and I realize that is inappropriate for what I want to do.
>
> How can I import my data so that I can work on columns of unequal length? The first thing I would like to do is generate a table containing mean, median, mode, standard deviation, min, max and count, all per column.
>
> Thank you, Tom
>
> Example data
> Dat1 Dat2 Dat3
> 1 1 5 4
> 2 7 7 9
> 3 3 3 5
> 4 2 NA 5
> 5 9 NA NA
>
> [[alternative HTML version deleted]]
>
>
> ______________________________________________
> 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.
More information about the R-help
mailing list