Toni Toni - 4 months ago 9
R Question

Copying and pasting data from an internet post to the R console

I am trying to import (or copy and paste) the dataset on this post into the R console, using these commands:

library(psych)
mat <- "dimnames<-"(as.matrix(read.clipboard()), NULL)


and

dat = read.table(stdin(), header=TRUE)


with error messages.

Is there a way to do it?

Answer

If this is a one-off copy and paste, you might want to try something like this:

df <- read.table(header=T,text="Strength              ChangenInstigators     GroupB     GroupC
Communication         300                    100        122
Productivity          200                    212        500
ConflictResolution   150                    157        130
Vision                216                    256        233
Personnel             350                    300        222")

The reason why you're probably getting errors is because one header "Change Instigators" has a space so its trying to be read as 2 columns. Furthermore, "Conflict resolution" has a space in it as well so it is also being read in as 2 columns. If you remove these two spaces it should work.