If you say "in RStudio" refers to the option via the menu (Tools> Import Dataset), it is not possible. This menu only creates a snippet to read the data, according to the parameters you configure.
As the @carlosfigueira mentioned, what you need is the transposition function, t()
. After reading just be careful with the names of the columns and the type of object.
You will have to read with header = FALSE
, and then make some modifications to the read date.frame to leave it in the correct form. I also recommend using stringsAsFactors = FALSE
. For example, considering that you saved the spreadsheet in csv from MS Excel in Portuguese:
csvtext <- "Var1;1,2;1,5;1,6
Var2;2;4;6
Var3;7;8;9,2"
dat1 <- read.csv2(text = csvtext, header = FALSE, stringsAsFactors = FALSE)
# Você usaria read.csv2(file = "pasta/arquivo.csv", ...)
dat2 <- t(dat1[, -1])
dat3 <- as.data.frame(dat2)
rownames(dat3) <- NULL
colnames(dat3) <- dat1[, 1]
dat3
# Var1 Var2 Var3
# 1.2 2 7.0
# 1.5 4 8.0
# 1.6 6 9.2
str(dat3)
#'data.frame': 3 obs. of 3 variables:
# $ Var1 : num 1.2 1.5 1.6
# $ Var2: num 2 4 6
# $ Var3: num 7 8 9.2
Although I strongly recommend changing the way the data is acquired, if at all possible. This organization is not the "R" standard, it is the most common organization of data.